Skip to content

Commit b38697e

Browse files
committed
Add support to create pre-releases with a generated changelog
Signed-off-by: Tobias Wolf <[email protected]> On-behalf-of: SAP <[email protected]>
1 parent e5e9c52 commit b38697e

File tree

13 files changed

+824
-313
lines changed

13 files changed

+824
-313
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: pre-release
2+
3+
on:
4+
push:
5+
tags: [ "[0-9]+.[0-9]+.[0-9]+*" ]
6+
7+
jobs:
8+
create-pre-release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
15+
with:
16+
version: 1.0.0-pre1
17+
- name: Use cargo cache
18+
id: cache-cargo
19+
uses: actions/cache@v4
20+
with:
21+
path: |
22+
~/.cargo
23+
key: gh-release-${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
24+
restore-keys: gh-release-${{ runner.os }}-cargo-
25+
- name: Install git-cliff
26+
if: steps.cache-cargo.outputs.cache-hit != 'true'
27+
run: |
28+
cargo install git-cliff
29+
- name: Get the Git tag name
30+
id: get-tag-name
31+
run: echo "tag-name=${GITHUB_REF/refs\/tags\//}" | tee -a "$GITHUB_OUTPUT"
32+
- id: release
33+
name: Create changelog and release
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
gl-gh-release create \
38+
--repo "python-gardenlinux-lib" \
39+
--tag "${{ steps.get-tag-name.outputs.tag-name }}" \
40+
--commit "${{ github.sha }}" \
41+
--name 'python-gardenlinux-lib v${{ steps.get-tag-name.outputs.tag-name }}' \
42+
--body "
43+
Changes for v${{ steps.get-tag-name.outputs.tag-name }}
44+
45+
$(git-cliff -o - --current)
46+
"

cliff.toml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
[remote.github]
4+
owner = "gardenlinux"
5+
repo = "python-gardenlinux-lib"
6+
7+
[changelog]
8+
# A Tera template to be rendered as the changelog's header.
9+
# See https://keats.github.io/tera/docs/#introduction
10+
header = """
11+
# Changelog\n
12+
All notable changes since last release will be documented below.\n
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+
{% for group, commits in commits | group_by(attribute="group") %}
18+
### {{ group | upper_first }}
19+
{% for commit in commits %}
20+
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
21+
{% endfor %}
22+
{% endfor %}\n
23+
"""
24+
# A Tera template to be rendered as the changelog's footer.
25+
# See https://keats.github.io/tera/docs/#introduction
26+
footer = """
27+
{% for release in releases -%}
28+
{% if release.version -%}
29+
{% if release.previous.version -%}
30+
[{{ release.version | trim_start_matches(pat="v") }}]: \
31+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
32+
/compare/{{ release.previous.version }}..{{ release.version }}
33+
{% else -%}
34+
[{{ release.version | trim_start_matches(pat="v") }}]: \
35+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
36+
/tree/{{ release.version }}
37+
{% endif -%}
38+
{% else -%}
39+
[unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
40+
/compare/{{ release.previous.version }}..HEAD
41+
{% endif -%}
42+
{% endfor %}
43+
<!-- generated by git-cliff -->
44+
"""
45+
# Remove leading and trailing whitespaces from the changelog's body.
46+
trim = true
47+
48+
[git]
49+
# Parse commits according to the conventional commits specification.
50+
# See https://www.conventionalcommits.org
51+
conventional_commits = true
52+
# Exclude commits that do not match the conventional commits specification.
53+
filter_unconventional = false
54+
# An array of regex based parsers for extracting data from the commit message.
55+
# Assigns commits to groups.
56+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
57+
commit_parsers = [
58+
{ message = "^[a|A]dd", group = "Added" },
59+
{ message = "^[s|S]upport", group = "Added" },
60+
{ message = "^[r|R]emove", group = "Removed" },
61+
{ message = "^.*: add", group = "Added" },
62+
{ message = "^.*: support", group = "Added" },
63+
{ message = "^.*: remove", group = "Removed" },
64+
{ message = "^.*: delete", group = "Removed" },
65+
{ message = "^test", group = "Fixed" },
66+
{ message = "^fix", group = "Fixed" },
67+
{ message = "^.*: fix", group = "Fixed" },
68+
{ message = "^.*", group = "Changed" },
69+
]
70+
# Prevent commits that are breaking from being excluded by commit parsers.
71+
filter_commits = false
72+
# Order releases topologically instead of chronologically.
73+
topo_order = true
74+
# Order of commits in each group/release within the changelog.
75+
# Allowed values: newest, oldest
76+
sort_commits = "oldest"

0 commit comments

Comments
 (0)