Skip to content

Commit e1ad094

Browse files
committed
Add support to create pre-releases with a generated changelog
Signed-off-by: Tobias Wolf <wolf@b1-systems.de> On-behalf-of: SAP <tobias.wolf@sap.com>
1 parent e5e9c52 commit e1ad094

File tree

13 files changed

+837
-313
lines changed

13 files changed

+837
-313
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
- name: Checkout commit
15+
uses: actions/checkout@v6
16+
with:
17+
sparse-checkout: |
18+
cliff.toml
19+
sparse-checkout-cone-mode: false
20+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
21+
with:
22+
version: 1.0.0-pre1
23+
- name: Use cargo cache
24+
id: cache-cargo
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cargo
29+
key: gh-release-${{ runner.os }}-cargo-${{ hashFiles('~/.cargo/.crates.toml') }}
30+
restore-keys: gh-release-${{ runner.os }}-cargo-
31+
- name: Install git-cliff
32+
if: steps.cache-cargo.outputs.cache-hit != 'true'
33+
run: |
34+
cargo install git-cliff
35+
- name: Get the Git tag name
36+
id: get-tag-name
37+
run: echo "tag-name=${GITHUB_REF/refs\/tags\//}" | tee -a "$GITHUB_OUTPUT"
38+
- id: release
39+
name: Create changelog and release
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
gl-gh-release create \
44+
--repo "python-gardenlinux-lib" \
45+
--tag "${{ steps.get-tag-name.outputs.tag-name }}" \
46+
--commit "${{ github.sha }}" \
47+
--name 'python-gardenlinux-lib v${{ steps.get-tag-name.outputs.tag-name }}' \
48+
--latest true \
49+
--body "
50+
$(git-cliff -o - --current)
51+
"

cliff.toml

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

0 commit comments

Comments
 (0)