Repository navigation
ci: publish to npm via Trusted Publishing instead of a 2FA-gated token - #1235
Merged
Merged
Conversation
The first real run of the Release workflow failed at `npm publish` with `EOTP`: the NPM_TOKEN secret is a classic *Publish* token, which still demands a one-time password. Only classic *Automation* tokens and granular access tokens bypass 2FA. release-it rolled back cleanly, so 2.1.0 was never tagged or published. Rather than swap in another token that expires on a 90-day cadence, move to npm Trusted Publishing (OIDC): npm mints a short-lived credential from the workflow's own GitHub identity, so there is no secret to rotate and the tarball gets a provenance attestation. - add `id-token: write` so npm can exchange the run's OIDC token - upgrade npm to >= 11.5.1; Node 22 ships 10.9.9, which has no OIDC support and would quietly fall back to looking for a token - drop NODE_AUTH_TOKEN, which would otherwise take precedence over OIDC - set release-it's `npm.skipChecks`. Its npm plugin gates publishing on `npm whoami` and `npm access list collaborators`, both of which need a long-lived token; under OIDC there is none, since `npm publish` mints the credential itself. The checks fail with ENEEDAUTH and abort the release before it starts. Also normalize the `repository` field to the object form, which silences the "npm auto-corrected some errors in your package.json" publish warning. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The first real run of the
Releaseworkflow (run 43671657901) failed at the publish step:The
NPM_TOKENsecret is a classic Publish token, which still demands a 2FA one-time password. Only classic Automation tokens and granular access tokens bypass 2FA.Everything before the publish worked correctly — the guard found 4 releasable commits since
v2.0.0, release-it computed2.0.0...2.1.0and a correct changelog. And release-it publishes before tagging, so it rolled back cleanly: nov2.1.0tag, nochore: releasecommit, no GitHub release, and npmlatestis still2.0.0. Nothing to unwind —2.1.0just needs a retry once auth works.Rather than swap in another token that expires on a 90-day cadence, this moves to npm Trusted Publishing (OIDC): npm mints a short-lived credential from the workflow's own GitHub identity, so there is no secret to rotate and the published tarball carries a provenance attestation.
What changed
.github/workflows/release.ymlid-token: writeadded to the job'spermissions, so npm can exchange the run's OIDC token for publish rights.>= 11.5.1. Not cosmetic — the failing run used npm10.9.9(what Node 22 ships), which has no OIDC support at all and would quietly fall back to looking for a token.NODE_AUTH_TOKENdropped from theReleasestep, with a comment on why it must stay absent: a token present in the env takes precedence over OIDC and would put us straight back on the 2FA-gated path.package.jsonrelease-it→npm.skipChecks: true. The non-obvious part. release-it 18.1.2's npm plugininit()gates publishing onnpm whoamiandnpm access list collaborators, and its error handler only toleratesE400/E404. Under OIDC there is no credential forwhoamito use —npm publishmints it itself — so this would have failed withENEEDAUTHand thrown "Not authenticated with npm" before ever attempting the publish. Without this, the migration would fail in a new and more confusing way. (release-it shells out to plainnpm publish, so the actual publish picks up OIDC fine.)repositorynormalized to the object form, silencing thenpm auto-corrected some errors in your package.jsonwarning seen in the run log.Required npm-side setup before merging helps
This PR alone does not fix publishing — the trusted publisher has to exist on npm first:
@react-native-menu/menu→ Settings → Trusted publisher → GitHub Actions, org/reporeact-native-menu/menu, workflowrelease.ymlgh secret delete NPM_TOKENReleaseviaworkflow_dispatchto ship2.1.0Notes
@react-native-menu/menualready exists at2.0.0, so this is fine.release-it20.2.1) is open; release-it 20 may be OIDC-aware enough to makeskipChecksunnecessary. Worth revisiting when taking that bump.Builddoes not exercise the release path, so CI passing here only confirms nothing else broke. The real verification is step 3 above.🤖 Generated with Claude Code