Changelog CI (Commit and/or Comment Auto-generated Changelog to PR using Actions)
Tags: actionshackathon, github, opensource, python
Published: 2020-09-03 06:40:33

### My Workflow
I have created my first Open Source GitHub Action called [Changelog CI](https://github.com/marketplace/actions/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](https://github.com/saadmk11/changelog-ci/blob/master/CHANGELOG.md)

### Submission Category: 

**Maintainer Must-Haves**

### Yaml File or Link to Code

Here are the links for ``Changelog CI``

**GitHub repository:**

{% github https://github.com/saadmk11/changelog-ci %}

**Marketplace:**

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

### Additional Resources / Info

[Changelog CI](https://github.com/marketplace/actions/changelog-ci) is a new open-source action, as of now, my open-source projects use it.

For example, [django-newsfeed](https://github.com/saadmk11/django-newsfeed) and [banking-system](https://github.com/saadmk11/banking-system) uses it.
This output was created using ``changelog-ci`` [CHANGELOG.md](https://github.com/saadmk11/banking-system/blob/master/CHANGELOG.md)

Changelog CI itself uses this Action to generate [Changelog](https://github.com/saadmk11/changelog-ci/blob/master/CHANGELOG.md).

## 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``](https://regex101.com/r/Ly7O1x/3/) (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](https://github.com/saadmk11/changelog-ci#config-file-usage-optional)

### Example Workflow Using Changelog CI

```yaml
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}}
```

**Changelog CI Badge:**
![Changelog CI Status](https://github.com/saadmk11/changelog-ci/workflows/Changelog%20CI/badge.svg)
Add this to your README to display the badge:
```markdown
![Changelog CI Status](https://github.com/<username>/<repo_name>/workflows/Changelog%20CI/badge.svg)
``` 


## Example Changelog Output using config file:

Learn more about config file for Changelog CI
from the [README.md](https://github.com/saadmk11/changelog-ci#config-file-usage-optional)

### Version: 0.0.2

#### Bug Fixes

* [#53](https://github.com/test/test/pull/57): Keep updating the readme
* [#54](https://github.com/test/test/pull/56): Again updating the Same Readme file :(

#### New Features

* [#68](https://github.com/test/test/pull/68): Update README.md

#### Documentation Updates

* [#66](https://github.com/test/test/pull/66): Docs update


### Version: 0.0.1

#### Bug Fixes

* [#53](https://github.com/test/test/pull/57): Keep updating the readme
* [#54](https://github.com/test/test/pull/56): Again updating the Same Readme file :(

#### Documentation Updates

* [#66](https://github.com/test/test/pull/66): Docs update


## Example Changelog Output without using config file:

### Version: 0.0.2

* [#53](https://github.com/test/test/pull/57): Keep updating the readme
* [#54](https://github.com/test/test/pull/56): Again updating the Same Readme file :(
* [#55](https://github.com/test/test/pull/55): README update


### Version: 0.0.1

* [#43](https://github.com/test/test/pull/43): It feels like testing never ends :(
* [#35](https://github.com/test/test/pull/35): Testing again and again
* [#44](https://github.com/test/test/pull/44): This is again another test, getting tired
* [#37](https://github.com/test/test/pull/37): This is again another test

### Changelog CI in Action (Comment & Commit)
![Changelog CI](https://media.giphy.com/media/J5SWNI4JNdzUy4ap5e/source.gif)

## Conclusion

I think this will be really helpful for Open Source Maintainers. If anyone is interested please try [Changelog CI](https://github.com/marketplace/actions/changelog-ci) out and leave feedback :)