DEV Community

Cover image for Changelog CI (Commit and/or Comment Auto-generated Changelog to PR using Actions)
Maksudul Haque
Maksudul Haque

Posted on • Edited on

Changelog CI (Commit and/or Comment Auto-generated Changelog to PR using Actions)

My Workflow

I have created my first Open Source GitHub Action called Changelog CI.
This is a GitHub Action that generates changelog, prepends it to CHANGELOG.md file, and commits and/or comments it to the release pull request.

Live Example: Changelog CI's Changelog

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

Here are the links for Changelog CI

GitHub repository:

GitHub logo saadmk11 / changelog-ci

Changelog CI is a GitHub Action that enables a project to automatically generate changelogs

Changelog CI Banner

GitHub release (latest by date) GitHub Workflow Status GitHub GitHub Marketplace GitHub stars

What is Changelog CI?

Changelog CI is a GitHub Action that enables a project to automatically generate changelogs.

Changelog CI can be triggered on pull_request, workflow_dispatch and any other events that can provide the required inputs Learn more about events that trigger workflows

The workflow can be configured to perform any (or all) of the following actions:

  • For pull_request event:

    • Generates changelog using Pull Request Titles or Commit Messages made after the last release.
    • Prepends the generated changelog to the CHANGELOG.md/CHANGELOG.rst file.
    • Then Commits the modified CHANGELOG.md/CHANGELOG.rst file to the release pull request branch.
    • Adds a Comment on the release pull request with the generated changelog.
  • For other events:

    • Generate changelog using Pull Request Title or Commit Messages made after the last release.
    • Prepends the generated changelog to the CHANGELOG.md/CHANGELOG.rst file.
    • Then Creates a Pull Request with the CHANGELOG.md/CHANGELOG.rst file changes.

Marketplace:

https://github.com/marketplace/actions/changelog-ci

Additional Resources / Info

Changelog CI is a new open-source action, as of now, my open-source projects use it.

For example, django-newsfeed and banking-system uses it.
This output was created using changelog-ci CHANGELOG.md

Changelog CI itself uses this Action to generate Changelog.

How Does It Work:

Changelog CI uses python and GitHub API to generate a changelog for a repository.
First, it tries to get the latest release from the repository (If available).
Then, it checks all the pull requests merged after the last release using the GitHub API. After that, it parses the data and generates the changelog. Finally, It writes the generated changelog at the beginning of the CHANGELOG.md (or user-provided filename) file. In addition to that, if a user provides a config (JSON file), Changelog CI parses the user-provided config file and renders the changelog according to users config. Then the changes are committed and/or commented on the release Pull request.

Usage:

To use this Action The pull request title must match with the default regex or the user-provided regex from the config file.

Default title regex: ^(?i)release (title must start with the word "release" (case insensitive))

Default version number regex: This follows SemVer (Semantic Versioning) pattern. e.g. 1.0.0, 1.0, v1.0.1 etc.

For more details on Semantic Versioning pattern go to this link: https://regex101.com/r/Ly7O1x/3/

Note: you can provide your own regex through the config file

Example Workflow Using Changelog CI

name: Changelog CI

# Controls when the action will run. Triggers the workflow on pull request
on:
  pull_request:
    types: [opened, reopened]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # Checks-out your repository
      - uses: actions/checkout@v2

      - name: Run Changelog CI
        uses: saadmk11/changelog-ci@v0.5.0
        with:
          # Optional, you can provide any name for your changelog file.
          # defaults to ``CHANGELOG.md`` if not provided.
          changelog_filename: CHANGELOG.md
          # Optional, only required when you want more customization
          config_file: changelog-ci-config.json
        env:
          # Optional, Only required for ``private`` repositories
          # and required if the changelog comment 
          # option is turned on through the config file
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Enter fullscreen mode Exit fullscreen mode

Changelog CI Badge:
Changelog CI Status
Add this to your README to display the badge:

![Changelog CI Status](https://github.com/<username>/<repo_name>/workflows/Changelog%20CI/badge.svg)
Enter fullscreen mode Exit fullscreen mode

Example Changelog Output using config file:

Learn more about config file for Changelog CI
from the README.md

Version: 0.0.2

Bug Fixes

  • #53: Keep updating the readme
  • #54: Again updating the Same Readme file :(

New Features

  • #68: Update README.md

Documentation Updates

  • #66: Docs update

Version: 0.0.1

Bug Fixes

  • #53: Keep updating the readme
  • #54: Again updating the Same Readme file :(

Documentation Updates

  • #66: Docs update

Example Changelog Output without using config file:

Version: 0.0.2

  • #53: Keep updating the readme
  • #54: Again updating the Same Readme file :(
  • #55: README update

Version: 0.0.1

  • #43: It feels like testing never ends :(
  • #35: Testing again and again
  • #44: This is again another test, getting tired
  • #37: This is again another test

Changelog CI in Action (Comment & Commit)

Changelog CI

Conclusion

I think this will be really helpful for Open Source Maintainers. If anyone is interested please try Changelog CI out and leave feedback :)

Top comments (4)

Collapse
 
saadmk11 profile image
Maksudul Haque

Just Added an option to GROUP Changelog items using GitHub repository labels and changelog config file. This will give users more control over how the changelog looks. Updated the post. Try it out.

It looks like this:

Version: 0.0.2

Bug Fixes

  • #53: Keep updating the readme
  • #54: Again updating the Same Readme file :(

New Features

  • #68: Update README.md
  • #68: Update README.md

Documentation Updates

  • #66: Docs update
Collapse
 
brookmg profile image
Brook Mezgebu

Awesome! Been thinking to do something like this for sometime but specific to android

Collapse
 
saadmk11 profile image
Maksudul Haque

Oh! Awesome 👍

Collapse
 
blindadoxdx profile image
BlindadoxDx • Edited

I hope someone can help. I followed all the steps but when I do the PR for different versions it shows me commits that are from other versions, what could be the error?