Skip to content

Commit c2b1be6

Browse files
committed
Add npm publish workflow triggered by semver tags
1 parent b31b6f4 commit c2b1be6

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish to npm
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- '[0-9]*.[0-9]*.[0-9]*'
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 24
23+
cache: npm
24+
registry-url: https://registry.npmjs.org
25+
26+
- run: npm ci
27+
28+
- name: Verify tag matches package.json version
29+
if: github.event_name == 'push'
30+
env:
31+
TAG: ${{ github.ref_name }}
32+
run: |
33+
PKG_VERSION=$(node -p "require('./package.json').version")
34+
if [ "$TAG" != "$PKG_VERSION" ]; then
35+
echo "Tag '$TAG' does not match package.json version '$PKG_VERSION'."
36+
exit 1
37+
fi
38+
39+
- run: npm run lint
40+
- run: npm run format:check
41+
- run: npm run typecheck
42+
- run: npm run build
43+
- run: npm test
44+
45+
- run: npm publish --provenance --access public

0 commit comments

Comments
 (0)