Auto-updating changelogs from commits is a powerful way to keep documentation synchronized with code changes, especially in collaborative or CI/CD-driven projects. Here’s how to implement this automation, using conventional commits and changelog generation tools:
1. Use Conventional Commits
Adopt the Conventional Commits specification to ensure consistent formatting of commit messages.
Example format:
This format enables tooling to parse commit messages and categorize them into changelogs.
2. Set Up Changelog Generator
Use a tool like standard-version, semantic-release, or auto-changelog.
Option A: standard-version
Install:
Add to package.json:
Usage:
This creates/updates a CHANGELOG.md, bumps the version, and tags a release based on commits.
Option B: semantic-release
Install:
Configure .releaserc.json:
CI/CD Integration:
Set up semantic-release to run automatically on merges to your main branch in GitHub Actions, GitLab CI, etc.
3. Automate with Git Hooks or CI Pipelines
For local workflow automation, use Husky:
Install:
Add hook:
For CI, configure the changelog generation step before deployment or packaging.
4. Customize the Output
Each changelog tool can be customized to include issue links, scopes, or custom sections:
5. Example Workflow with GitHub Actions
6. Best Practices
-
Enforce conventional commits using
commitlint. -
Always review changelogs before release.
-
Tag versions consistently to match changelog entries.
-
Consider adding manual notes for breaking changes.
By automating changelog generation from commits, you ensure consistent documentation, faster releases, and better collaboration between developers and stakeholders.