fix(release): let OIDC authenticate the npm publish - #51
Merged
Conversation
The publish job authenticates with npm via OIDC trusted publishing and sets
no NODE_AUTH_TOKEN, but it passed registry-url to setup-node. That makes
setup-node write "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" into
.npmrc, where the unset variable expands to an empty string. npm reads that
as credentials already being configured, skips the OIDC token exchange, and
publishes anonymously, which the registry rejects with E404. 0.3.3 built and
packed correctly but never reached npm.
Drop registry-url so the file is never written; npm already defaults to
registry.npmjs.org. Pin the registry on the publish command instead, so the
target stays explicit at the step that matters without configuring auth.
Add a guard before publish that fails the job if any _authToken is configured,
so this silently reverting to an anonymous publish becomes a loud failure at
the exact assumption that broke.
Refs npm/documentation#1960
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.
Problem
0.3.3 never reached npm. CI passed, the package built and packed correctly (303 kB, 363 files, shasum
fbd4b7d8…), and then the publish died at the upload:lateston npm is still 0.3.2, and there is nov0.3.3tag or GitHub release because the release step runs after publish.The job authenticates via OIDC trusted publishing and deliberately sets no
NODE_AUTH_TOKEN— but it passedregistry-urltosetup-node, which writes//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}into.npmrc. With the variable unset, that expands to an empty string. npm reads the line as "credentials are already configured", skips the OIDC token exchange entirely, and publishes anonymously. The registry rejects it as E404 rather than 403, to avoid confirming whether the package exists. See npm/documentation#1960.Change
registry-urlfromsetup-node, so the conflicting.npmrcis never created. npm already defaults toregistry.npmjs.org, and nothing else in the repo depends on the pin — there is no checked-in.npmrc, andscripts/npm-registry.mjsreaches the registry over plainfetchwith its own default rather than through npm config.npm publishitself instead. The publish target stays explicit at the one step where targeting matters, without configuring auth._authTokenis configured. An anonymous publish surfaces as a bare E404 that points nowhere near its cause, so the invariant is asserted rather than assumed — if a futuresetup-nodechange or a re-addedregistry-urlreintroduces the credential, the job fails loudly at that step.Verification
.npmrc→ pass,.npmrcwithout a token → pass,.npmrcwith the placeholder → fail with the diagnostic.test:release4/4, build clean.npm pack --dry-runreproduces shasumfbd4b7d8bd07e2511e1b00a8f0adb46ed30f493c, byte-identical to the tarball the failed run produced. Only the auth path changes.Notes
The trusted publisher has been configured on npmjs.org for
mathnotes-app/mobile-ink, workflowpublish.yml, environmentnpm. Merging this tomainruns CI, which fires Publish;package.jsonis still at 0.3.3, socheck-npm-version.mjswill see it absent from the registry and publish it, then tagv0.3.3.Separately, and not addressed here:
npm ciruns dependency lifecycle scripts in a job holdingid-token: writeandcontents: write.--ignore-scriptsthere would be worth a follow-up once the build is verified without them.