Skip to content

Commit 37e81a1

Browse files
switch npm publishing to trusted publishing (OIDC)
- Grant the job id-token: write (plus contents: read for the tag guard and release-asset download); npm publish exchanges the GitHub OIDC token for a short-lived per-publish credential and generates provenance attestations automatically. - Drop registry-url from setup-node: it writes an .npmrc authToken line referencing $NODE_AUTH_TOKEN, and npm hard-fails on every command when a referenced env var is unset. - Bump to Node 24 (Node 20 is EOL) and pin npm@12.0.1 alongside the existing semver pin — trusted publishing requires npm >= 11.5.1 and the runner's bundled npm may lag. - Remove NODE_AUTH_TOKEN from the publish step; no registry token is referenced anywhere anymore.
1 parent 19a4a56 commit 37e81a1

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ jobs:
3737
npm:
3838
name: Publish to npm
3939
runs-on: ubuntu-latest
40+
permissions:
41+
# Publishing authenticates via npm trusted publishing: the job mints a
42+
# GitHub OIDC token that npm verifies against each package's trusted
43+
# publisher config (this repo + this workflow filename). No registry
44+
# token exists anywhere.
45+
id-token: write
46+
contents: read
4047
steps:
4148
- name: Require the newest stable vX.Y.Z tag
4249
run: |
@@ -64,20 +71,24 @@ jobs:
6471
with:
6572
ref: ${{ env.TAG }}
6673

74+
# No registry-url here: setup-node would write an .npmrc authToken
75+
# line referencing $NODE_AUTH_TOKEN, and npm hard-fails on any command
76+
# when a referenced env var is unset. Trusted publishing needs no
77+
# token; npm publish detects the OIDC environment on its own.
6778
- uses: actions/setup-node@v4
6879
with:
69-
node-version: "20"
70-
registry-url: "https://registry.npmjs.org"
80+
node-version: "24"
7181

72-
# Installed up front so a fetch failure is a loud step failure. If the
73-
# publish loop fetched it via npx on demand, a transient network error
74-
# would be indistinguishable from "version not newer" and would
75-
# silently skip publishing a package. Pinned to an exact version: this
76-
# is the only third-party code fetched into the job that holds publish
77-
# rights for the @provablehq packages, and npm versions are immutable,
78-
# so a pin closes off both drift and package-takeover of new releases.
79-
- name: Install semver CLI
80-
run: npm install -g semver@7.8.5
82+
# npm >= 11.5.1 is required for trusted publishing; the runner's
83+
# bundled npm may lag. Both tools installed up front so a fetch
84+
# failure is a loud step failure (npx-on-demand in the publish loop
85+
# would be indistinguishable from "version not newer" and silently
86+
# skip a package), and pinned to exact versions: this is the only
87+
# third-party code fetched into the job that holds publish rights for
88+
# the @provablehq packages, and npm versions are immutable, so a pin
89+
# closes off both drift and package-takeover of new releases.
90+
- name: Install pinned npm and semver CLI
91+
run: npm install -g npm@12.0.1 semver@7.8.5
8192

8293
- name: Download release assets
8394
run: gh release download "$TAG" --pattern '*.zip' --dir artifacts
@@ -133,5 +144,3 @@ jobs:
133144
publish "./${pkg%/}"
134145
done
135146
publish ./dist-npm/main
136-
env:
137-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)