Skip to content
jshacks.dev
Packages

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.

1 min read
Summarize in AI

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:

.github/workflows/release.ymlYAML
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 publish
Text
npm 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.

Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.