Skip to content

Commit d80f689

Browse files
committed
ci: add npm OIDC trusted-publish workflow
Triggers on v* tag push or manual dispatch. Builds, tests, then publishes codeburn to npm with provenance attestation. Uses OIDC so no NPM_TOKEN is stored in repo secrets. The npm-publish GitHub Environment gates the publish step behind a required reviewer, so every release needs explicit human approval before it reaches the registry. Tag/package version mismatch fails fast before any build work. Tests run before publish to prevent shipping a broken release.
1 parent 7a5cb32 commit d80f689

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/publish-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+
# Triggers when a semver tag (v*) is pushed. Publishes `codeburn` to the npm
4+
# registry using npm OIDC trusted publishing, so no NPM_TOKEN lives in
5+
# secrets. The `npm-publish` Environment requires a human approval before
6+
# the publish step runs.
7+
on:
8+
push:
9+
tags:
10+
- 'v*'
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
id-token: write # Required for npm OIDC provenance
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
environment: npm-publish
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '22'
29+
registry-url: 'https://registry.npmjs.org'
30+
31+
- name: Verify tag matches package.json
32+
run: |
33+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
34+
PKG_VERSION=$(node -p "require('./package.json').version")
35+
if [[ "$TAG_VERSION" != "$PKG_VERSION" ]]; then
36+
echo "Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)" >&2
37+
exit 1
38+
fi
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
43+
- name: Build
44+
run: npm run build
45+
46+
- name: Run tests
47+
run: npm test -- --run
48+
49+
- name: Publish with provenance
50+
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)