Skip to content

Commit 5a44f07

Browse files
committed
Automatically publish changelog to Github release
1 parent 6fa6d48 commit 5a44f07

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

.github/workflows/changelog.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish changelog
2+
permissions:
3+
contents: write
4+
5+
on:
6+
push:
7+
tags:
8+
- '[0-9]+.[0-9]+.[0-9]+'
9+
10+
jobs:
11+
generate-changelog:
12+
name: Generate changelog
13+
runs-on: ubuntu-22.04
14+
outputs:
15+
release_body: ${{ steps.git-cliff.outputs.content }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Generate a changelog
24+
uses: orhun/git-cliff-action@main
25+
id: git-cliff
26+
with:
27+
config: cliff.toml
28+
args: --strip all -v --latest --github-repo ${{ github.repository }}
29+
30+
- name: Create Github release
31+
uses: softprops/action-gh-release@v2
32+
if: startsWith(github.ref, 'refs/tags/')
33+
with:
34+
make_latest: true
35+
body_path: ${{ steps.git-cliff.outputs.changelog }}

cliff.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[changelog]
5+
6+
# template for the changelog body
7+
# https://keats.github.io/tera/docs/#introduction
8+
body = """
9+
{% if version -%}
10+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
11+
{% for group, commits in commits | group_by(attribute="group") %}
12+
### {{ group | upper_first }}
13+
{% for commit in commits %}
14+
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
15+
{% endfor %}
16+
{% endfor %}\n
17+
{% endif -%}
18+
"""
19+
20+
# template for the changelog footer
21+
footer = """
22+
{% for release in releases -%}
23+
{% if release.version -%}
24+
{% if release.previous.version -%}
25+
[{{ release.version | trim_start_matches(pat="v") }}]: \
26+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
27+
/compare/{{ release.previous.version }}..{{ release.version }}
28+
{% endif -%}
29+
{% else -%}
30+
[unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
31+
/compare/{{ release.previous.version }}..HEAD
32+
{% endif -%}
33+
{% endfor %}
34+
<!-- generated by git-cliff -->
35+
"""
36+
37+
# remove the leading and trailing whitespace from the templates
38+
trim = true
39+
40+
[git]
41+
# parse the commits based on https://www.conventionalcommits.org
42+
conventional_commits = true
43+
# filter out the commits that are not conventional
44+
filter_unconventional = false
45+
# regex for parsing and grouping commits
46+
commit_parsers = [
47+
{ message = "^[a|A]dd", group = "Added" },
48+
{ message = "^[s|S]upport", group = "Added" },
49+
{ message = "^[r|R]emove", group = "Removed" },
50+
{ message = "^.*: add", group = "Added" },
51+
{ message = "^.*: support", group = "Added" },
52+
{ message = "^.*: remove", group = "Removed" },
53+
{ message = "^.*: delete", group = "Removed" },
54+
{ message = "^test", group = "Fixed" },
55+
{ message = "^fix", group = "Fixed" },
56+
{ message = "^.*: fix", group = "Fixed" },
57+
{ message = "^.*", group = "Changed" },
58+
# { message = ".*changelog.*", changelog = true },
59+
]
60+
# filter out the commits that are not matched by commit parsers
61+
filter_commits = false
62+
# sort the tags topologically
63+
topo_order = false
64+
# sort the commits inside sections by oldest/newest order
65+
sort_commits = "newest"
66+

0 commit comments

Comments
 (0)