|
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' |
| 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 | + |
12 | 34 | # Prompt the release version |
| 35 | +echo "Previous version: ${PREVIOUS_VERSION}" |
13 | 36 | echo "Release version: $VERSION" |
14 | 37 | read -p "Are you sure you want to release this version? (y/n): " confirm |
15 | 38 | if [ "$confirm" != "y" ]; then |
16 | 39 | echo "Aborting release" |
17 | 40 | exit 1 |
18 | 41 | fi |
19 | 42 |
|
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..." |
24 | 45 |
|
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 |
26 | 55 |
|
27 | 56 | git cliff -o CHANGELOG.md --tag $VERSION --github-token $GITHUB_TOKEN |
28 | 57 | git add CHANGELOG.md |
@@ -51,7 +80,11 @@ git submodule foreach --recursive "git archive --prefix=${ARCHIVE_NAME}/\$path/ |
51 | 80 | echo "Tarball created at: $TMPDIR/$TARBALL_NAME" |
52 | 81 |
|
53 | 82 | # 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 |
55 | 88 |
|
56 | 89 | # Cleanup |
57 | 90 | rm -rf "$TMPDIR" |
0 commit comments