Skip to content

Commit a7da7b4

Browse files
committed
chore: add a changelog and a release script
1 parent 7c2430e commit a7da7b4

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

cliff.toml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# git-cliff ~ default configuration file
2+
# https://git-cliff.org/docs/configuration
3+
#
4+
# Lines starting with "#" are comments.
5+
# Configuration options are organized into tables and keys.
6+
# See documentation for more information on available options.
7+
[remote.github]
8+
owner = "CodSpeedHQ"
9+
repo = "runner"
10+
11+
[changelog]
12+
# template for the changelog header
13+
header = """
14+
# Changelog\n
15+
16+
<sub>The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).</sub>
17+
\n
18+
19+
"""
20+
# template for the changelog body
21+
# https://keats.github.io/tera/docs/#introduction
22+
body = """
23+
{%- macro remote_url() -%}
24+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
25+
{%- endmacro -%}
26+
27+
{% if version -%}
28+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
29+
{% else -%}
30+
## [Unreleased]
31+
{% endif -%}
32+
33+
{% for group, commits in commits | group_by(attribute="group") %}
34+
### {{ group | upper_first }}
35+
{%- for commit in commits %}
36+
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
37+
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
38+
{% if commit.remote.pr_number %} in \
39+
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
40+
{%- endif -%}
41+
{% endfor %}
42+
{% endfor %}\n\n
43+
"""
44+
# template for the changelog footer
45+
footer = """
46+
{%- macro remote_url() -%}
47+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
48+
{%- endmacro -%}
49+
50+
{% for release in releases -%}
51+
{% if release.version -%}
52+
{% if release.previous.version -%}
53+
[{{ release.version | trim_start_matches(pat="v") }}]: \
54+
{{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }}
55+
{% endif -%}
56+
{% else -%}
57+
[unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD
58+
{% endif -%}
59+
{% endfor %}
60+
<!-- generated by git-cliff -->
61+
"""
62+
63+
# remove the leading and trailing s
64+
trim = true
65+
# postprocessors
66+
postprocessors = [
67+
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
68+
]
69+
# render body even when there are no releases to process
70+
# render_always = true
71+
# output file path
72+
# output = "test.md"
73+
74+
[git]
75+
# parse the commits based on https://www.conventionalcommits.org
76+
conventional_commits = true
77+
# filter out the commits that are not conventional
78+
filter_unconventional = true
79+
# process each line of a commit as an individual commit
80+
split_commits = false
81+
# regex for preprocessing the commit messages
82+
commit_preprocessors = [
83+
# Replace issue numbers
84+
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
85+
# Check spelling of the commit with https://github.com/crate-ci/typos
86+
# If the spelling is incorrect, it will be automatically fixed.
87+
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
88+
]
89+
# regex for parsing and grouping commits
90+
commit_parsers = [
91+
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
92+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
93+
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
94+
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
95+
{ message = "^refactor", group = "<!-- 2 -->🏗️ Refactor" },
96+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
97+
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
98+
{ message = "^chore\\(release\\): prepare for", skip = true },
99+
{ message = "^chore: Release.*", skip = true },
100+
{ message = "^chore: release v.*", skip = true },
101+
{ message = "^chore\\(deps.*\\)", skip = true },
102+
{ message = "^chore\\(pr\\)", skip = true },
103+
{ message = "^chore\\(pull\\)", skip = true },
104+
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Internals" },
105+
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
106+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
107+
{ message = ".*", group = "<!-- 10 -->💼 Other" },
108+
]
109+
# filter out the commits that are not matched by commit parsers
110+
filter_commits = false
111+
# sort the tags topologically
112+
topo_order = false
113+
# sort the commits inside sections by oldest/newest order
114+
sort_commits = "newest"

scripts/release.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check is on main
5+
if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
6+
echo "Not on main branch"
7+
exit 1
8+
fi
9+
10+
# First and only argument is the version number
11+
VERSION=v$1 # The version number, prefixed with 'v'
12+
# Prompt the release version
13+
echo "Release version: $VERSION"
14+
read -p "Are you sure you want to release this version? (y/n): " confirm
15+
if [ "$confirm" != "y" ]; then
16+
echo "Aborting release"
17+
exit 1
18+
fi
19+
20+
# Check that GITHUB_TOKEN is set
21+
if [ -z "$GITHUB_TOKEN" ]; then
22+
echo "GITHUB_TOKEN is not set. Trying to fetch it from gh"
23+
GITHUB_TOKEN=$(gh auth token)
24+
25+
fi
26+
27+
git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN
28+
git add CHANGELOG.md
29+
git commit -m "chore: Release $VERSION"
30+
git tag $VERSION -m "Release $VERSION"
31+
git push origin $VERSION
32+
gh release create $VERSION -t $VERSION --generate-notes -d

0 commit comments

Comments
 (0)