ci: set up npm trusted publishing - #213
Merged
Merged
Conversation
Publish to npm via GitHub Actions OIDC instead of a long-lived NPM_TOKEN secret. - Bump semantic-release 17 -> 25, which pulls in @semantic-release/npm v13. OIDC token exchange landed in @semantic-release/npm v13.1.0, and v13 bundles npm 11.x (trusted publishing needs npm >= 11.5.1). - Move the release out of the test matrix into its own job so that `id-token: write` is scoped to the publish step only, and grant the permissions semantic-release needs now that the workflow declares an explicit permissions block. - Drop the NPM_TOKEN env var. With trusted publishing configured, @semantic-release/npm exchanges the Actions OIDC token for a short-lived registry token and never reads NPM_TOKEN. - Add publishConfig.access=public so the scoped package keeps publishing publicly, and bump CI to Node 22 because semantic-release v25 requires ^22.14.0 || >=24.10.0 (yarn v1 hard-fails on engine mismatch). Provenance attestations are generated automatically for public packages published from a public repo via OIDC, so no --provenance flag is needed. Co-Authored-By: Steven <229881+styfle@users.noreply.github.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
🎉 This PR is included in version 1.10.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Publishes
@vercel/webpack-asset-relocator-loaderto npm via trusted publishing (GitHub Actions OIDC) instead of the long-livedNPM_TOKEN_ELEVATEDsecret.npm does not let you register a trusted publisher from CI — it has to be done in the npmjs.com UI, and until it exists the OIDC token exchange fails and
@semantic-release/npmfalls back to token auth (which this PR removes). So the next release after merge will fail unless this is done first.On the package settings page, under Trusted Publisher, add a GitHub Actions publisher:
vercelwebpack-asset-relocator-loaderci.ymlnpm publishThese fields are case-sensitive and npm doesn't validate them at save time — mistakes only surface as
ENEEDAUTHat publish time. Note the workflow filename is the file that runs the publish, which isci.ymlhere, not a path.Once a release has published successfully, the
NPM_TOKEN_ELEVATEDsecret can be deleted and Publishing access can be tightened to Require two-factor authentication and disallow tokens (that setting only affects token auth, so OIDC keeps working).Changes
package.jsonpublishConfig.access = "public"so the scoped package keeps publishing publicly.semantic-release^17.3.0→^25.0.9. OIDC token exchange landed in@semantic-release/npmv13.1.0, which is only pulled in by semantic-release v25. v13 also bundles npm 11.x, satisfying the npm >= 11.5.1 requirement regardless of the runner's npm.No change was needed to
repository— npm normalizes thevercel/webpack-asset-relocator-loadershorthand togit+https://github.com/vercel/webpack-asset-relocator-loader.git, which is what the registry already has on record for v1.10.0 and what the OIDC repository check compares against..github/workflows/ci.ymlreleasejob gated onneeds: testand push-to-main. This keepsid-token: writescoped to the publish step rather than granting it to every matrix leg on every PR.contents: readat the workflow level, and on the release jobcontents: write(GitHub release + tag),issues: write/pull-requests: write(release comments),id-token: write(OIDC).NPM_TOKEN.@semantic-release/npmnow callsgetIDToken("npm:registry.npmjs.org")and exchanges it for a short-lived registry token;verify-auth.jsreturns early on success and never readsNPM_TOKEN.fetch-depth: 0to the release checkout, per the semantic-release GitHub Actions recipe.engines.node: ^22.14.0 || >= 24.10.0, and yarn v1 hard-errors (Found incompatible module) on an engine mismatch rather than warning — so leaving the matrix on Node 18 breaksyarn installon every leg. npm trusted publishing itself also requires Node >= 22.14.0. Node 18 went EOL in April 2025. If you'd rather keep Node 18 test coverage, the alternative isyarn install --ignore-enginesin the test job — happy to switch.Provenance attestations are generated automatically for public packages published from a public repo over OIDC, so no
--provenanceflag orpublishConfig.provenanceis needed.Verification
yarn test— 85/85 passing on Node 22.semantic-release@25.0.9/@semantic-release/npm@13.1.5with npm11.19.0hoisted, and that the plugin'strusted-publishing/token-exchange.jsreads the Actions OIDC token thatid-token: writeprovides.NPM_TOKENreference.The end-to-end publish can't be exercised from a PR — OIDC only works on
pushtomain— so the first real validation is the next release.🤖 Generated with Claude Code