Skip to content

Commit a6975e8

Browse files
feat(changelog): Created changelog automation
Now the changelog will be automatically kept up to date using git cliff.
1 parent ca266a9 commit a6975e8

6 files changed

Lines changed: 236 additions & 144 deletions

File tree

.config/changelog.toml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# configuration file for git-cliff
2+
3+
[changelog]
4+
trim = true # might have to be false to ensure ending on a new line.
5+
6+
header = """
7+
# Changelog
8+
9+
All notable changes to this project will be documented in this file.
10+
11+
The format is based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#specification),
12+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
13+
14+
"""
15+
16+
body = """
17+
{%- macro remote_url() -%}
18+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
19+
{%- endmacro -%}
20+
21+
{% macro print_commit(commit) -%}
22+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
23+
{% if commit.breaking %}[**breaking**] {% endif %}\
24+
{{ commit.message | upper_first }} - \
25+
([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}))\
26+
{% endmacro -%}
27+
28+
{% if version %}\
29+
{% if previous.version %}\
30+
## [{{ version | trim_start_matches(pat="v") }}]\
31+
({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }}
32+
{% else %}\
33+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
34+
{% endif %}\
35+
{% else %}\
36+
## [unreleased]
37+
{% endif %}\
38+
39+
{% for group, commits in commits | group_by(attribute="group") %}
40+
### {{ group | striptags | trim | upper_first }}
41+
{% for commit in commits
42+
| filter(attribute="scope")
43+
| sort(attribute="scope") %}
44+
{{ self::print_commit(commit=commit) }}
45+
{%- endfor %}
46+
{% for commit in commits %}
47+
{%- if not commit.scope -%}
48+
{{ self::print_commit(commit=commit) }}
49+
{% endif -%}
50+
{% endfor -%}
51+
{% endfor -%}
52+
{%- if github -%}
53+
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
54+
## New Contributors
55+
{% endif %}\
56+
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
57+
* @{{ contributor.username }} made their first contribution
58+
{%- if contributor.pr_number %} in \
59+
[#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
60+
{%- endif %}
61+
{%- endfor -%}
62+
{%- endif %}
63+
"""
64+
65+
footer = """
66+
67+
That is all, [go back to the top](#changelog).
68+
"""
69+
70+
#// # An array of regex based postprocessors to modify the changelog.
71+
#// postprocessors = [
72+
#// # Replace the placeholder `<REPO>` with a URL.
73+
#// { pattern = '<REPO>', replace = "https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}" }, # replace repository URL
74+
#// ]
75+
76+
[bump]
77+
features_always_bump_minor = true
78+
breaking_always_bump_major = true
79+
custom_major_increment_regex = "major"
80+
custom_minor_increment_regex = "minor"
81+
initial_tag = "0.0.0"
82+
83+
[git]
84+
85+
# Parse commits according to the conventional commits specification.
86+
# See https://www.conventionalcommits.org
87+
conventional_commits = true
88+
89+
# Exclude commits that do not match the conventional commits specification.
90+
filter_unconventional = true
91+
92+
# If any unconventional commits are found, an error will be logged and changelog generation fails.
93+
require_conventional = true
94+
95+
# Split commits on newlines, treating each line as an individual commit.
96+
split_commits = false
97+
98+
#// # An array of regex based parsers to modify commit messages prior to further processing.
99+
#// commit_preprocessors = [
100+
#// # Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
101+
#// { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))" },
102+
#// ]
103+
104+
# Prevent commits that are breaking from being excluded by commit parsers.
105+
protect_breaking_commits = true
106+
107+
# Exclude commits that are not matched by any commit parser.
108+
filter_commits = false
109+
110+
# Regex to select git tags that represent releases.
111+
tag_pattern = "v[0-9].*"
112+
113+
# Regex to select git tags that do not represent proper releases.
114+
# Takes precedence over `tag_pattern`.
115+
# Changes belonging to these releases will be included in the next release.
116+
skip_tags = "beta|alpha"
117+
118+
# Regex to exclude git tags after applying the tag_pattern.
119+
# ignore_tags = ""
120+
121+
# Order releases topologically instead of chronologically.
122+
topo_order = false
123+
124+
# Order of commits in each group/release within the changelog.
125+
# Allowed values: newest, oldest
126+
sort_commits = "newest"
127+
128+
# An array of regex based parsers for extracting data from the commit message.
129+
# Assigns commits to groups.
130+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
131+
commit_parsers = [
132+
# feat: a new feature
133+
{ group = "<!-- 00 --> New Features", message = "^feat.*:"},
134+
# fix: fixed bugs
135+
{ group = "<!-- 01 --> Bug Fixes", message = "^fix.*:" },
136+
# perf: performance improvements
137+
{ group = "<!-- 02 --> Performance Improvements", message = "perf.*:" },
138+
# test: adding or updating tests
139+
{ group = "<!-- 03 --> Code Quality", message = "test.*:" },
140+
# revert: reverts a previous commit
141+
{ group = "<!-- 04 --> Reverts", message = "^reverts.*:", skip = true },
142+
# docs: added or improved Documentation
143+
{ group = "<!-- 05 --> Documentation", message = "^docs.*:" },
144+
# chore: maintenance tasks (build tools, CI, etc.)
145+
{ group = "<!-- 06 --> General Maintenance", message = "chore.*:" },
146+
# refactor: code change that neither fixes a bug nor adds a feature
147+
{ group = "<!-- 07 --> Refactors", message = "refactor.*:", skip = true },
148+
# deps: sometimes used for dependency changes
149+
{ group = "<!-- 08 --> Dependency Changes", message = "^deps.*:" },
150+
{ group = "<!-- 08 --> Dependency Changes", message = "^chore\\(deps\\):" },
151+
# ci: CI configuration or script changes
152+
{ group = "<!-- 09 --> Automation", message = "^ci.*:" },
153+
# style: formatting (whitespace, semicolons, etc.) — no code change
154+
{ group = "<!-- 10 --> Stylistic Changes", message = "style.*:", skip = true },
155+
# build: changes affecting the build system or dependencies
156+
{ group = "<!-- 11 --> Build", message = "build.*:", skip = true },
157+
# merge: merge commits (should be prevented)
158+
{ group = "<!-- 12 --> Merges", message = "^[M|m]erge", skip = true },
159+
# Unmentioned
160+
{ group = "<!-- 13 --> Other", message = ".*", default_scope = "other"},
161+
]

