Skip to content

Instantly share code, notes, and snippets.

@mjrider
Created January 27, 2019 18:58
Show Gist options
  • Save mjrider/bfc26eecf7c975cc492d43fc05fdd7a9 to your computer and use it in GitHub Desktop.
Save mjrider/bfc26eecf7c975cc492d43fc05fdd7a9 to your computer and use it in GitHub Desktop.
quick'n'dirty tag next release script
#!/bin/bash
# ==============================================================================
# MIT License
#
# Copyright (c) 2019 Robbert Müller
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
# ==============================================================================
readonly EX_OK=0 # Successful termination
readonly EX_NOT_ENOUGH_PARAMETERS=65 # Not enough parameters given
set -eo pipefail
git fetch --all
REF=${1:-origin/master}
version=$(git describe --abbrev=0 --tags "${REF}")
count=$(git rev-list --count "${version}".."${REF}")
if [ "${count}" -eq 0 ] ; then
echo "No commits since last tag, abort"
exit
fi
log=$(git shortlog --no-merges "${version}".."${REF}")
patch=$(semver -i patch "${version}")
minor=$(semver -i minor "${version}")
major=$(semver -i major "${version}")
dirname=$(basename "${PWD}")
newversion=$( \
whiptail --title "Select new version ( ${dirname} )" \
--menu " ${log} " 35 80 3 \
"${patch}" "Patch release" \
"${minor}" "Minor release" \
"${major}" "Major release" \
3>&1 1>&2 2>&3
)
exitstatus=$?
if [ $exitstatus != 0 ]; then
echo "Abort"
exit 1
fi
newversion="v${newversion}"
tmp=$(mktemp --suffix=commit-msg)
echo -e "🔖${newversion}\n\n${log}" > "${tmp}"
git tag -e -s -F "${tmp}" "${newversion}" "${REF}"
rm "${tmp}"
git push origin "${newversion}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment