Skip to content
Latchkey

How to Version and Publish a Monorepo With Changesets in GitHub Actions

changesets/action opens a Version Packages PR from pending changesets and publishes to npm when that PR merges.

Run changesets/action on push to main. It bumps versions and opens a release PR; merging that PR triggers the same action to run publish against npm.

Steps

  • Add permissions: contents: write and pull-requests: write.
  • Run changesets/action with a publish: command.
  • Provide GITHUB_TOKEN and NPM_TOKEN.

Workflow

.github/workflows/release.yml
on:
  push:
    branches: [main]
permissions:
  contents: write
  pull-requests: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - uses: changesets/action@v1
        with:
          publish: npm run release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Gotchas

  • Set npm provenance or auth via .npmrc; the action does not log in for you.
  • The release PR only appears once at least one changeset file exists on main.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →