Automatically generating changelogs can be accomplished through tools and practices that parse commit messages, track changes in your codebase, and format the output into human-readable changelog files. Here’s how you can set it up:
1. Follow a Conventional Commit Format
To generate changelogs automatically, your commits should follow a structured format like Conventional Commits, such as:
Common tags:
-
feat
: a new feature -
fix
: a bug fix -
docs
: documentation changes -
style
: code style changes (formatting, missing semi colons, etc.) -
refactor
: code refactoring -
test
: adding or updating tests -
chore
: maintenance tasks
2. Use Changelog Generation Tools
Here are some popular tools that automate changelog creation:
a. standard-version
(Node.js)
A powerful tool for versioning and changelog generation using Conventional Commits.
Usage:
Generates or updates a CHANGELOG.md
and bumps version in package.json
.
b. conventional-changelog
CLI
Install globally:
Generate changelog:
c. release-it
Customizable release automation tool.
Config in .release-it.json
or package.json
:
Run with:
d. GitHub Actions for Automation
You can automate changelog generation during CI/CD with GitHub Actions. Example workflow:
3. Best Practices
-
Commit discipline: Enforce Conventional Commits with a pre-commit hook (e.g., via Husky).
-
Semantic versioning: Combine with tools that bump versions based on commit type (
feat
= minor,fix
= patch). -
Review changelogs: Automatically generated logs should still be reviewed before publishing.
4. Additional Tools
-
Gitmoji +
gitmoji-changelog
: If using emoji-based commit messages. -
Keep a Changelog format: Some tools can format the output following keepachangelog.com.
-
Semantic Release: Fully automates the release process with changelogs, versioning, and publishing.
Summary
By adopting structured commit messages and using tools like standard-version
or conventional-changelog
, you can automate changelog generation efficiently. Integration with CI/CD pipelines ensures your changelogs remain consistent and up to date without manual effort.
Leave a Reply