.github/release-drafter.yml

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/draft-release.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/publish-release.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
publish:
12+
13+
publish-release:
14+
name: Publish Release
1315
runs-on: ubuntu-latest
1416
steps:
1517

1618
- name: Checkout code
1719
uses: actions/checkout@v4.2.2
20+
with:
21+
fetch-depth: 0
1822

1923
- name: Install Nix
2024
uses: cachix/install-nix-action@v30
@@ -44,24 +48,34 @@ jobs:
4448
rm -rf result
4549
done
4650
47-
- name: Create release
48-
uses: release-drafter/release-drafter@v6.1.0
51+
- name: Generate a changelog
52+
uses: orhun/git-cliff-action@v3
53+
id: git-cliff
4954
with:
50-
publish: true
51-
tag: ${{ github.ref_name }}
55+
config: .config/changelog.toml
56+
args: --verbose
5257
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
OUTPUT: CHANGELOG.md
59+
GITHUB_REPO: ${{ github.repository }}
60+
61+
- name: Print the changelog
62+
run: cat "${{ steps.git-cliff.outputs.changelog }}"
5463

55-
- name: Upload Release Asset
56-
id: upload-release-asset
64+
- name: Create GitHub Release
5765
uses: softprops/action-gh-release@v2.2.2
5866
with:
5967
token: ${{ secrets.GITHUB_TOKEN }}
68+
files: 'artifacts/**/*.{tar.gz,pdf}'
6069
fail_on_unmatched_files: true
61-
# globs to files you want to upload:
62-
# artifacts/**/*.pdf
63-
# artifacts/**/*.stl
64-
files: 'artifacts/**/*.tar.gz' # always created for each package in the flake
65-
# Do not change the body
66-
append_body: true
67-
body: ''
70+
body: ${{ steps.git-cliff.outputs.content }}
71+
72+
- name: Commit changelog
73+
run: |
74+
branch="main"
75+
git checkout $branch
76+
git config user.name 'github-actions[bot]'
77+
git config user.email 'github-actions[bot]@users.noreply.github.com'
78+
set +e
79+
git add CHANGELOG.md
80+
git commit --message "docs(changelog): Update changelog"
81+
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git $branch

0 commit comments

Comments
 (0)