Skip to content

Commit 5c12a61

Browse files
committed
Add npm publish workflow
1 parent 622645b commit 5c12a61

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: Publish to npm
3+
4+
on:
5+
release:
6+
types:
7+
- published
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.release.tag_name || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
publish:
16+
name: Publish Package
17+
runs-on: [self-hosted, macOS]
18+
permissions:
19+
contents: read
20+
steps:
21+
- name: Checkout Repository
22+
uses: actions/checkout@v6
23+
with:
24+
clean: true
25+
ref: ${{ github.event.release.tag_name || github.ref }}
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 22
31+
cache: npm
32+
registry-url: https://registry.npmjs.org
33+
34+
- name: Install Dependencies
35+
run: npm ci
36+
37+
- name: Run Tests
38+
run: npm test
39+
40+
- name: Verify Release Tag Matches package.json
41+
if: github.event_name == 'release'
42+
run: |
43+
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
44+
RELEASE_TAG="${{ github.event.release.tag_name }}"
45+
46+
if [ "$PACKAGE_VERSION" != "$RELEASE_TAG" ]; then
47+
echo "Release tag $RELEASE_TAG does not match package.json version $PACKAGE_VERSION"
48+
exit 1
49+
fi
50+
51+
- name: Publish Package
52+
run: npm publish --access public
53+
env:
54+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)