Skip to content

Commit 5589b78

Browse files
committed
ci(stable-release): make version bump idempotent
`npm version <X> --no-git-tag-version` errors when the package.json version is already <X> — which is what happens when the version was bumped in a PR before the release workflow runs. The v0.2.0 dispatch hit this and the run died at the bump step. - Replace `npm version` with `npm pkg set "version=$VERSION"` which is a no-op when the value is already correct. - Skip the version-bump commit if package.json/lock are unchanged after staging (still tag + push). Otherwise `git commit` errors with "nothing to commit".
1 parent 677ef45 commit 5589b78

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/stable-release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ jobs:
4343
- name: Update package.json version
4444
env:
4545
VERSION: ${{ inputs.version }}
46-
run: npm version "$VERSION" --no-git-tag-version
46+
# `npm version` errors when the requested version equals the current
47+
# (which happens when the version was bumped in a PR before the
48+
# release workflow runs). `npm pkg set` is idempotent.
49+
run: npm pkg set "version=$VERSION"
4750

4851
- run: npm ci
4952
- run: npx tsc --noEmit
@@ -58,7 +61,14 @@ jobs:
5861
git config user.name "github-actions[bot]"
5962
git config user.email "github-actions[bot]@users.noreply.github.com"
6063
git add package.json package-lock.json
61-
git commit -m "chore: release v${VERSION}"
64+
# If the version was already bumped in a PR (so package.json/lock
65+
# are unchanged here) skip the commit. The tag and push still need
66+
# to run.
67+
if ! git diff --cached --quiet; then
68+
git commit -m "chore: release v${VERSION}"
69+
else
70+
echo "package.json already at v${VERSION}; skipping bump commit"
71+
fi
6272
git tag "v${VERSION}"
6373
git push origin main --follow-tags
6474

0 commit comments

Comments
 (0)