Skip to content

Commit 30f3f30

Browse files
feat: improve release script
1 parent cccb6fc commit 30f3f30

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
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: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,49 @@ if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
77
exit 1
88
fi
99

10+
# Check that GITHUB_TOKEN is set
11+
if [ -z "$GITHUB_TOKEN" ]; then
12+
echo "GITHUB_TOKEN is not set. Trying to fetch it from gh"
13+
GITHUB_TOKEN=$(gh auth token)
14+
fi
15+
1016
# First and only argument is the version number
1117
VERSION=v$1 # The version number, prefixed with 'v'
18+
VERSION_NO_V=${1} # The version number without the 'v' prefix
19+
20+
# List of files and line numbers to update with version numbers
21+
# Format: "file:line_number"
22+
VERSION_FILES=(
23+
"core/CMakeLists.txt:3"
24+
"core/MODULE.bazel:3"
25+
"google_benchmark/MODULE.bazel:3"
26+
"google_benchmark/MODULE.bazel:6"
27+
)
28+
29+
# Get current version from core/CMakeLists.txt
30+
PREVIOUS_VERSION=$(grep "set(CODSPEED_VERSION" core/CMakeLists.txt | grep -oP '\d+\.\d+\.\d+')
31+
1232
# Prompt the release version
33+
echo "Previous version: ${PREVIOUS_VERSION}"
1334
echo "Release version: $VERSION"
1435
read -p "Are you sure you want to release this version? (y/n): " confirm
1536
if [ "$confirm" != "y" ]; then
1637
echo "Aborting release"
1738
exit 1
1839
fi
1940

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)
41+
# Update version in all relevant files
42+
echo "Updating version numbers in source files..."
2443

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

2754
git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN
2855
git add CHANGELOG.md

0 commit comments

Comments
 (0)