Skip to content

Commit 56edd76

Browse files
fix: prevent stale tags from poisoning publish version detection
Three issues caused publish failures: 1. Stale tags (e.g. v2.0.0 at merge commit) made commit-and-tag-version see zero new commits and default to patch bump (1.4.0 → 1.4.1) 2. commit-and-tag-version crashed on pre-existing tags with "fatal: tag already exists" 3. Release event path ignored the release tag version Fix: clean stale local tags before bumping, use --skip.tag to separate tag creation from versioning, and create tags manually with force-replace for idempotent re-runs.
1 parent a403acc commit 56edd76

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

.github/workflows/publish.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,35 @@ jobs:
128128
CURRENT=$(node -p "require('./package.json').version")
129129
130130
if [ "${{ github.event_name }}" = "release" ]; then
131-
echo "Triggered by release event — using existing version $CURRENT"
131+
# Extract version from the release tag instead of trusting package.json
132+
TAG="${{ github.event.release.tag_name }}"
133+
RELEASE_VERSION="${TAG#v}"
134+
if [ "$CURRENT" != "$RELEASE_VERSION" ]; then
135+
echo "::warning::package.json ($CURRENT) doesn't match release tag ($TAG) — bumping to match"
136+
npx commit-and-tag-version --release-as "$RELEASE_VERSION" --skip.tag --skip.changelog
137+
else
138+
echo "Triggered by release event — version $CURRENT matches tag $TAG"
139+
fi
132140
else
133141
OVERRIDE="${{ inputs.version-override }}"
142+
143+
# Remove stale local tags newer than current version — these are
144+
# leftovers from prior failed runs and poison commit-and-tag-version's
145+
# bump detection (it uses the latest tag as baseline for commit range)
146+
for tag in $(git tag -l 'v*'); do
147+
TAG_VER="${tag#v}"
148+
if node -e "process.exit(require('semver').gt('$TAG_VER','$CURRENT')?0:1)" 2>/dev/null; then
149+
echo "::warning::Removing stale local tag $tag (newer than v$CURRENT)"
150+
git tag -d "$tag" || true
151+
fi
152+
done
153+
134154
if [ -n "$OVERRIDE" ] && [ "$CURRENT" = "$OVERRIDE" ]; then
135155
echo "Version already at $OVERRIDE — skipping bump"
136156
elif [ -n "$OVERRIDE" ]; then
137-
npx commit-and-tag-version --release-as "$OVERRIDE"
157+
npx commit-and-tag-version --release-as "$OVERRIDE" --skip.tag
138158
else
139-
npx commit-and-tag-version
159+
npx commit-and-tag-version --skip.tag
140160
fi
141161
fi
142162
@@ -225,4 +245,7 @@ jobs:
225245
if: github.event_name == 'workflow_dispatch' && !inputs.dry-run
226246
run: |
227247
git push origin main
228-
git push origin "v${{ steps.version.outputs.new_version }}"
248+
TAG="v${{ steps.version.outputs.new_version }}"
249+
# Create annotated tag (force-replace if stale from a prior run)
250+
git tag -fa "$TAG" -m "release: $TAG"
251+
git push origin "$TAG" --force

0 commit comments

Comments
 (0)