Skip to content

Commit 3a4f42b

Browse files
feat: update release process to add full tarball and bump versions
Github asset does not contain submodule code, we manually create the git archive with all submodules sources checked out to be used as a self contained bazel module.
1 parent 18f9286 commit 3a4f42b

File tree

3 files changed

+79
-16
lines changed

3 files changed

+79
-16
lines changed

CONTRIBUTING.md

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

33
## Release
44

5-
For now, releasing is done manually, by tagging a git rev with vX.Y.Z.
6-
7-
When releasing a new version, please make sure the version is updated in the [`core/CMakeLists.txt`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/CMakeLists.txt#L3) and [`core/BUILD`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/BUILD#L4) files to match the pushed version
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)
8+
- [`core/MODULE.bazel`](https://github.com/CodSpeedHQ/codspeed-cpp/blob/main/core/MODULE.bazel#L3)
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

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
commonBuildInputs = with pkgs; [
2222
gcc
2323
pkg-config
24+
git-cliff
2425

2526
# Build systems
2627
cmake

scripts/release.sh

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,90 @@
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'
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
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
1814
fi
1915

2016
# Check that GITHUB_TOKEN is set
2117
if [ -z "$GITHUB_TOKEN" ]; then
2218
echo "GITHUB_TOKEN is not set. Trying to fetch it from gh"
2319
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+
)
2430

31+
# Get current version from core/CMakeLists.txt
32+
PREVIOUS_VERSION=$(awk -F'[ )]' '/set\(CODSPEED_VERSION/ {print $2}' core/CMakeLists.txt)
33+
34+
# Prompt the release version
35+
echo "Previous version: ${PREVIOUS_VERSION}"
36+
echo "New version: ${VERSION_NO_V}"
37+
read -p "Are you sure you want to release this version? (y/n): " confirm
38+
if [ "$confirm" != "y" ]; then
39+
echo "Aborting release"
40+
exit 1
2541
fi
2642

43+
# Update version in all relevant files
44+
echo "Updating version numbers in source files..."
45+
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
55+
2756
git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN
2857
git add CHANGELOG.md
2958
git commit -m "chore: Release $VERSION"
3059
git tag $VERSION -m "Release $VERSION"
3160
git push origin main
3261
git push origin $VERSION
33-
gh release create $VERSION -t $VERSION --generate-notes -d
62+
63+
# Create tarball with submodules included
64+
git submodule update --init --recursive
65+
echo "Creating release tarball with submodules..."
66+
TMPDIR=$(mktemp -d)
67+
ARCHIVE_NAME="codspeed-cpp-${VERSION}"
68+
TARBALL_NAME="${ARCHIVE_NAME}.tar.gz"
69+
70+
# Create main archive
71+
git archive --prefix="${ARCHIVE_NAME}/" --format=tar HEAD | \
72+
(cd "$TMPDIR" && tar xf -)
73+
74+
# Add submodule content
75+
git submodule foreach --recursive "git archive --prefix=${ARCHIVE_NAME}/\$path/ --format=tar HEAD | (cd $TMPDIR && tar xf -)"
76+
77+
# Create final tarball
78+
(cd "$TMPDIR" && tar czf "$TMPDIR/$TARBALL_NAME" "$ARCHIVE_NAME")
79+
80+
echo "Tarball created at: $TMPDIR/$TARBALL_NAME"
81+
82+
# Create GitHub release with the tarball
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
88+
89+
# Cleanup
90+
rm -rf "$TMPDIR"

0 commit comments

Comments
 (0)