Workflow Template
See assets/release-npm.yml — can be copied directly to .github/workflows/ for use.
How It Works
trusted publishing uses GitHub OIDC to replace long-lived NPM_TOKEN:
- the workflow runs on a GitHub-hosted runner
- the job has
permissions.id-token: write - npm /
actions/setup-nodeuse the GitHub OIDC identity to exchange for publishing credentials npm publishpublish using those credentials
no need for NPM_TOKEN secret。
Verified Requirements
- the workflow must be in
.github/workflows/ - a GitHub-hosted runner must be used
- there must be
id-token: write - the npm trusted publisher must exactly match the repository and workflow filename, for example
release-auth-sdk.yml package.json.repository.urlmust match the GitHub repository URL- recommended
actions/setup-node@v6 - Node 24 is recommended; if you keep Node 22, confirm that npm has been upgraded to
11.5.1+
Important Gotchas
- When using
actions/setup-node@v6, do not manually setNODE_AUTH_TOKEN: ""again. Based on testing, this combination causesENEEDAUTH; prefer to letsetup-nodehandle the publishing credentials itself. npm notice Publishing to https://registry.npmjs.org/after that, an error is reportedE404, which usually means authentication has already passed, but the package permissions, scope permissions, or trusted publisher metadata on the npm side still do not match.E422 ... Unsupported GitHub Actions source repository visibility: "private"indicates that private GitHub repositories do not support--provenance. In this case, remove--provenanceand keep ordinary trusted publishing.- provenance currently only applies to public source repositories.
Publish Command
- public GitHub repo:
npm publish --provenance --access public - private GitHub repo:
npm publish --access public
Quick Checklist
actions/setup-node@v6node-version: "24"registry-url: https://registry.npmjs.org/- do not configure
NPM_TOKEN - do not manually override
NODE_AUTH_TOKEN - the workflow filename in the npm backend trusted publisher must exactly match the actual filename