Skip to content

Commit

Permalink
add bin/create-release and supporting changes (#33)
Browse files Browse the repository at this point in the history
add bin/create-release and supporting changes
  • Loading branch information
jrwest authored Oct 8, 2024
1 parent bd503ad commit 31b6e34
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
139 changes: 139 additions & 0 deletions bin/create-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

# Release script to be used for the main repo.
# Requires the GitHub client (gh) to be installed.
# No actions should be taken until the release is confirmed!

# Variables
VERSION_FILE="gradle.properties"
VERSION_KEY="version"
DEBUG=false
GH_RELEASE_DEBUG=""

HOMEBREW_FORMULA="${RRB_HOMEBREW_REPO}/Formula/easy-cass-stress.rb"


# Parse command line options
while getopts "d" opt; do
case $opt in
d)
DEBUG=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done

##### Helper Functions #####
function get_current_version {
grep "^$VERSION_KEY" "$VERSION_FILE" | cut -d'=' -f2
}

function bump_version {
echo $(( $1 + 1 ))
}

function update_version_file {
echo "Updating $VERSION_FILE, version=$1"
sed -i '' "s/^$VERSION_KEY=.*/$VERSION_KEY=$1/" "$VERSION_FILE"
if [[ "$DEBUG" = false ]]; then
git add "$VERSION_FILE"
git commit -m "Bump version to $1"
else
echo "Skipping commit"
fi
}

##### End Helper Functions #####

##### Sanity Checks. Debug mode outputs all commands. #####

if [ "$DEBUG" = true ]; then
set -x
fi

##### Check if gh is installed ####
if ! command -v gh &> /dev/null; then
echo "gh CLI is not installed. Please install it and try again."
exit 1
fi

##### ensure the formula exists #####
if [ ! -f "$HOMEBREW_FORMULA" ]; then
echo "Error: File $HOMEBREW_FORMULA does not exist."
exit 1
fi

##### ensure docker is running
if ! docker info > /dev/null 2>&1; then
echo "Error: Docker is not running."
exit 1
fi

##### End Sanity Checks #####

####### Main script #######

if [ "$DEBUG" = false ]; then
if ! git diff-index --quiet HEAD --; then
echo "You have uncommitted changes. Please commit or stash them before running this script."
exit 1
fi
else
GH_RELEASE_DEBUG="--draft"
fi

current_version=$(get_current_version)
new_version=$(bump_version "$current_version")

echo "Current version: $current_version, new version: $new_version"

echo "Building..."

gw distTar
RELEASE_FILE="build/distributions/easy-cass-stress-${current_version}.tar.gz"

if [ ! -f "$RELEASE_FILE" ]; then
echo "Release file $RELEASE_FILE does not exist, exiting."
exit 1
fi

#### SHA256 and URL for the repo update
ARTIFACT_SHA=$(sha2 -256 -q $RELEASE_FILE)

echo "SHA: $ARTIFACT_SHA"

echo "Current version: $current_version, next version: $new_version. Enter to continue, control-c to quit."

read

##### Create release in GitHub #####
if [ "$DEBUG" = false ]; then
gh release create "v${current_version}" --generate-notes $RELEASE_FILE
else
echo "Skipping gh create create because we're in debug mode."
fi

##### Update Homebrew

# Update the `version` and `sha256` fields.
sed -i '' "s/^\([[:space:]]*\)version.*/\1version \"${current_version}\"/" $HOMEBREW_FORMULA
sed -i '' "s/^\([[:space:]]*\)sha256.*/\1sha256 \"${ARTIFACT_SHA}\"/" $HOMEBREW_FORMULA

# commit and push
if [ "$DEBUG" = false ]; then
(
cd $RRB_HOMEBREW_REPO
git commit -am "Version bump to $current_version"
git push
)
fi

##### Done with the release, now we increment gradle's version #####

update_version_file "$new_version"

echo "Release $new_version created successfully."

1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

group 'com.rustyrazorblade'
version '6.2.0-SNAPSHOT'

sourceCompatibility = 11

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=7

0 comments on commit 31b6e34

Please sign in to comment.