Skip to content

Commit b727b08

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 b727b08

File tree

13 files changed

+830
-313
lines changed

13 files changed

+830
-313
lines changed

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.lock') }}
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+
--body "
49+
Changes for v${{ steps.get-tag-name.outputs.tag-name }}
50+
51+
$(git-cliff -o - --current)
52+
"

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)