Skip to content

Commit cb13014

Browse files
feat: use git-cliff for better changelogs
1 parent d6b3ac8 commit cb13014

File tree

5 files changed

+168
-49
lines changed

5 files changed

+168
-49
lines changed

.github/workflows/lint-commits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ jobs:
5858
- name: Check the commits
5959
shell: bash
6060
run: |
61-
cog check
61+
cog check --ignore-merge-commits

.github/workflows/release.yml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
~/.cargo/registry/index/
5454
~/.cargo/registry/cache/
5555
~/.cargo/git/db/
56-
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-cocogitto
56+
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-git-cliff
5757
restore-keys: |
5858
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-
5959
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-
@@ -93,33 +93,45 @@ jobs:
9393
--gunzip \
9494
--file=-
9595
96-
- name: Install cocogitto to get the next version number
96+
- name: Install git-cliff to generate changelog & next version number
9797
shell: bash
9898
run: |
99-
cargo binstall --github-token ${{ secrets.GITHUB_TOKEN }} --no-confirm cocogitto --pkg-url "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.tar.gz" --bin-dir "{ target }/{ bin }{ binary-ext }" --target x86_64-unknown-linux-musl --pkg-fmt tgz --bin cog --strategies crate-meta-data
99+
cargo binstall --github-token ${{ secrets.GITHUB_TOKEN }} --no-confirm git-cliff
100100
101-
- name: Bump
101+
- name: Get new version, generated updated changelog and update repo with updated changelog
102102
shell: bash
103103
id: release
104104
run: |
105-
git config --global user.name github-actions
106-
git config --global user.email github-actions@github.com
105+
repository=${{ github.repository }}
106+
# split at the last / and keep that (kristof-mattei/repo-name -> repo-name)
107+
repository=${repository##*/}
107108
108-
cog bump --auto
109+
git config --global user.name ${repository}-release[bot]
110+
git config --global user.email 864376+${repository}-release[bot]@users.noreply.github.com
109111
110-
version="v$(cog -v get-version)"
112+
version=$(git-cliff --bumped-version --unreleased --github-token ${{ secrets.GITHUB_TOKEN }})
111113
echo "version=$version" >> ${GITHUB_OUTPUT}
112114
113-
git push
115+
git tag $version --message "chore(version): Release ${version}"
114116
115-
- name: Generate Changelog
116-
shell: bash
117-
run: |
118-
cog changelog --at ${{ steps.release.outputs.version }} > GITHUB_CHANGELOG.md
117+
git push --follow-tags
118+
119+
git-cliff --output diff-CHANGELOG.md --current --github-token ${{ secrets.GITHUB_TOKEN }}
119120
120121
- name: Upload github release
121122
uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836 # v2.3.3
122123
with:
123-
body_path: GITHUB_CHANGELOG.md
124+
body_path: diff-CHANGELOG.md
124125
tag_name: ${{ steps.release.outputs.version }}
125126
token: ${{ secrets.TOKEN_TO_TRIGGER_SUBSEQUENT_WORKFLOWS }}
127+
128+
- name: Update changelog
129+
shell: bash
130+
run: |
131+
git-cliff --output CHANGELOG.md --github-token ${{ secrets.GITHUB_TOKEN }}
132+
133+
git add CHANGELOG.md
134+
135+
git commit --message "chore(version): Publish changelog for ${{ steps.release.outputs.version }}"
136+
137+
git push

.github/workflows/test-release.yml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ name: Test Release
44
on:
55
workflow_dispatch: # releasing is manual as we don't want to release every time
66

7+
concurrency:
8+
group: "${{ github.workflow }}"
9+
cancel-in-progress: true # only last step is important, which runs or doesn't
10+
711
permissions:
812
contents: write
913
issues: read
@@ -47,7 +51,7 @@ jobs:
4751
~/.cargo/registry/index/
4852
~/.cargo/registry/cache/
4953
~/.cargo/git/db/
50-
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-cocogitto
54+
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-git-cliff
5155
restore-keys: |
5256
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-
5357
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-
@@ -87,27 +91,20 @@ jobs:
8791
--gunzip \
8892
--file=-
8993
90-
- name: Install cocogitto to get the next version number
94+
- name: Install git-cliff to generate changelog & next version number
9195
shell: bash
9296
run: |
93-
cargo binstall --github-token ${{ secrets.GITHUB_TOKEN }} --no-confirm cocogitto --pkg-url "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.tar.gz" --bin-dir "{ target }/{ bin }{ binary-ext }" --target x86_64-unknown-linux-musl --pkg-fmt tgz --bin cog --strategies crate-meta-data
97+
cargo binstall --github-token ${{ secrets.GITHUB_TOKEN }} --no-confirm git-cliff
9498
95-
- name: Bump
99+
- name: Generate the changelog representing the next release
96100
shell: bash
97101
id: release
98102
run: |
99-
git config --global user.name github-actions
100-
git config --global user.email github-actions@github.com
101-
102-
cog bump --auto
103-
104-
version="v$(cog -v get-version)"
105-
echo "version=${version}" >> ${GITHUB_OUTPUT}
106-
107-
cog changelog --at ${version} > GITHUB_CHANGELOG.md
108-
109-
echo "New version: ${version}"
103+
repository=${{ github.repository }}
104+
# split at the last / and keep that (kristof-mattei/repo-name -> repo-name)
105+
repository=${repository##*/}
110106
111-
echo "Changelog: "
107+
git-cliff --output diff-CHANGELOG.md --bump --unreleased --latest --github-token ${{ secrets.GITHUB_TOKEN }}
112108
113-
cat GITHUB_CHANGELOG.md
109+
echo "# Next release changelog:" >> ${GITHUB_STEP_SUMMARY}
110+
cat diff-CHANGELOG.md >> ${GITHUB_STEP_SUMMARY}

cliff.toml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[remote.github]
5+
owner = "kristof-mattei"
6+
repo = "rust-seed"
7+
8+
[changelog]
9+
# A Tera template to be rendered as the changelog's header.
10+
# See https://keats.github.io/tera/docs/#introduction
11+
header = """
12+
<!-- header goes here -->
13+
"""
14+
# A Tera template to be rendered for each release in the changelog.
15+
# See https://keats.github.io/tera/docs/#introduction
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+
"""
53+
# A Tera template to be rendered as the changelog's footer.
54+
# See https://keats.github.io/tera/docs/#introduction
55+
footer = """
56+
<!-- generated by git-cliff -->
57+
"""
58+
# Remove leading and trailing whitespaces from the changelog's body.
59+
trim = true
60+
# Render body even when there are no releases to process.
61+
render_always = true
62+
# An array of regex based postprocessors to modify the changelog.
63+
postprocessors = [
64+
# Replace the placeholder `<REPO>` with a URL.
65+
{ pattern = '<REPO>', replace = "https://github.com/kristof-mattei/rust-seed" }, # replace repository URL
66+
]
67+
# render body even when there are no releases to process
68+
# render_always = true
69+
# output file path
70+
# output = "test.md"
71+
72+
[git]
73+
# Parse commits according to the conventional commits specification.
74+
# See https://www.conventionalcommits.org
75+
conventional_commits = true
76+
# Exclude commits that do not match the conventional commits specification.
77+
filter_unconventional = true
78+
# Require all commits to be conventional.
79+
# Takes precedence over filter_unconventional.
80+
require_conventional = false
81+
# Split commits on newlines, treating each line as an individual commit.
82+
split_commits = false
83+
# An array of regex based parsers to modify commit messages prior to further processing.
84+
commit_preprocessors = [
85+
# Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
86+
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
87+
# Check spelling of the commit message using https://github.com/crate-ci/typos.
88+
# If the spelling is incorrect, it will be fixed automatically.
89+
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
90+
]
91+
# Prevent commits that are breaking from being excluded by commit parsers.
92+
protect_breaking_commits = false
93+
# An array of regex based parsers for extracting data from the commit message.
94+
# Assigns commits to groups.
95+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
96+
commit_parsers = [
97+
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
98+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
99+
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
100+
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
101+
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
102+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
103+
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
104+
{ message = "^chore\\(release\\): prepare for", skip = true },
105+
{ message = "^chore\\(deps.*\\)", skip = true },
106+
{ message = "^chore\\(pr\\)", skip = true },
107+
{ message = "^chore\\(pull\\)", skip = true },
108+
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
109+
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
110+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
111+
{ message = ".*", group = "<!-- 10 -->💼 Other" },
112+
]
113+
# Exclude commits that are not matched by any commit parser.
114+
filter_commits = false
115+
# An array of link parsers for extracting external references, and turning them into URLs, using regex.
116+
link_parsers = []
117+
# Include only the tags that belong to the current branch.
118+
use_branch_tags = false
119+
# Order releases topologically instead of chronologically.
120+
topo_order = true
121+
# Order releases topologically instead of chronologically.
122+
topo_order_commits = true
123+
# Order of commits in each group/release within the changelog.
124+
# Allowed values: newest, oldest
125+
sort_commits = "oldest"
126+
# Process submodules commits
127+
recurse_submodules = false

cog.toml

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

0 commit comments

Comments
 (0)