Skip to content

Commit 5c8b9a2

Browse files
authored
Add npm provenance publish workflow (#2)
1 parent be61d36 commit 5c8b9a2

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
attestations: write
11+
artifact-metadata: write
12+
13+
jobs:
14+
publish:
15+
name: publish to npmjs
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: checkout
20+
uses: actions/checkout@v6
21+
22+
- name: setup node 24
23+
uses: actions/setup-node@v6
24+
with:
25+
node-version: 24
26+
registry-url: https://registry.npmjs.org
27+
cache: npm
28+
29+
- name: verify publish toolchain
30+
run: |
31+
node --version
32+
npm --version
33+
node -e "const version = require('node:child_process').execFileSync('npm', ['--version'], { encoding: 'utf8' }).trim(); const [major, minor, patch] = version.split('.').map(Number); if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) throw new Error('npm 11.5.1 or newer is required for trusted publishing')"
34+
35+
- name: install dependencies
36+
run: npm ci
37+
38+
- name: run tests
39+
run: npm test
40+
41+
- name: audit dependencies
42+
run: npm audit --audit-level=moderate
43+
44+
- name: verify runtime dependency tree
45+
run: npm ls --omit=dev --all
46+
47+
- name: pack package
48+
id: pack
49+
run: |
50+
mkdir -p dist
51+
npm pack --json --pack-destination dist > dist/pack.json
52+
tarball="$(find dist -maxdepth 1 -name '*.tgz' -print -quit)"
53+
test -n "$tarball"
54+
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
55+
56+
- name: attest npm package artifact
57+
uses: actions/attest@v4
58+
with:
59+
subject-path: ${{ steps.pack.outputs.tarball }}
60+
61+
- name: upload npm package artifact
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: npm-package
65+
path: ${{ steps.pack.outputs.tarball }}
66+
if-no-files-found: error
67+
68+
- name: publish package
69+
run: npm publish "$TARBALL" --provenance --access public
70+
env:
71+
TARBALL: ${{ steps.pack.outputs.tarball }}
72+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)