Changelog Update Action
Synchronizes the repository's CHANGELOG.md
with content from the draft release, ensuring an "Unreleased" section reflects all recent changes and maintains consistent formatting.
Usage
steps:
- name: Update Changelog
uses: ./actions/changelog_update
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ steps.version.outputs.next_version }}
Inputs
Input | Description | Required | Default |
---|---|---|---|
github-token |
GitHub token for API access | Yes | N/A |
version |
Version number to use in the unreleased section | Yes | N/A |
Functionality
Draft Release Content
This action retrieves draft release details via the GitHub API:
- Identifies the draft release.
- Extracts PR entries.
- Strips footer content.
Changelog Format
Follows a consistent structure:
# Repository Changelog
## **MM/DD/YYYY - vX.Y.Z Unreleased**
- PR #123: Feature description
- PR #124: Another change
## **[(MM/DD/YYYY) - vX.Y.Z](link-to-release)**
- Previous release content
Processing Steps
- Fetches draft release content.
- Updates or creates the "Unreleased" section with:
- Current date
- Provided version number
- Draft release content.
- Preserves all previous releases.
- Maintains formatting consistency.
Implementation Details
Environment Setup
- Configures Git in container environments.
- Installs required tools (e.g., GitHub CLI).
- Prepares workspace access.
Git Operations
Handles:
- Git configuration.
- Committing changes.
- Pushing to a staging branch.
Error Handling
Provides clear feedback for:
- Missing GitHub token.
- API request failures.
- File operation issues.
- Git command failures.
Example Workflows
Basic Usage with Version Calculation
jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: staging
fetch-depth: 0
- name: Calculate Version
uses: ./actions/version_calculation
id: version
- name: Update Changelog
uses: ./actions/changelog_update
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ steps.version.outputs.next_version }}
Manual Version Specification
steps:
- name: Update Changelog
uses: ./actions/changelog_update
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: 'v1.0.0'
Requirements
-
Repository must include:
CHANGELOG.md
in the root directory.- Draft release for content sourcing.
- Proper GitHub token permissions.
-
Environment must have:
- Git.
- GitHub CLI.
- Python 3.9+.
Files
action.yml
Defines the action interface:
- Input parameters.
- Environment configuration.
- Docker container setup.
Dockerfile
Configures the container with:
- Python runtime.
- Git installation.
- GitHub CLI.
- Necessary environment setups.
update_changelog.py
Implements core logic:
- Fetches draft release content.
- Parses and updates the changelog.
- Manages Git operations.
- Handles errors.
Error Cases
The action accounts for several potential issues:
-
Missing Draft Release
- Outputs a clear error message.
- Returns a non-zero exit code.
-
GitHub API Issues
- Validates tokens.
- Handles request failures or permission errors.
-
File Operations
- Detects missing changelog.
- Handles write permissions or format inconsistencies.
-
Git Operations
- Resolves configuration or push errors.
- Handles permission issues.
Future Improvements
Possible enhancements:
- Support custom changelog formats.
- Handle multiple changelog files.
- Categorize release notes.
- Automate version bumping.
- Customize commit messages.
Integration Points
Designed to integrate with:
- Version calculation actions.
- Release preparation workflows.
- GitHub release drafts.
- Branch protection rules.
Contributing
To contribute:
- Update the Python script for logic changes.
- Test with various changelog states.
- Verify formatting consistency.
- Submit a PR for review.