Skip to content

Commit

Permalink
Merge pull request #13 from saadmk11/changelog-label-support
Browse files Browse the repository at this point in the history
Add Support to group changelog items by labels
  • Loading branch information
saadmk11 authored Sep 5, 2020
2 parents 706f97e + 2f9659b commit 28442f9
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 72 deletions.
181 changes: 131 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,167 @@

## What is Changelog CI?

Changelog CI is a GitHub Action that generates changelog,
prepends it to CHANGELOG.md file and commits it to a release pull request
Changelog CI is a GitHub Action that generates changelog,
prepends it to ``CHANGELOG.md`` file and commits it to a release pull request


## How Does It Work:

It uses a python script with GitHub API to get the last release.
Then it checks all the pull request merged after the last release and
writes it to ``CHANGELOG.md`` or user provided file.
The pull request title must start with ``release <space> <version_number><space> *anything else``
for example: ``Release 0.1.1 releasing a new version``
The Changelog CI will see the pull request and submit a commit to the pull request
with the changes written in the ``CHANGELOG.md`` file.
Changelog CI uses ``python`` and ``GitHub API`` to generate 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 an 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 to the release Pull request.


## Usage:

To integrate ``Changelog CI`` with your repository Actions,
Put this inside your ``.github/workflows/workflow.yml`` file:
To use this Action The pull **request title** must start with
``release <space> <version_number><space> <anything else>``
for example: ``Release 0.1.1 releasing a new version``
Changelog CI will see the pull request and only commit the changes to that pull request.

To integrate ``Changelog CI`` with your repositories Actions,
Put this step inside your ``.github/workflows/workflow.yml`` file:

```yaml
- name: Run Changelog CI
uses: saadmk11/[email protected]
# You can provide any name for your changelog file,
# defaults to ``CHANGELOG.md`` if not provided.
- name: Run Changelog CI
uses: saadmk11/[email protected]
with:
# You can provide any name for your changelog file,
# defaults to ``CHANGELOG.md`` if not provided.
changelog_filename: MY_CHANGELOG.md
# optional, only required when you want to
# group your changelog by labels and titles
config_file: changelog-ci-config.json
env:
# This will be used to configure git
# you can use secrets for it as well
USERNAME: 'test'
EMAIL: '[email protected]'
# optional, only required for ``private`` repositories
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
## Example Workflow
```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@master
with:
changelog_filename: MY_CHANGELOG.md
changelog_filename: CHANGELOG.md
config_file: changelog-ci-config.json
env:
# This will be used to configure git
# you can use secrets for it as well
USERNAME: 'test'
EMAIL: '[email protected]'
# optional only required for ``private`` repositories
USERNAME: ${{secrets.USERNAME}}
EMAIL: ${{secrets.EMAIL}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
## Example Workflow
## Group changelog by labels and titles
To group your changelog by labels and titles and have more control
over how your changelog looks you need to use Changelog CI's config file.
Its a ``json`` file you can add it to your workflow by adding this:
```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@master
env:
USERNAME: ${{secrets.USERNAME}}
EMAIL: ${{secrets.EMAIL}}
with:
config_file: changelog-ci-config.json
```
Example Config File:
```
{
// The prefix before the version number. "eg": ``Version: 0.0.2``
"header_prefix": "Version:",
"group_config": [
// You can add any number of sections to group by
{
// This will be the title of each section of the changelog
"title": "Bug Fixes",
// List of labels from your repository. You can add any number of labels
// Pull Requests with these labels will be under the title above
"labels": ["bug", "bugfix"]
},
{
"title": "Code Improvements",
"labels": ["improvements", "enhancement"]
},
{
"title": "New Features",
"labels": ["feature"]
},
{
"title": "Documentation Updates",
"labels": ["docs", "documentation", "doc"]
}
]
}
```

This will look at the pull request ``labels`` and put them under the provided title.
By using the config file the output will be:

## Example Changelog Output:
# Example Changelog Output using config file:

Version: 0.0.3

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 :(
* [#55](https://github.com/test/test/pull/55): README update

#### 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/53): Testing again and again
* [#54](https://github.com/test/test/pull/54): This is again another test
* [#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
Expand All @@ -90,10 +173,8 @@ Version: 0.0.1
* [#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
* [#47](https://github.com/test/test/pull/47): This is another test
* [#51](https://github.com/test/test/pull/51): This is a test


## License
# License

The code in this project is released under the [MIT License](LICENSE).
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
description: 'Name of the changelog file if not provided defaults to CHANGELOG.md'
required: false
default: 'CHANGELOG.md'
config_file:
description: 'Location of the config JSON file'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Loading

0 comments on commit 28442f9

Please sign in to comment.