Skip to content

ci: publish to npm via Trusted Publishing instead of a 2FA-gated token - #1235

Merged
Naturalclar merged 1 commit into
masterfrom
ci/npm-trusted-publishing
Nov 15, 2026
Merged

Naturalclar merged 1 commit into
masterfrom
ci/npm-trusted-publishing

Conversation

@Naturalclar

Copy link
Copy Markdown
Member

Why

The first real run of the Release workflow (run 43671657901) failed at the publish step:

npm error code EOTP
npm error This operation requires a one-time password from your authenticator.

The NPM_TOKEN secret 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 computed 2.0.0...2.1.0 and a correct changelog. And release-it publishes before tagging, so it rolled back cleanly: no v2.1.0 tag, no chore: release commit, no GitHub release, and npm latest is still 2.0.0. Nothing to unwind — 2.1.0 just 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.yml

  • id-token: write added to the job's permissions, so npm can exchange the run's OIDC token for publish rights.
  • npm upgraded to >= 11.5.1. Not cosmetic — the failing run used npm 10.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_TOKEN dropped from the Release step, 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.
  • Header comment rewritten to document the npm-side binding and the fact that it is tied to this filename.

package.json

  • release-it → npm.skipChecks: true. The non-obvious part. release-it 18.1.2's npm plugin init() gates publishing on npm whoami and npm access list collaborators, and its error handler only tolerates E400/E404. Under OIDC there is no credential for whoami to use — npm publish mints it itself — so this would have failed with ENEEDAUTH and 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 plain npm publish, so the actual publish picks up OIDC fine.)
  • repository normalized to the object form, silencing the npm auto-corrected some errors in your package.json warning 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:

  1. npmjs.com → @react-native-menu/menu → Settings → Trusted publisher → GitHub Actions, org/repo react-native-menu/menu, workflow release.yml
  2. Delete the now-unused secret: gh secret delete NPM_TOKEN
  3. Re-run Release via workflow_dispatch to ship 2.1.0

Notes

  • Trusted publishing cannot be used for a package's first publish, but @react-native-menu/menu already exists at 2.0.0, so this is fine.
  • fix(ios): pass taps to the children of a long-press MenuView on Fabric #1233 (release-it 20.2.1) is open; release-it 20 may be OIDC-aware enough to make skipChecks unnecessary. Worth revisiting when taking that bump.
  • Build does 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

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>
@Naturalclar
Naturalclar merged commit c401309 into master Nov 15, 2026
5 checks passed
@Naturalclar
Naturalclar deleted the ci/npm-trusted-publishing branch November 15, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant