Publish from GitHub Actions with trusted publishing
Publish to npm from GitHub Actions without a stored token, using OIDC trusted publishing and a short-lived credential. Needs npm 11.5.1 or newer.
Long-lived npm tokens in CI secrets get leaked. Trusted publishing lets npm accept a login from a specific GitHub workflow, using a short-lived OIDC identity instead of a token.
First, on npmjs.com open the package settings and add a trusted publisher: your GitHub owner, repository and the workflow file name. Then grant the job an identity token:
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm publishnpm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
+ [email protected]Trusted publishing needs npm 11.5.1 or newer, so upgrade npm in the job if the runner ships an older one. Public packages published this way also get provenance automatically. See the npm trusted publishing docs.
The workflow file name must match exactly, including the extension. A mismatch fails with an authentication error.