Skip to content

Commit 5519557

Browse files
committed
ci: make release version check robust against stale runs and prereleases
- Check whether the exact version is already published on npm instead of comparing against urllib@latest, so a prerelease under its own dist-tag is not treated as perpetually newer than latest and re-released - Add workflow concurrency (cancel-in-progress) to cancel an older run still pending approval when a newer version lands - Re-check publication state immediately before npm publish as a guard against a stale run approved after a newer version was published
1 parent 4d9aded commit 5519557

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ on:
88

99
permissions: {}
1010

11+
# Serialize releases and cancel an older run still pending approval when a
12+
# newer version lands, so an approved-late stale run cannot publish backwards.
13+
concurrency:
14+
group: ${{ github.workflow }}
15+
cancel-in-progress: true
16+
1117
jobs:
1218
check:
1319
if: github.repository == 'node-modules/urllib'
@@ -22,13 +28,22 @@ jobs:
2228
- name: Checkout repository
2329
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
2430

25-
- name: Check version changes
26-
uses: EndBug/version-check@095362f3cd50f690c8fa0e6afeea81834bd8d320 # v3.0.0
31+
- name: Check whether version is already published
2732
id: version
28-
with:
29-
static-checking: localIsNew
30-
file-url: https://unpkg.com/urllib@latest/package.json
31-
file-name: package.json
33+
run: |
34+
set -euo pipefail
35+
# Compare the exact version against the registry, not against `latest`,
36+
# so prereleases (published under their own dist-tag) are not treated
37+
# as perpetually newer than the stable `latest` and re-released.
38+
VERSION=$(node -p "require('./package.json').version")
39+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
40+
if npm view "urllib@$VERSION" version > /dev/null 2>&1; then
41+
echo "urllib@$VERSION is already published; nothing to release."
42+
echo "changed=false" >> "$GITHUB_OUTPUT"
43+
else
44+
echo "urllib@$VERSION is not published yet; proceeding."
45+
echo "changed=true" >> "$GITHUB_OUTPUT"
46+
fi
3247
3348
request-approval:
3449
name: Request approval
@@ -98,6 +113,15 @@ jobs:
98113
echo "tag=latest" >> "$GITHUB_OUTPUT"
99114
fi
100115
116+
- name: Re-check version before publish
117+
run: |
118+
set -euo pipefail
119+
# Guard against a stale run approved after a newer version was published.
120+
if npm view "urllib@$VERSION" version > /dev/null 2>&1; then
121+
echo "::error::urllib@$VERSION is already published; aborting to avoid republishing a stale version."
122+
exit 1
123+
fi
124+
101125
- name: Publish to npm
102126
run: npm publish --access public --tag ${{ steps.dist-tag.outputs.tag }}
103127

0 commit comments

Comments
 (0)