Skip to content

Commit 3258b26

Browse files
cinderblockclaude
andcommitted
Add npm publish workflow (Trusted Publishing via OIDC)
Publishes to npm automatically when a `v*` tag is pushed. Uses GitHub OIDC trusted publishing (no NPM_TOKEN secret) with provenance, so the package gets a verifiable build attestation and there is no long-lived credential to manage. The job upgrades npm to >= 11.5.1 (required for trusted publishing), installs deps with bun, verifies the tag matches package.json version, then runs `npm publish --provenance` — which triggers the existing prepublishOnly gate (check, typecheck, test, licenses, build). Requires the npm package to have a Trusted Publisher configured for this repo + the publish.yml workflow (done on npmjs.com). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a073bea commit 3258b26

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish
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+
id-token: write # required for npm Trusted Publishing (OIDC) + provenance
14+
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- uses: oven-sh/setup-bun@v2
19+
with:
20+
bun-version: latest
21+
22+
- uses: actions/setup-node@v6
23+
with:
24+
node-version: lts/*
25+
registry-url: https://registry.npmjs.org
26+
27+
# Trusted Publishing + provenance need npm >= 11.5.1.
28+
- run: npm install -g npm@latest
29+
30+
- run: bun install --frozen-lockfile
31+
32+
- name: Verify tag matches package.json version
33+
run: |
34+
TAG="${GITHUB_REF_NAME#v}"
35+
PKG="$(node -p "require('./package.json').version")"
36+
echo "tag=${TAG} package.json=${PKG}"
37+
if [ "${TAG}" != "${PKG}" ]; then
38+
echo "::error::Tag v${TAG} does not match package.json version ${PKG}"
39+
exit 1
40+
fi
41+
42+
# `npm publish` runs the prepublishOnly gate (check, typecheck, test,
43+
# licenses, build). Auth is via OIDC — no NPM_TOKEN needed.
44+
- run: npm publish --provenance --access public

0 commit comments

Comments
 (0)