Skip to content

Commit af880d9

Browse files
JohnMcLearclaude
andcommitted
ci: skip npm publish when no new commits since last tag
The bump step in npmpublish.yml early-exits when there are no new commits since the latest tag, but the publish step then runs unconditionally and tries to republish the existing version, failing with 'cannot publish over previously published versions'. Only fires for manual `gh workflow run` on a tag-current branch (on:push always has ≥1 new commit), but leaves a spurious red on CI. Gate the post-bump steps on a new `bumped` step output. Template-wide fix: ep_subscript_and_superscript#127 was the pilot. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7da2380 commit af880d9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

.github/workflows/npmpublish.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ jobs:
5353
fetch-depth: 0
5454
-
5555
name: Bump version (patch)
56+
id: bump
5657
run: |
5758
LATEST_TAG=$(git describe --tags --abbrev=0) || exit 1
5859
NEW_COMMITS=$(git rev-list --count "${LATEST_TAG}"..) || exit 1
59-
[ "${NEW_COMMITS}" -gt 0 ] || exit 0
60+
# No new commits since the last tag → nothing to publish.
61+
# Setting `bumped=false` lets the publish step below skip
62+
# itself instead of trying to republish the existing version
63+
# (which fails with "cannot publish over previously published
64+
# versions"). Only manual `gh workflow run` invocations on a
65+
# tag-current branch hit this path; on:push always sees ≥1
66+
# new commit because the push event is what triggered us.
67+
if [ "${NEW_COMMITS}" -le 0 ]; then
68+
echo "bumped=false" >> "${GITHUB_OUTPUT}"
69+
exit 0
70+
fi
6071
git config user.name 'github-actions[bot]'
6172
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
6273
pnpm i --frozen-lockfile
@@ -84,9 +95,11 @@ jobs:
8495
# rejects the tag push too, and the next workflow tick can retry
8596
# cleanly against the up-to-date refs.
8697
git push --atomic origin "${GITHUB_REF_NAME}" "${NEW_TAG}"
98+
echo "bumped=true" >> "${GITHUB_OUTPUT}"
8799
# This is required if the package has a prepare script that uses something
88100
# in dependencies or devDependencies.
89101
-
102+
if: steps.bump.outputs.bumped == 'true'
90103
run: pnpm i
91104
# `npm publish` must come after `git push` otherwise there is a race
92105
# condition: If two PRs are merged back-to-back then master/main will be
@@ -104,4 +117,5 @@ jobs:
104117
# whichever `npm` is on PATH; calling `npm` directly avoids any shim
105118
# ambiguity.
106119
- name: Publish to npm via OIDC
120+
if: steps.bump.outputs.bumped == 'true'
107121
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)