Skip to content

Commit ba47bed

Browse files
committed
ci: add tag-based publish workflow for npm and GitHub Packages
- trigger on v* tags - validate tag version matches package.json - run tests before publishing - publish to npm via NPM_TOKEN and GitHub Packages via GITHUB_TOKEN
1 parent e9d0bc0 commit ba47bed

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish package
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
registry-url: https://registry.npmjs.org
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run tests
29+
run: npm test
30+
31+
- name: Validate tag matches package version
32+
run: |
33+
TAG_VERSION="${GITHUB_REF_NAME#v}"
34+
PKG_VERSION="$(node -p \"require('./package.json').version\")"
35+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
36+
echo "Tag version v$TAG_VERSION does not match package.json version $PKG_VERSION"
37+
exit 1
38+
fi
39+
40+
- name: Publish to npm
41+
run: npm publish --access public
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
45+
- name: Publish to GitHub Packages
46+
run: |
47+
npm config set @timmsy:registry https://npm.pkg.github.com
48+
npm publish --registry=https://npm.pkg.github.com
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)