Created
June 17, 2019 19:32
-
-
Save ErikHumphrey/a74c859bd1f6ced8bfa04f34d2dc12f5 to your computer and use it in GitHub Desktop.
Bash script to push new releases easily
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
#!/bin/bash | |
current_date=`date +%Y-%m-%d` | |
cd | |
# Replace with path to repository | |
cd projects/sandbox | |
git fetch --tags | |
latest=`git describe --abbrev=0` | |
tags_by_date=$( | |
git for-each-ref --sort=taggerdate --format '%(tag)_,,,_%(taggerdate:raw)_,,,_%(taggername)_,,,_%(subject)' refs/tags \ | awk 'BEGIN { FS = "_,,,_" } ; { t=strftime("%Y-%m-%d %H:%M",$2); printf "%-20s %-18s %-25s %s\n", t, $1, $4, $3 }' | |
) | |
next_version () | |
{ | |
declare -a part=( ${1//\./ } ) | |
declare new | |
declare -i carry=1 | |
for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do | |
len=${#part[CNTR]} | |
new=$((part[CNTR]+carry)) | |
[ ${#new} -gt $len ] && carry=1 || carry=0 | |
[ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} | |
done | |
new="${part[*]}" | |
echo -e "${new// /.}" | |
} | |
version=v`next_version $latest` | |
read -e -i "$version" -p "Enter the version: " version_input | |
version=${input:-$version} | |
sha=`git rev-parse --short HEAD` | |
read -e -i "$sha" -p "Enter the commit hash: " sha_input | |
sha=${sha_input:-$sha} | |
build_num=$(echo "$tags_by_date" | grep -c "$current_date") | |
((build_num++)) | |
read -e -i $build_num -p "Including this one, how many times have you pushed today? " build_num_input | |
BUILD_NUM=${build_num_input:-$build_num} | |
echo -e "\nNext version: $version" | |
echo "Production Release $build_num on $current_date" | |
echo "Latest commit $sha" | |
read -p " | |
OK?" | |
git tag -a $version -m "Production Release $build_num on $current_date" $sha | |
git push origin $version > /dev/null 2>&1 | |
$SHELL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment