Automating Changelog Generation with Changesets
Introduction
Changesets automate version bumps and changelog generation based on pull request summaries, ensuring consistent semantic versioning.
Prerequisites
- Node.js >=14
- Monorepo or single package project
Step 1: Install Changesets
pnpm add -D @changesets/cli
pnpm changeset init
This creates a .changeset
folder and config files.
Step 2: Creating Changesets
After making changes, run:
pnpm changeset
- Select packages to update
- Categorize as
patch
,minor
, ormajor
- Provide summary of changes
This generates a markdown file in .changeset/
.
Step 3: Generating Changelog and Versions
Run:
pnpm changeset version
- Updates
package.json
versions - Updates
CHANGELOG.md
- Applies changeset summaries under version headings
Step 4: Committing Changes
Include generated files:
git add package.json **/package.json CHANGELOG.md .changeset
git commit -m "chore: version packages and update changelog"
Step 5: CI Integration
In CI pipeline (GitHub Actions example):
- uses: pnpm/action-setup@v2
with:
version: 8
- run: pnpm install
- run: pnpm test
- run: pnpm changeset version
- run: git diff --exit-code || (
git config user.name "github-actions"
git config user.email "actions@github.com"
git commit -am "chore: version packages"
git push
)
Step 6: Releasing
after pushing version commit, run:
pnpm changeset publish
- Publishes updated packages to npm
- Creates release on GitHub (if configured)
Summary
Changesets provide automated, consistent semantic versioning and changelog maintenance, reducing manual errors and improving release workflows.