Update Changelog Workflow
This workflow automatically updates the repository's CHANGELOG.md file when pull requests are merged into the develop branch.
Workflow File
.github/workflows/update-changelog.yml
Trigger
The workflow is triggered when a pull request targeting the develop
branch is closed:
on:
pull_request:
branches:
- develop
types: [closed]
The workflow will only run if the pull request was actually merged, not just closed:
jobs:
update-changelog:
if: github.event.pull_request.merged == true
Changelog Format
The workflow expects and maintains a changelog in the following format:
## **MM/DD/YYYY - Unreleased**
- PR #123: Description of change
- PR #124: Another change
## **MM/DD/YYYY - v1.0.0**
- Previous release changes...
Process
The workflow performs the following steps:
- Checks out the repository's develop branch
- Processes the CHANGELOG.md file:
- If an "Unreleased" section exists, adds the new PR entry to it
- If no "Unreleased" section exists, creates one with today's date
- Commits and pushes the updated changelog
Entry Format
Each changelog entry follows the format:
- PR #{number}: {pull request title}
Usage
The workflow runs automatically when PRs are merged. No manual intervention is required.
Prerequisites
- Repository must have a
CHANGELOG.md
file in the root directory - The file should follow the expected format
- PRs should be merged into the
develop
branch
Pull Request Requirements
- PRs must target the
develop
branch - PR title should be descriptive as it will be used in the changelog
- PR must be merged (not just closed)
Examples
PR Title Examples
Good PR titles that make meaningful changelog entries:
Add user authentication system
Fix memory leak in data processing
Update dependencies to latest versions
Poor PR titles to avoid:
Fix bug
Update code
WIP: Changes
Changelog Entry Examples
The workflow will create entries like:
## **01/02/2025 - Unreleased**
- PR #123: Add user authentication system
- PR #124: Fix memory leak in data processing
- PR #125: Update dependencies to latest versions
Permissions
The workflow requires:
- Read access to pull request metadata
- Write access to the repository (for pushing changes)
It uses the GITHUB_TOKEN
secret which is automatically provided by GitHub Actions.
Error Handling
The workflow includes several safeguards:
- Only runs on merged PRs
- Creates "Unreleased" section if missing
- Checks for changes before committing
- Uses [skip ci] in commit message to prevent CI loops
Troubleshooting
Common issues and solutions:
-
Changelog Not Updated
- Verify PR was actually merged
- Check if PR targeted develop branch
- Verify CHANGELOG.md exists in root directory
-
Push Failed
- Check if workflow has write permissions
- Verify branch protections allow GitHub Actions to push
-
Format Issues
- Ensure CHANGELOG.md follows expected format
- Check for manual modifications that might break format
Contributing
To modify this workflow:
- Fork the repository
- Edit
.github/workflows/update-changelog.yml
- Test changes by merging PRs to your fork
- Submit a pull request