|
1 | 1 | #!/bin/bash |
2 | 2 | set -e |
3 | 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 | 4 | # First and only argument is the version number |
| 5 | +VERSION_NO_V=${1} # The version number without the 'v' prefix |
11 | 6 | 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 |
18 | 14 | fi |
19 | 15 |
|
20 | 16 | # Check that GITHUB_TOKEN is set |
21 | 17 | if [ -z "$GITHUB_TOKEN" ]; then |
22 | 18 | echo "GITHUB_TOKEN is not set. Trying to fetch it from gh" |
23 | 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 | +) |
24 | 30 |
|
| 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 |
25 | 41 | fi |
26 | 42 |
|
| 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 | + |
27 | 56 | git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN |
28 | 57 | git add CHANGELOG.md |
29 | 58 | git commit -m "chore: Release $VERSION" |
30 | 59 | git tag $VERSION -m "Release $VERSION" |
31 | 60 | git push origin main |
32 | 61 | 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