feat: add npm OIDC trusted publishing support #561
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.
This PR adds support for npm's OIDC-based trusted publishing, which lets you publish packages without managing long-lived NPM tokens.
What this addresses
Closes #542 and helps with #515 by enabling OIDC in the current workflow model. Related to #545 but takes a more comprehensive approach.
Changes
Added a new
oidcAuthinput parameter (defaults tofalsefor backward compatibility). When enabled, the action validates your OIDC environment before trying to publish:id-token: writepermission is setNPM_TOKENset (conflicting auth)The implementation explicitly passes OIDC environment variables to the publish command. This is necessary because some toolchains spawn fresh shell processes, and we need to ensure the OIDC tokens reach npm even through those layers.
Testing
I've been testing this in production at Adobe (spectrum-design-data repo) and added comprehensive test coverage:
All 30 tests pass locally.
How to use it
You'll also need to configure trusted publishing on npmjs.com for your packages (one-time setup).
Why this approach vs PR #545
PR #545 just prevents writing
undefinedto.npmrc, but doesn't validate the environment or provide any feedback when things are misconfigured. This implementation validates upfront and gives you clear error messages if something's wrong, which saves a lot of debugging time.Backward compatibility
Fully backward compatible - existing workflows using
NPM_TOKENcontinue to work unchanged. OIDC is opt-in via the new parameter.