Skip to content

Commit 5c354f7

Browse files
committed
ci: add npm publish workflow on release
1 parent 8537e44 commit 5c354f7

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
tags:
8+
- 'v*'
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20'
24+
registry-url: 'https://registry.npmjs.org'
25+
cache: 'npm'
26+
27+
- name: Verify version matches tag
28+
run: |
29+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
30+
PKG_VERSION=$(node -p "require('./package.json').version")
31+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
32+
echo "Error: Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)"
33+
exit 1
34+
fi
35+
echo "Version check passed: $PKG_VERSION"
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
- name: Build
41+
run: npm run build
42+
43+
- name: Publish to npm
44+
run: npm publish --access public
45+
env:
46+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)