Repository navigation
fix: missing npm token treated as trusted pub - #35
Merged
Merged
Conversation
Merged
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.
Description
Fixes a publish-auth bug where a missing
npm-tokenwas treated as "use TrustedPublishers (OIDC)." That assumption breaks the common setup where you authenticate
via
actions/setup-node+NODE_AUTH_TOKENand deliberately don't pass a token tothis action: the action overwrote the
.npmrcsetup-node manages (wiping the authline) and then
rm'd it, producingnpm error code ENEEDAUTHagainsthttps://npm.pkg.github.com— while logging the misleading "using TrustedPublishers (OIDC)" message.
The auth mode is now resolved from what's actually present, in three distinct cases:
.npmrcnpm-tokenset.npmrc, removed after publishid-token: write(OIDC).npmrc, removed after publishNODE_AUTH_TOKEN/~/.npmrc)OIDC is detected via
ACTIONS_ID_TOKEN_REQUEST_URL, which GitHub sets only whenid-token: writeis granted — the real signal for Trusted Publishers, rather thaninferring it from the absence of a token. Cleanup now only removes an
.npmrctheaction itself wrote, so a file from a prior step is never deleted.
The logic is extracted into a new, unit-testable helper
scripts/npm-auth.sh(
npm_auth_mode,registry_host,write_npmrc), matching the style of theexisting
workspaces.sh/install.shhelpers.Fixes # (issue)
Type of change
How Has This Been Tested?
Added
tests/npm-auth.bats(10 tests) covering all three auth modes, token-beats-OIDCprecedence, registry-host normalization, exact
.npmrccontents for token/OIDC modes,and the two behaviors behind the bug: external mode writes nothing and does not clobber
a pre-existing
.npmrc. Ran the full suite and bash syntax checks locally.bats tests/passes (77 tests: 10 new + 67 existing)Test Configuration:
publish-npm: trueto GitHub Packages viaactions/setup-node+NODE_AUTH_TOKEN(nonpm-token); also token and OIDC modesChecklist
set -euo pipefail, quoted expansions)action.ymldescriptions where relevant