Changelog Automation & Formatting
NeuroLink automatically formats the CHANGELOG.md file after generation during the release process to ensure consistent formatting and readability.
Overview
The project uses semantic-release to automatically generate changelogs based on commit messages. To ensure the generated CHANGELOG.md is properly formatted, we've implemented an automatic formatting step that runs immediately after changelog generation.
How It Works
Release Process Flow
- Commit Analysis:
@semantic-release/commit-analyzeranalyzes commits since the last release - Release Notes Generation:
@semantic-release/release-notes-generatorcreates release notes - Changelog Generation:
@semantic-release/changelogupdates CHANGELOG.md - 📄 Formatting Step: Custom plugin formats the CHANGELOG.md file using Prettier
- Git Commit:
@semantic-release/gitcommits the formatted changelog - NPM Publishing:
@semantic-release/npmpublishes to npm - GitHub Release:
@semantic-release/githubcreates GitHub release
Configuration
The formatting is configured in .releaserc.json:
{
"branches": ["release"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"./scripts/semantic-release-format-plugin.cjs",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": ["CHANGELOG.md", "package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
Scripts
Format Changelog Script
Location: scripts/format-changelog.ts
Standalone script that formats CHANGELOG.md using Prettier:
# Run manually
pnpm run format:changelog
# Or directly
tsx scripts/format-changelog.ts
Features:
- ✅ Checks if CHANGELOG.md exists before formatting
- ✅ Uses project's Prettier configuration
- ✅ Provides clear success/error feedback
- ✅ Exits with error code on failure
Semantic Release Plugin
Location: scripts/semantic-release-format-plugin.cjs
Custom semantic-release plugin that integrates formatting into the release workflow:
Features:
- ✅ Runs during the
preparestep after changelog generation - ✅ Uses semantic-release's logger for consistent output
- ✅ Automatically skips if CHANGELOG.md doesn't exist
- ✅ Integrates seamlessly with existing release pipeline
Benefits
Consistent Formatting
- All changelog entries follow the same formatting rules
- Markdown is properly structured and readable
- Code blocks, links, and lists are consistently formatted
Automated Process
- No manual formatting required after releases
- Reduces human error in changelog maintenance
- Ensures formatting doesn't get forgotten
Developer Experience
- Contributors don't need to worry about changelog formatting
- Semantic commit messages automatically generate well-formatted entries
- Release process remains fully automated
Manual Usage
Format Current Changelog
pnpm run format:changelog
Test the Plugin
node scripts/semantic-release-format-plugin.cjs
Format All Files (Including Changelog)
pnpm run format
Troubleshooting
"CHANGELOG.md not found" Warning
This is normal if:
- No changelog has been generated yet
- Running on a branch without changelog changes
- CHANGELOG.md was accidentally deleted
Solution: The script safely skips formatting and continues.
Formatting Errors
If Prettier fails to format CHANGELOG.md:
- Check Prettier Configuration: Ensure
.prettierrcorpackage.jsonprettier config is valid - Check File Permissions: Ensure CHANGELOG.md is writable
- Check File Content: Ensure CHANGELOG.md contains valid Markdown
Plugin Not Running
If the formatting plugin doesn't run during releases:
- Check Plugin Order: Ensure the format plugin comes after
@semantic-release/changelog - Check Plugin Path: Ensure
./scripts/semantic-release-format-plugin.cjsexists and is executable - Check Semantic Release Config: Ensure
.releaserc.jsonis valid JSON
Integration with Build Rules
The changelog formatting integrates with NeuroLink's comprehensive build rule enforcement:
- Pre-commit Hooks: Lint-staged ensures files are formatted before commits
- CI Validation: GitHub Actions verify formatting in pull requests
- Release Automation: Semantic-release handles the entire release pipeline
- Quality Gates: All formatting must pass before merge
Best Practices
Commit Messages
Use semantic commit messages to generate meaningful changelog entries:
# Good - generates clear changelog entry
feat(auth): add OAuth2 authentication system
# Good - generates clear changelog entry
fix(api): resolve timeout issues in user service
# Bad - creates unclear changelog entry
Update stuff
Release Workflow
- Development: Make commits with semantic commit messages
- Pull Request: CI validates formatting and build rules
- Merge: Squash merge to release branch
- Automatic Release: semantic-release generates and formats changelog
- Distribution: Formatted changelog is published to npm and GitHub
This automation ensures that NeuroLink's changelog remains consistently formatted and professional, supporting our commitment to high-quality documentation and developer experience.