feat: switch npm publish to Trusted Publishing (OIDC), drop NPM_TOKEN - #4
Conversation
npm retired classic Automation tokens in the 2025 overhaul; the token stored for #2 was a classic Publish token that still enforces 2FA OTP in CI (the EOTP the first publish run hit). Trusted Publishing replaces the token entirely: GitHub Actions OIDC (id-token: write, already granted) mints a short-lived workflow-scoped token that npm exchanges for publish rights — nothing to store, rotate, or leak. Changes: - Remove the NPM_TOKEN requirement step and NODE_AUTH_TOKEN env. - Upgrade npm to >= 11.5.1 in-run (Node 22 ships npm 10.x; Trusted Publishing needs 11.5.1+ / Node 22.14+). - Provenance stays automatic for a public repo+package; --provenance kept explicit. - README + header document the one-time npmjs.com Trusted Publisher config (the only remaining human step, replacing the token secret). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
AI review (advisory) — cycle 1
SummaryCorrect migration from a stored token to npm Trusted Publishing (OIDC). Verified against npm's current docs: the mechanism needs exactly what this workflow provides — Findingsnit: No blockers. Prior workflow guards preserved: main-ref gate, whole-string name/version validation, version-change publish gate, ripgrep install (#3). Verification
Handoff — the one-time step this replaces the token withOn npmjs.com: hardcode-replacer → Settings → Trusted Publisher → GitHub Actions → org Verdict (a5ca05c): APPROVE (handoff — merge is yours) |
What
Switches the push-to-publish workflow from a stored npm token to npm Trusted Publishing (OIDC). No
NPM_TOKENsecret at all — GitHub Actions mints a short-lived, workflow-scoped OIDC token (id-token: write, already granted) that npm exchanges for publish rights.Why
You were right that classic Automation tokens no longer exist — npm retired them in the 2025 token overhaul. The token stored for #2 was a classic Publish token, which still enforces 2FA OTP in CI: the first
mainpublish run got all the way through tests and provenance-signing, then failed withEOTP("requires a one-time password"). Trusted Publishing is the modern replacement and is strictly better — nothing to store, rotate, or leak, and provenance stays automatic.Changes
NPM_TOKENrequirement step and theNODE_AUTH_TOKENenv on publish.npm install -g npm@latest— Trusted Publishing needs npm CLI ≥ 11.5.1 / Node ≥ 22.14, and Node 22's bundled npm is 10.x.--provenancekept explicit (automatic for a public repo + package anyway).One-time setup (package owner — replaces the token secret)
On npmjs.com, hardcode-replacer → Settings → Trusted Publisher → GitHub Actions:
ytsparhardcode-replacerpublish.ymlThen merge this PR. The
mainrun sees2.3.0 ≠ registry (2.2.0)and performs the pending v2.3.0 publish with zero token. You can also delete the now-unusedNPM_TOKENsecret and optionally enable "require 2FA and disallow tokens" on the package for defense in depth.Testing
ciruns jest on this PR (ripgrep installed, per #3). The publish path only runs onmain.