Skip to content

Commit cf9c85e

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 cf9c85e

File tree

13 files changed

+828
-313
lines changed

13 files changed

+828
-313
lines changed

.github/workflows/release.yml

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

cliff.toml

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

0 commit comments

Comments
 (0)