Skip to content

Commit 55de118

Browse files
Add GitHub Actions workflow for automated NPM publishing
This workflow automates the process of publishing the package to NPM when a new GitHub release is created. It includes: - Setting up Node.js 20 environment - Building and testing the package - Extracting version from the release tag - Publishing to NPM with provenance for enhanced security
1 parent c4bfa13 commit 55de118

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/npm.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write # Required for npm provenance
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
registry-url: 'https://registry.npmjs.org'
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Build package
29+
run: npm run build
30+
31+
- name: Run tests
32+
run: npm test
33+
34+
- name: Extract version from tag
35+
id: version
36+
run: |
37+
# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
38+
VERSION=${GITHUB_REF#refs/tags/}
39+
VERSION=${VERSION#v}
40+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
41+
echo "Version: ${VERSION}"
42+
43+
- name: Update package.json version
44+
run: |
45+
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
46+
47+
- name: Publish to NPM
48+
run: npm publish --provenance --access public
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)