Skip to content

Commit a586073

Browse files
committed
fix(release): add preflight checks for version consistency in publish workflow
1 parent a5d19e7 commit a586073

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ jobs:
4040
- name: Build
4141
run: bun run build
4242

43+
- name: Preflight publish context
44+
run: |
45+
set -euo pipefail
46+
47+
PACKAGE_NAME="$(node -p \"require('./package.json').name\")"
48+
PACKAGE_VERSION="$(node -p \"require('./package.json').version\")"
49+
TAG_NAME="${GITHUB_REF_NAME}"
50+
51+
echo "Repository: ${GITHUB_REPOSITORY}"
52+
echo "Workflow: ${GITHUB_WORKFLOW}"
53+
echo "Ref: ${GITHUB_REF}"
54+
echo "Tag: ${TAG_NAME}"
55+
echo "Package: ${PACKAGE_NAME}"
56+
echo "Version: ${PACKAGE_VERSION}"
57+
58+
echo "Current npm version (if already published):"
59+
npm view "${PACKAGE_NAME}" version || true
60+
61+
if [ "${TAG_NAME}" != "v${PACKAGE_VERSION}" ]; then
62+
echo "Tag (${TAG_NAME}) does not match package version (v${PACKAGE_VERSION})."
63+
exit 1
64+
fi
65+
4366
- name: Publish to npm (Trusted Publisher)
4467
run: npm publish --provenance --access public
4568

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"clean": "rimraf .vite dist",
5959
"changelog": "changelogen --output CHANGELOG.md",
6060
"changelog:bump": "changelogen --bump --output CHANGELOG.md",
61-
"release": "bun run build && changelogen --release --output CHANGELOG.md && (git rev-parse -q --verify refs/tags/v$npm_package_version >/dev/null || git tag v$npm_package_version) && git push origin v$npm_package_version"
61+
"release": "bun run build && changelogen --bump --output CHANGELOG.md && (git rev-parse -q --verify refs/tags/v$npm_package_version >/dev/null || git tag v$npm_package_version) && git push origin v$npm_package_version"
6262
},
6363
"publishConfig": {
6464
"access": "public"

0 commit comments

Comments
 (0)