Skip to content

Commit 8a8c313

Browse files
feat: improve release script
1 parent cccb6fc commit 8a8c313

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## Release
44

5-
To create a release, follow these steps:
6-
7-
1. Update the version in the following locations to the new version:
8-
- [`core/CMakeLists.txt`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/CMakeLists.txt#L3)
5+
To create a release, run `scripts/release.sh <new_version>` from the main branch. This script will:
6+
1. Automatically update the version in all relevant files:
7+
- [`core/CMakeLists.txt`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/CMakeLists.txt#L3)
98
- [`core/MODULE.bazel`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/MODULE.bazel#L3)
10-
- [`google_benchmark/MODULE.bazel` module's version](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/google_benchmark/MODULE.bazel#L3)
11-
- [`google_benchmark/MODULE.bazel` core dependency version](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/google_benchmark/MODULE.bazel#L6)
12-
2. Once the version changes are merged on main, run `scripts/release.sh <new_version>` to tag and create the release on GitHub.
9+
- [`google_benchmark/MODULE.bazel`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/google_benchmark/MODULE.bazel)
10+
2. Create a commit with the version changes
11+
3. Generate the CHANGELOG
12+
4. Tag and create the release on GitHub

scripts/release.sh

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
#!/bin/bash
22
set -e
33

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-
104
# First and only argument is the version number
5+
VERSION_NO_V=${1} # The version number without the 'v' prefix
116
VERSION=v$1 # The version number, prefixed with 'v'
7+
8+
# Check is on main (unless releasing an alpha version)
9+
if [[ ! "$VERSION_NO_V" =~ -alpha ]]; then
10+
if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
11+
echo "Not on main branch (only alpha releases can be made from non-main branches)"
12+
exit 1
13+
fi
14+
fi
15+
16+
# Check that GITHUB_TOKEN is set
17+
if [ -z "$GITHUB_TOKEN" ]; then
18+
echo "GITHUB_TOKEN is not set. Trying to fetch it from gh"
19+
GITHUB_TOKEN=$(gh auth token)
20+
fi
21+
22+
# List of files and line numbers to update with version numbers
23+
# Format: "file:line_number"
24+
VERSION_FILES=(
25+
"core/CMakeLists.txt:3"
26+
"core/MODULE.bazel:3"
27+
"google_benchmark/MODULE.bazel:3"
28+
"google_benchmark/MODULE.bazel:6"
29+
)
30+
31+
# Get current version from core/CMakeLists.txt
32+
PREVIOUS_VERSION=$(grep "set(CODSPEED_VERSION" core/CMakeLists.txt | grep -oP '\d+\.\d+\.\d+')
33+
1234
# Prompt the release version
35+
echo "Previous version: ${PREVIOUS_VERSION}"
1336
echo "Release version: $VERSION"
1437
read -p "Are you sure you want to release this version? (y/n): " confirm
1538
if [ "$confirm" != "y" ]; then
1639
echo "Aborting release"
1740
exit 1
1841
fi
1942

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)
43+
# Update version in all relevant files
44+
echo "Updating version numbers in source files..."
2445

25-
fi
46+
for entry in "${VERSION_FILES[@]}"; do
47+
IFS=':' read -r file line_num <<< "$entry"
48+
sed -i "${line_num}s/${PREVIOUS_VERSION}/${VERSION_NO_V}/" "$file"
49+
echo " Updated $file:$line_num"
50+
done
51+
52+
# Commit version changes
53+
FILES_TO_COMMIT=$(printf "%s\n" "${VERSION_FILES[@]%%:*}" | sort -u | xargs)
54+
git add $FILES_TO_COMMIT
2655

2756
git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN
2857
git add CHANGELOG.md
@@ -51,7 +80,11 @@ git submodule foreach --recursive "git archive --prefix=${ARCHIVE_NAME}/\$path/
5180
echo "Tarball created at: $TMPDIR/$TARBALL_NAME"
5281

5382
# Create GitHub release with the tarball
54-
gh release create $VERSION -t $VERSION --generate-notes -d "$TMPDIR/$TARBALL_NAME"
83+
if [[ "$VERSION_NO_V" =~ -alpha ]]; then
84+
gh release create $VERSION -t $VERSION --generate-notes --latest=false "$TMPDIR/$TARBALL_NAME"
85+
else
86+
gh release create $VERSION -t $VERSION --generate-notes --latest "$TMPDIR/$TARBALL_NAME"
87+
fi
5588

5689
# Cleanup
5790
rm -rf "$TMPDIR"

0 commit comments

Comments
 (0)