Skip to content

Commit a9ed95e

Browse files
chore: add release workflow to publish on GitHub Release (#18)
Publishes the package to npm when a GitHub Release is published (or via manual workflow_dispatch). Uses npm publish with provenance so the npmjs listing shows a verified build origin. Guards against version drift: if the release tag (e.g. v2.0.2) does not match package.json version, the job fails before publishing.
1 parent df28602 commit a9ed95e

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: pnpm/action-setup@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
registry-url: https://registry.npmjs.org
22+
cache: pnpm
23+
- run: pnpm install --frozen-lockfile
24+
- name: Verify tag matches package.json version
25+
if: github.event_name == 'release'
26+
run: |
27+
TAG="${GITHUB_REF_NAME#v}"
28+
PKG=$(node -p "require('./package.json').version")
29+
if [ "$TAG" != "$PKG" ]; then
30+
echo "tag $GITHUB_REF_NAME ($TAG) does not match package.json version $PKG"
31+
exit 1
32+
fi
33+
- run: pnpm check
34+
- run: pnpm test -- --run
35+
- run: pnpm build
36+
- run: npm publish --provenance --access public
37+
env:
38+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)