-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (127 loc) · 5.37 KB
/
release.yml
File metadata and controls
149 lines (127 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: CI - Auto-release & upload to PyPI
on:
push:
branches: [main] # bump version & create Release
release:
types: [published] # build & upload to PyPI
workflow_dispatch: # allow manual trigger
permissions:
contents: write
id-token: write
jobs:
# ──────────────────────────────────────
# 1. Job A: bump version & make Release
# ──────────────────────────────────────
auto-release:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.2
with: { fetch-depth: 0 }
- name: Set up Python
uses: actions/setup-python@v5.6.0
with: { python-version: '3.x' }
# Read current version (default 0.0.0 if file missing)
- name: Get current version
id: ver
run: |
cur=$(cat src/veedb/VERSION 2>/dev/null || echo "0.0.0")
echo "current=$cur" >> "$GITHUB_OUTPUT"
# Bump patch (1.2.3 ➜ 1.2.4)
- name: Bump patch version
id: bump
run: |
IFS='.' read -r MAJ MIN PAT <<< "${{ steps.ver.outputs.current }}"
PAT=$((PAT + 1))
NEW="$MAJ.$MIN.$PAT"
echo "$NEW" > src/veedb/VERSION
echo "new=$NEW" >> "$GITHUB_OUTPUT"
# Commit VERSION bump, tag & push
- name: Commit & tag
env:
NEW_VERSION: ${{ steps.bump.outputs.new }}
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add src/veedb/VERSION
git commit -m "chore: bump version to v$NEW_VERSION" || true
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
git push origin HEAD
git push origin "v$NEW_VERSION"
# ---------------------------
# Generate markdown changelog
# ---------------------------
- name: Generate changelog
id: changelog
run: |
# Find previous tag (ignore errors if first release)
prev=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$prev" ]; then
range="HEAD"
else
range="$prev..HEAD"
fi
# Collect commit messages *except* the autobump commit
git log $range --pretty=format:"- %s (%h)" --invert-grep --grep "bump version" > CHANGELOG_GH_ACTION.md
# Fallback message if no commits make it through the filter
if [ ! -s CHANGELOG_GH_ACTION.md ]; then
echo "- Version bump only" > CHANGELOG_GH_ACTION.md
fi
echo "body_path=CHANGELOG_GH_ACTION.md" >> "$GITHUB_OUTPUT" # Create GitHub Release with the changelog as body
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.bump.outputs.new }}
body_path: ${{ steps.changelog.outputs.body_path }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
# ─────────────────────────────────────────────────────────
# Build + publish to PyPI in the same job — relying on the
# release.published event to fire downstream is unreliable
# when the Release is created by an action (a previous setup
# broke quietly between v0.1.7 and v0.1.10, leaving PyPI
# behind the git tags by three versions).
# ─────────────────────────────────────────────────────────
- name: Set up Python (publish)
uses: actions/setup-python@v5.6.0
with: { python-version: '3.x' }
- name: Install build deps
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build wheel & sdist
run: |
# Make sure we build from the freshly bumped checkout —
# the VERSION write happened earlier in this job.
python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# ────────────────────────────────────────
# 2. Manual republish-only path (workflow_dispatch)
# Useful when PyPI is behind the git tag and you want to
# reprocess the latest tag without bumping again.
# ────────────────────────────────────────
republish:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/checkout@v4.2.2
- name: Set up Python
uses: actions/setup-python@v5.6.0
with: { python-version: '3.x' }
- name: Install build deps
run: pip install build twine
- name: Build wheel & sdist
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true