diff --git a/bin/create-release b/bin/create-release new file mode 100755 index 0000000..c9c78ee --- /dev/null +++ b/bin/create-release @@ -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." + diff --git a/build.gradle b/build.gradle index a82b792..1da4205 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,6 @@ apply plugin: 'application' apply plugin: 'com.github.johnrengelman.shadow' group 'com.rustyrazorblade' -version '6.2.0-SNAPSHOT' sourceCompatibility = 11 diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..22f05fd --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version=7 \ No newline at end of file