Add a release workflow with tags
Publish an npm package from a GitHub Actions workflow that runs when you push a version tag, with provenance and a scoped token permission.
A tag push is a clear signal for "release this". The workflow builds, tests and publishes from a clean runner.
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 test
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}npm version minor
git push --follow-tagsnpm version bumps package.json, commits and creates the v1.3.0 tag. Pushing the tag starts the workflow. id-token: write lets npm sign a provenance statement that links the package to this run. setup-node with registry-url writes an .npmrc that reads NODE_AUTH_TOKEN. See npm's provenance docs.
Check that the tag matches the version in package.json before publishing, or a wrong tag will publish the wrong number. Store the token as a repository secret, never in the file.