-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bin/create-release and supporting changes (#33)
add bin/create-release and supporting changes
- Loading branch information
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=7 |