11name : Release
22
33on :
4- pull_request :
5- types : [closed]
6- branches : [main]
4+ workflow_dispatch :
5+ inputs :
6+ dry-run :
7+ description : ' Dry run (build only, skip publish)'
8+ type : boolean
9+ default : false
710
811permissions : {}
912
1013jobs :
11- check-release :
12- if : github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v')
14+ version :
1315 runs-on : ubuntu-latest
1416 outputs :
15- version : ${{ steps.extract .outputs.VERSION }}
17+ version : ${{ steps.read .outputs.VERSION }}
1618 steps :
17- - name : Extract version from branch name
18- id : extract
19- env :
20- HEAD_REF : ${{ github.event.pull_request.head.ref }}
19+ - name : Checkout
20+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+ with :
22+ persist-credentials : false
23+
24+ - name : Read version from Cargo.toml
25+ id : read
2126 run : |
22- VERSION="${HEAD_REF#release/v}"
27+ VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
2328 echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
24- echo "Detected release version: $VERSION"
29+ echo "Release version: $VERSION"
30+
31+ - name : Check tag does not exist
32+ run : |
33+ VERSION="${{ steps.read.outputs.VERSION }}"
34+ if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
35+ echo "::error::Tag v${VERSION} already exists. Bump the version in a PR first."
36+ exit 1
37+ fi
2538
2639 tag :
27- needs : check-release
40+ needs : version
41+ if : ${{ !inputs.dry-run }}
2842 runs-on : ubuntu-latest
2943 permissions :
3044 contents : write
3145 steps :
3246 - name : Checkout
3347 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3448
35- - name : Configure Git
36- run : |
37- git config user.name "github-actions[bot]"
38- git config user.email "github-actions[bot]@users.noreply.github.com"
39-
4049 - name : Create and push tag
4150 run : |
42- VERSION="${{ needs.check-release.outputs.version }}"
43- TAG="v${VERSION}"
44- if git rev-parse "$TAG" >/dev/null 2>&1; then
45- echo "::error::Tag $TAG already exists."
46- exit 1
47- fi
51+ TAG="v${{ needs.version.outputs.version }}"
4852 git tag "$TAG"
4953 git push origin "$TAG"
5054
5155 build :
52- needs : [check-release, tag]
56+ needs : [version, tag]
57+ if : ${{ always() && needs.version.result == 'success' && (needs.tag.result == 'success' || needs.tag.result == 'skipped') }}
5358 strategy :
5459 matrix :
5560 include :
@@ -116,7 +121,6 @@ jobs:
116121 - name : Checkout
117122 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
118123 with :
119- ref : v${{ needs.check-release.outputs.version }}
120124 persist-credentials : false
121125
122126 - name : Install Rust
@@ -165,7 +169,8 @@ jobs:
165169 path : socket-patch-${{ matrix.target }}.zip
166170
167171 github-release :
168- needs : [check-release, build]
172+ needs : [version, build]
173+ if : ${{ !inputs.dry-run }}
169174 runs-on : ubuntu-latest
170175 permissions :
171176 contents : write
@@ -180,14 +185,15 @@ jobs:
180185 env :
181186 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
182187 run : |
183- TAG="v${{ needs.check-release .outputs.version }}"
188+ TAG="v${{ needs.version .outputs.version }}"
184189 gh release create "$TAG" \
185190 --repo "$GITHUB_REPOSITORY" \
186191 --generate-notes \
187192 artifacts/*
188193
189194 cargo-publish :
190- needs : [check-release, build]
195+ needs : [version, build]
196+ if : ${{ !inputs.dry-run }}
191197 runs-on : ubuntu-latest
192198 permissions :
193199 contents : read
@@ -196,7 +202,6 @@ jobs:
196202 - name : Checkout
197203 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
198204 with :
199- ref : v${{ needs.check-release.outputs.version }}
200205 persist-credentials : false
201206
202207 - name : Install Rust
@@ -225,7 +230,8 @@ jobs:
225230 CARGO_REGISTRY_TOKEN : ${{ steps.crates-io-auth.outputs.token }}
226231
227232 npm-publish :
228- needs : [check-release, build]
233+ needs : [version, build]
234+ if : ${{ !inputs.dry-run }}
229235 runs-on : ubuntu-latest
230236 permissions :
231237 contents : read
@@ -234,7 +240,6 @@ jobs:
234240 - name : Checkout
235241 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
236242 with :
237- ref : v${{ needs.check-release.outputs.version }}
238243 persist-credentials : false
239244
240245 - name : Configure git for HTTPS
@@ -250,6 +255,7 @@ jobs:
250255 uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
251256 with :
252257 node-version : ' 22'
258+ registry-url : ' https://registry.npmjs.org'
253259
254260 - name : Update npm for trusted publishing
255261 run : npm install -g npm@latest
@@ -285,6 +291,8 @@ jobs:
285291 stage_win socket-patch-aarch64-pc-windows-msvc npm/socket-patch-win32-arm64
286292
287293 - name : Publish platform packages
294+ env :
295+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
288296 run : |
289297 for pkg_dir in npm/socket-patch-*/; do
290298 echo "Publishing ${pkg_dir}..."
@@ -298,10 +306,13 @@ jobs:
298306 run : cp README.md npm/socket-patch/README.md
299307
300308 - name : Publish main package
309+ env :
310+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
301311 run : npm publish ./npm/socket-patch --provenance --access public
302312
303313 pypi-publish :
304- needs : [check-release, build]
314+ needs : [version, build]
315+ if : ${{ !inputs.dry-run }}
305316 runs-on : ubuntu-latest
306317 permissions :
307318 contents : read
@@ -310,7 +321,6 @@ jobs:
310321 - name : Checkout
311322 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
312323 with :
313- ref : v${{ needs.check-release.outputs.version }}
314324 persist-credentials : false
315325
316326 - name : Download all artifacts
@@ -329,7 +339,7 @@ jobs:
329339
330340 - name : Build platform wheels
331341 run : |
332- VERSION="${{ needs.check-release .outputs.version }}"
342+ VERSION="${{ needs.version .outputs.version }}"
333343 python scripts/build-pypi-wheels.py --version "$VERSION" --artifacts artifacts --dist dist
334344
335345 - name : Publish to PyPI
0 commit comments