Skip to content

Commit 0498d43

Browse files
committed
chore: add release script and git-cliff config
1 parent 9f16403 commit 0498d43

3 files changed

Lines changed: 214 additions & 6 deletions

File tree

CONTRIBUTING.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# Contributing
22

3-
## Bumping the JMH fork version
3+
## Release
44

5-
The JMH fork is published under group ID `io.codspeed.jmh`. To bump the version across all modules:
5+
To create a release, run `scripts/release.sh <new_version>` from the main
6+
branch. This script will:
67

7-
```bash
8-
cd jmh-fork && mvn versions:set -DnewVersion=x.y.z
9-
```
8+
1. Automatically update the version in all relevant files
9+
2. Create a commit with the version changes
10+
3. Generate the `CHANGELOG.md` (skipped for prereleases)
11+
4. Tag, push, and create a **draft** release on GitHub
1012

11-
This updates all `pom.xml` files in the multi-module project. After bumping, also update the version reference in `build.gradle.kts`.
13+
The release is created as a draft — review the auto-generated notes at
14+
[github.com/CodSpeedHQ/codspeed-jvm/releases](https://github.com/CodSpeedHQ/codspeed-jvm/releases)
15+
and click "Publish" to ship.
16+
17+
### Pre-releases
18+
19+
For alpha versions (e.g. `0.2.0-alpha`), the script:
20+
21+
- Allows running from a non-main branch
22+
- Skips `CHANGELOG.md` regeneration
23+
- Marks the GitHub Release as `--latest=false` so it doesn't appear as the latest release

cliff.toml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[remote.github]
5+
owner = "CodSpeedHQ"
6+
repo = "codspeed-jvm"
7+
8+
[changelog]
9+
header = """
10+
# Changelog\n
11+
12+
<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>
13+
\n
14+
15+
"""
16+
body = """
17+
{%- macro remote_url() -%}
18+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
19+
{%- endmacro -%}
20+
21+
{% if version -%}
22+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
23+
{% else -%}
24+
## [Unreleased]
25+
{% endif -%}
26+
27+
{% for group, commits in commits | group_by(attribute="group") %}
28+
### {{ group | upper_first }}
29+
{%- for commit in commits %}
30+
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
31+
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
32+
{% if commit.remote.pr_number %} in \
33+
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
34+
{%- endif -%}
35+
{% endfor %}
36+
{% endfor %}\n\n
37+
"""
38+
footer = """
39+
{%- macro remote_url() -%}
40+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
41+
{%- endmacro -%}
42+
43+
{% for release in releases -%}
44+
{% if release.version -%}
45+
{% if release.previous and release.previous.version -%}
46+
[{{ release.version | trim_start_matches(pat="v") }}]: \
47+
{{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }}
48+
{% endif -%}
49+
{% else -%}
50+
{% if release.previous and release.previous.version -%}
51+
[unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD
52+
{% endif -%}
53+
{% endif -%}
54+
{% endfor %}
55+
<!-- generated by git-cliff -->
56+
"""
57+
58+
trim = true
59+
postprocessors = []
60+
61+
[git]
62+
conventional_commits = true
63+
filter_unconventional = true
64+
split_commits = false
65+
commit_preprocessors = []
66+
commit_parsers = [
67+
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
68+
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
69+
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
70+
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
71+
{ message = "^refactor", group = "<!-- 2 -->🏗️ Refactor" },
72+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
73+
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
74+
{ message = "^chore\\(release\\): prepare for", skip = true },
75+
{ message = "^chore: release", skip = true },
76+
{ message = "^chore\\(deps.*\\)", skip = true },
77+
{ message = "^chore\\(pr\\)", skip = true },
78+
{ message = "^chore\\(pull\\)", skip = true },
79+
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Internals" },
80+
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
81+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
82+
{ message = ".*", group = "<!-- 10 -->💼 Other" },
83+
]
84+
filter_commits = false
85+
topo_order = false
86+
sort_commits = "newest"
87+
ignore_tags = "alpha|beta|rc"

scripts/release.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Usage: ./scripts/release.sh <version>
5+
#
6+
# <version> is a Maven-style version without the leading 'v', e.g. 0.2.0
7+
# or 0.2.0-beta.1. The git tag will be prefixed with 'v' (vX.Y.Z).
8+
#
9+
# This script bumps the jmh-fork version everywhere it's pinned,
10+
# regenerates CHANGELOG.md from conventional commits (skipped for
11+
# alpha/beta/rc), commits, tags, and prints the push command.
12+
# It does NOT push.
13+
#
14+
# Based on this: https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/scripts/release.sh
15+
16+
# First and only argument is the version number
17+
VERSION_NO_V=${1} # The version number without the 'v' prefix
18+
VERSION=v$1 # The version number, prefixed with 'v'
19+
20+
# Validate version format (X.Y.Z or X.Y.Z-alpha where X, Y, Z are integers)
21+
if [[ ! "$VERSION_NO_V" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-alpha)?$ ]]; then
22+
echo "Error: Invalid version format '$VERSION_NO_V'"
23+
echo "Usage: $0 <version>"
24+
echo " Version must be in format X.Y.Z or X.Y.Z-alpha (e.g., 1.2.3 or 1.2.3-alpha)"
25+
exit 1
26+
fi
27+
28+
# Check is on main (unless releasing an alpha version)
29+
if [[ ! "$VERSION_NO_V" =~ -alpha ]]; then
30+
if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
31+
echo "Not on main branch (only alpha releases can be made from non-main branches)"
32+
exit 1
33+
fi
34+
fi
35+
36+
# Check that GITHUB_TOKEN is set
37+
if [ -z "${GITHUB_TOKEN:-}" ]; then
38+
echo "GITHUB_TOKEN is not set. Trying to fetch it from gh"
39+
GITHUB_TOKEN=$(gh auth token)
40+
fi
41+
42+
# Check that the tag doesn't already exist
43+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
44+
echo "error: tag $VERSION already exists" >&2
45+
exit 1
46+
fi
47+
48+
49+
## Bump all the versions in the repo
50+
##
51+
52+
# List of files to update with version numbers.
53+
VERSION_FILES=(
54+
"jmh-fork/build.gradle.kts"
55+
"examples/example-maven/pom.xml"
56+
"examples/example-gradle/build.gradle.kts"
57+
)
58+
59+
# Get current version from jmh-fork/build.gradle.kts
60+
PREVIOUS_VERSION=$(awk -F'"' '/version = / {print $2; exit}' jmh-fork/build.gradle.kts)
61+
62+
# Prompt the release version
63+
echo "Previous version: ${PREVIOUS_VERSION}"
64+
echo "New version: ${VERSION_NO_V}"
65+
read -p "Are you sure you want to release this version? (y/n): " confirm
66+
if [ "$confirm" != "y" ]; then
67+
echo "Aborting release"
68+
exit 1
69+
fi
70+
71+
# Update version in all relevant files
72+
echo "Updating version numbers in source files..."
73+
74+
# Use sed in a cross-platform way (macOS requires empty string after -i)
75+
sed_inplace() {
76+
if [[ "$OSTYPE" == "darwin"* ]]; then
77+
sed -i '' "$@"
78+
else
79+
sed -i "$@"
80+
fi
81+
}
82+
83+
for file in "${VERSION_FILES[@]}"; do
84+
sed_inplace "s/${PREVIOUS_VERSION}/${VERSION_NO_V}/g" "$file"
85+
echo " Updated $file"
86+
done
87+
88+
# Bump the jmh-fork poms (parent + all child modules) in one shot
89+
(cd jmh-fork && mvn versions:set -DnewVersion="$VERSION_NO_V" -DgenerateBackupPoms=false -q)
90+
echo " Updated jmh-fork/**/pom.xml (via mvn versions:set)"
91+
92+
# Commit version changes
93+
git add \
94+
jmh-fork \
95+
examples/example-maven/pom.xml \
96+
examples/example-gradle/build.gradle.kts
97+
git cliff -o CHANGELOG.md --tag "$VERSION" --github-token "$GITHUB_TOKEN"
98+
git add CHANGELOG.md
99+
git commit -m "chore: Release $VERSION"
100+
git tag -s "$VERSION" -m "Release $VERSION"
101+
git push origin HEAD
102+
git push origin "$VERSION"
103+
104+
# Create GitHub release
105+
if [[ "$VERSION_NO_V" =~ -alpha ]]; then
106+
gh release create "$VERSION" -t "$VERSION" --generate-notes --latest=false --draft
107+
else
108+
gh release create "$VERSION" -t "$VERSION" --generate-notes --latest --draft
109+
fi

0 commit comments

Comments
 (0)