fix(ci): pass NPM_TOKEN to the publish steps, not just NODE_AUTH_TOKEN - #15
Merged
Conversation
The 0.5.0 release failed at the credential check with `401 Unauthorized` from
`npm whoami`. That reads as a revoked or mistyped token. It was neither — the
token is fine and the workflow was wrong.
This repository's `.npmrc` reads
`//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, and npm's project config
outranks the userconfig that `setup-node` writes. So for any command run from
the repository root the repo `.npmrc` wins, and it wants NPM_TOKEN — a name the
workflow never set, because it set only NODE_AUTH_TOKEN.
Critically, npm does not fall back to the userconfig when the variable is
missing. It sends the literal, unexpanded text as the bearer token. Confirmed
against a local registry that echoes the Authorization header:
NPM_TOKEN unset -> AUTH_HEADER: "Bearer ${NPM_TOKEN}"
NPM_TOKEN set -> AUTH_HEADER: "Bearer REAL_TOKEN_VALUE"
The first is indistinguishable, from the registry's side, from a garbage
credential — hence the 401 and the misleading diagnosis.
Both publish steps now set NPM_TOKEN alongside NODE_AUTH_TOKEN. They stay
step-scoped rather than job-scoped so the token is not exposed to `pnpm -r test`.
verify-npm-publish-access.mjs now checks NPM_TOKEN is present and expanded before
calling the registry, so a recurrence names the cause instead of surfacing an
authentication error that sends you looking at the token.
Verified: both guard paths exit 1 with an accurate message, architecture guard
passes, workflow YAML parses with the trigger intact.
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.
Summary
The
cli-v0.5.0release failed at the credential check with401 Unauthorizedfromnpm whoami. That looks like a revoked or mistyped token. It was neither — the token is fine and this workflow was wrong.This repository's
.npmrcreads:npm's project config outranks the userconfig that
setup-nodewrites, so for any command run from the repository root the repo.npmrcwins — and it wantsNPM_TOKEN, a name the workflow never set. It set onlyNODE_AUTH_TOKEN.The part that makes this misdiagnose so cleanly: npm does not fall back to the userconfig when the variable is missing. It sends the literal, unexpanded text as the bearer token. Confirmed against a local registry that echoes the
Authorizationheader:From the registry's side the first is indistinguishable from a garbage credential — hence the 401, and hence an error that points at the secret instead of at the workflow.
Changes
NPM_TOKENalongsideNODE_AUTH_TOKEN. Kept step-scoped rather than job-scoped, so the publish token is not exposed topnpm -r test.verify-npm-publish-access.mjsnow checksNPM_TOKENis present and expanded before touching the registry. A recurrence names the cause instead of returning an authentication error that sends you to revoke a perfectly good token.Verification
pnpm run check:architectureon.push.tagstrigger intactpnpm -r testetc. — not re-run; no application code changed (workflow env and one release script)Notes
Nothing was published by the failed run:
@workspacejson/clistill 404s, so0.5.0is not burned.After merge the
cli-v0.5.0tag must be recreated, not just re-run. Tag-triggered workflows execute the workflow file as of the tagged commit, so re-running the existing tag would replay the broken version. Delete the tag, re-tag at the newmainhead, push.The invalid
cli-v0.5.1tag has already been deleted locally and on the remote.