Skip to content

Commit 7e22ab3

Browse files
committed
chore: enhance npm publish workflow with structured steps and version check
1 parent d74c84e commit 7e22ab3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

.github/workflows/npm-publish.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@ jobs:
1616
with:
1717
node-version: 20
1818
registry-url: https://registry.npmjs.org/
19-
- run: npm ci
20-
- run: npm test
21-
- run: npm run build
22-
- run: npm publish
19+
cache: "npm"
20+
- name: Install dependencies
21+
run: npm ci
22+
- name: Run tests
23+
run: npm test
24+
- name: Build package
25+
run: npm run build
26+
- name: Check package version matches release
27+
run: |
28+
PKG_VERSION=$(node -p "require('./package.json').version")
29+
GITHUB_REF_VERSION=${GITHUB_REF#refs/tags/v}
30+
if [ "$PKG_VERSION" != "$GITHUB_REF_VERSION" ]; then
31+
echo "::error::Package version ($PKG_VERSION) does not match release tag ($GITHUB_REF_VERSION)"
32+
exit 1
33+
fi
34+
- name: Publish to NPM
35+
run: npm publish --provenance --access public
2336
env:
2437
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

0 commit comments

Comments
 (0)