Skip to content

Commit 26300b9

Browse files
authored
Merge pull request #21 from optave/feat/registry-hardening
fix: harden publish workflow against stale tags and version misdetection
2 parents 9bd9ce1 + 6906448 commit 26300b9

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

.github/workflows/publish.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,23 @@ 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 }}"
134142
if [ -n "$OVERRIDE" ] && [ "$CURRENT" = "$OVERRIDE" ]; then
135143
echo "Version already at $OVERRIDE — skipping bump"
136144
elif [ -n "$OVERRIDE" ]; then
137-
npx commit-and-tag-version --release-as "$OVERRIDE"
145+
npx commit-and-tag-version --release-as "$OVERRIDE" --skip.tag
138146
else
139-
npx commit-and-tag-version
147+
npx commit-and-tag-version --skip.tag
140148
fi
141149
fi
142150
@@ -225,4 +233,11 @@ jobs:
225233
if: github.event_name == 'workflow_dispatch' && !inputs.dry-run
226234
run: |
227235
git push origin main
228-
git push origin "v${{ steps.version.outputs.new_version }}"
236+
TAG="v${{ steps.version.outputs.new_version }}"
237+
# Skip if tag already exists on remote (e.g. created by a GitHub release)
238+
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
239+
echo "Tag $TAG already exists on remote — skipping tag push"
240+
else
241+
git tag -a "$TAG" -m "release: $TAG"
242+
git push origin "$TAG"
243+
fi

0 commit comments

Comments
 (0)