11name : Release
22
33on :
4- workflow_dispatch :
5- inputs :
6- bump :
7- description : ' Version bump type'
8- required : true
9- default : ' patch'
10- type : choice
11- options :
12- - patch
13- - minor
14- - major
4+ pull_request :
5+ types : [closed]
6+ branches : [main]
157
168permissions : {}
179
1810jobs :
19- sync-and-tag :
11+ check-release :
12+ if : github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v')
13+ runs-on : ubuntu-latest
14+ outputs :
15+ version : ${{ steps.extract.outputs.VERSION }}
16+ steps :
17+ - name : Extract version from branch name
18+ id : extract
19+ run : |
20+ BRANCH="${{ github.event.pull_request.head.ref }}"
21+ VERSION="${BRANCH#release/v}"
22+ echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
23+ echo "Detected release version: $VERSION"
24+
25+ tag :
26+ needs : check-release
2027 runs-on : ubuntu-latest
2128 permissions :
2229 contents : write
23- outputs :
24- version : ${{ steps.sync.outputs.VERSION }}
2530 steps :
2631 - name : Checkout
2732 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -31,32 +36,19 @@ jobs:
3136 git config user.name "github-actions[bot]"
3237 git config user.email "github-actions[bot]@users.noreply.github.com"
3338
34- - name : Bump version and sync
35- id : sync
39+ - name : Create and push tag
3640 run : |
37- CURRENT=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
38- IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
39- case "${{ inputs.bump }}" in
40- major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
41- minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
42- patch) PATCH=$((PATCH + 1)) ;;
43- esac
44- VERSION="${MAJOR}.${MINOR}.${PATCH}"
45- echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
46- bash scripts/version-sync.sh "$VERSION"
47- git add Cargo.toml npm/ pypi/
48- git commit -m "v$VERSION: bump and sync package versions"
49- if git rev-parse "v$VERSION" >/dev/null 2>&1; then
50- echo "::error::Tag v$VERSION already exists."
41+ VERSION="${{ needs.check-release.outputs.version }}"
42+ TAG="v${VERSION}"
43+ if git rev-parse "$TAG" >/dev/null 2>&1; then
44+ echo "::error::Tag $TAG already exists."
5145 exit 1
5246 fi
53- git tag "v$VERSION"
54-
55- - name : Push changes and tag
56- run : git push && git push --tags
47+ git tag "$TAG"
48+ git push origin "$TAG"
5749
5850 build :
59- needs : sync-and- tag
51+ needs : [check-release, tag]
6052 strategy :
6153 matrix :
6254 include :
@@ -123,7 +115,7 @@ jobs:
123115 - name : Checkout
124116 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
125117 with :
126- ref : v${{ needs.sync-and-tag .outputs.version }}
118+ ref : v${{ needs.check-release .outputs.version }}
127119 persist-credentials : false
128120
129121 - name : Install Rust
@@ -172,7 +164,7 @@ jobs:
172164 path : socket-patch-${{ matrix.target }}.zip
173165
174166 github-release :
175- needs : [sync-and-tag , build]
167+ needs : [check-release , build]
176168 runs-on : ubuntu-latest
177169 permissions :
178170 contents : write
@@ -187,14 +179,14 @@ jobs:
187179 env :
188180 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
189181 run : |
190- TAG="v${{ needs.sync-and-tag .outputs.version }}"
182+ TAG="v${{ needs.check-release .outputs.version }}"
191183 gh release create "$TAG" \
192184 --repo "$GITHUB_REPOSITORY" \
193185 --generate-notes \
194186 artifacts/*
195187
196188 cargo-publish :
197- needs : [sync-and-tag , build]
189+ needs : [check-release , build]
198190 runs-on : ubuntu-latest
199191 permissions :
200192 contents : read
@@ -203,7 +195,7 @@ jobs:
203195 - name : Checkout
204196 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
205197 with :
206- ref : v${{ needs.sync-and-tag .outputs.version }}
198+ ref : v${{ needs.check-release .outputs.version }}
207199 persist-credentials : false
208200
209201 - name : Install Rust
@@ -232,7 +224,7 @@ jobs:
232224 CARGO_REGISTRY_TOKEN : ${{ steps.crates-io-auth.outputs.token }}
233225
234226 npm-publish :
235- needs : [sync-and-tag , build]
227+ needs : [check-release , build]
236228 runs-on : ubuntu-latest
237229 permissions :
238230 contents : read
@@ -241,7 +233,7 @@ jobs:
241233 - name : Checkout
242234 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
243235 with :
244- ref : v${{ needs.sync-and-tag .outputs.version }}
236+ ref : v${{ needs.check-release .outputs.version }}
245237 persist-credentials : false
246238
247239 - name : Configure git for HTTPS
@@ -308,7 +300,7 @@ jobs:
308300 run : npm publish ./npm/socket-patch --provenance --access public
309301
310302 pypi-publish :
311- needs : [sync-and-tag , build]
303+ needs : [check-release , build]
312304 runs-on : ubuntu-latest
313305 permissions :
314306 contents : read
@@ -317,7 +309,7 @@ jobs:
317309 - name : Checkout
318310 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
319311 with :
320- ref : v${{ needs.sync-and-tag .outputs.version }}
312+ ref : v${{ needs.check-release .outputs.version }}
321313 persist-credentials : false
322314
323315 - name : Download all artifacts
@@ -336,7 +328,7 @@ jobs:
336328
337329 - name : Build platform wheels
338330 run : |
339- VERSION="${{ needs.sync-and-tag .outputs.version }}"
331+ VERSION="${{ needs.check-release .outputs.version }}"
340332 python scripts/build-pypi-wheels.py --version "$VERSION" --artifacts artifacts --dist dist
341333
342334 - name : Publish to PyPI
0 commit comments