GitHub Action
Tag Changelog
A GitHub Action triggered by a new tag getting pushed. It then fetches all the commits since the previous tag and creates a changelog text using the Conventional Commits format. It will also turn PR numbers into clickable links.
This action returns the generated changelog text, but doesn't do anything more; you need to for example prepend it to a CHANGELOG.md
file, create a GitHub Release with this text, etc.
name: Create Release
on:
push:
tags:
- '*'
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Create changelog text
id: changelog
uses: loopwerk/conventional-changelog-action@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
exclude: other,doc,chore
- name: Create release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{ steps.changelog.outputs.changes }}
token
: Your GitHub token,${{ secrets.GITHUB_TOKEN }}
. Required.exclude
: A comma separated list of commits types you want to exclude from the changelog, for example: "other,chore". Optional (defaults to nothing).config_file
: Location of the config file. Optional.
changelog
: Generated changelog for the latest tag, including the version/date header (suitable for prepending to a CHANGELOG.md file).changes
: Generated changelog for the latest tag, without the version/date header (suitable for GitHub Releases).
- name: Create changelog text
uses: loopwerk/conventional-changelog-action@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
config_file: .github/tag-changelog-config.js
The config file can be used to map commit types to changelog labels, to override the rendering of changelog sections, and the rendering of the overall changelog. You only need to override the things you want to override. For example, you can leave out renderTypeSection
and renderChangelog
and only include the types
config; the default config will be used for whatever is not overriden.
module.exports = {
types: [
{ types: ["feat", "feature"], label: "π New Features" },
{ types: ["fix", "bugfix"], label: "π Bugfixes" },
{ types: ["improvements", "enhancement"], label: "π¨ Improvements" },
{ types: ["perf"], label: "ποΈ Performance Improvements" },
{ types: ["build", "ci"], label: "ποΈ Build System" },
{ types: ["refactor"], label: "πͺ Refactors" },
{ types: ["doc", "docs"], label: "π Documentation Changes" },
{ types: ["test", "tests"], label: "π Tests" },
{ types: ["style"], label: "π
Code Style Changes" },
{ types: ["chore"], label: "π§Ή Chores" },
{ types: ["other"], label: "Other Changes" },
],
renderTypeSection: function (label, commits) {
let text = `\n## ${label}\n`;
commits.forEach((commit) => {
text += `- ${commit.subject}\n`;
});
return text;
},
renderChangelog: function (release, changes) {
const now = new Date();
return `# ${release} - ${now.toISOString().substr(0, 10)}\n` + changes + "\n\n";
},
};
The order in which the types
appear also determines the order of the generated sections in the changelog.
- Display breaking changes notes
- Display type scope
- Handle the very first tag - currently this Action only works when at least two tags are found
Thanks to Helmisek/conventional-changelog-generator and ardalanamini/auto-changelog for inspiration. Thanks to nektos/act for making it possible to run GitHub Actions locally, making development and testing a whole lot easier.