How to Release a Monorepo With the Changesets Flow in CI
Changesets separates intent (a changeset file) from action (version and publish), so CI can accumulate intents and release in one atomic step.
Contributors run changeset add to drop a markdown intent file under .changeset/. In CI, changeset version consumes those files to bump package.json versions and write changelogs, and changeset publish pushes the bumped packages to the registry.
Steps
- Install
@changesets/cliand runchangeset initto create.changeset/config.json. - On each PR, run
changeset addto record which packages changed and at what semver level. - In CI on main, run
changeset versionto apply the pending changesets. - Run
changeset publishto publish every package whose version increased.
Manual flow
Terminal
# On a feature branch: describe the change
pnpm changeset
# In CI on main: apply pending changesets
pnpm changeset version # bumps package.json + writes CHANGELOG.md
git add -A && git commit -m "Version packages"
# Publish the newly bumped packages
pnpm changeset publish # runs npm publish for each changed packagePublish workflow
.github/workflows/release.yml
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- run: pnpm install --frozen-lockfile
- run: pnpm changeset publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}Gotchas
changeset publishpublishes only packages whose version inpackage.jsonis ahead of the registry, so it is safe to re-run.- Run
changeset versionand commit beforechangeset publish; publishing without bumping does nothing.
Related guides
How to Automate Monorepo Releases With the Changesets Release PRUse changesets/action to open and maintain a Version Packages PR that aggregates pending changesets; merging…
How to Configure Fixed vs Independent Versioning With ChangesetsSet up independent per-package versions or lock a group of packages to one version in Changesets using the fi…