diff --git a/tag.sh b/tag.sh index e68796f..9637d7e 100755 --- a/tag.sh +++ b/tag.sh @@ -1,5 +1,12 @@ #!/bin/bash +# Error exit +# +function error_exit() { + echo -e "${red}FAILURE${reset}" + exit 1 +} + # @param $1 # Replacement pattern # @param $2 @@ -25,8 +32,8 @@ function set_version() { else grep -q "[0-9\.]*-dev" core/lib/Drupal.php if [ ! $? -eq 0 ] ; then - echo -e "Cannot match version constant. The release must be tagged manually." - exit 1 + echo -e "\nCannot match version constant. The release must be tagged manually." + error_exit fi echo -e "\n\n Setting version with sed for 9.0 and earlier \n" @@ -35,9 +42,20 @@ function set_version() { fi } +# Set up variables to make coloured output simple. +red=`tput setaf 1 && tput bold` +green=`tput setaf 2` +reset=`tput sgr0` + +# Get the new tag and exit if it exists. echo -e "Enter the release version (e.g. 9.3.6 or 9.4.0-beta2):" read v +if git rev-parse "$v" >/dev/null 2>&1 ; then + echo -e "\nTag '$v' exists." + error_exit +fi + re="^([0-9]+)\.([0-9]+)\.([0-9]+)(-[A-Za-z0-9]+)?$" if [[ $v =~ $re ]] ; then @@ -57,21 +75,29 @@ if [[ $v =~ $re ]] ; then if [ -z "$p" ] ; then p=$calc_p fi + if ! git rev-parse "$p" >/dev/null 2>&1 ; then + echo -e "\nPrevious tag '$p' does not exist." + error_exit + fi + echo -e "Enter the next stable release (blank for $calc_n):" read n if [ -z "$n" ] ; then n=$calc_n fi else - echo -e "Unrecognized version. The release must be tagged manually." - exit 1 + echo -e "\nUnrecognized version. The release must be tagged manually." + error_exit fi +set_version "$v" "$major" "$minor" + echo "Composer installing." rm -rf vendor composer install --no-progress --no-suggest -n -q - -set_version "$v" "$major" "$minor" +if [ "$?" -ne "0" ] ; then + error_exit +fi # Update the version strings in the metapackages echo "Updating metapackage versions to ${v} and tagging." @@ -80,16 +106,29 @@ echo "Updating metapackage versions to ${v} and tagging." COMPOSER_ROOT_VERSION="$v" composer update drupal/core* git commit -am "Drupal $v" --no-verify +if [ "$?" -ne "0" ] ; then + error_exit +fi + git tag -a "$v" -m "Drupal $v" +if [ "$?" -ne "0" ] ; then + error_exit +fi # Revert the composer.lock change in the last commit git revert HEAD --no-commit +if [ "$?" -ne "0" ] ; then + error_exit +fi # Put the version back to dev set_version "${n}-dev" "$major" "$minor" echo "Restoring metapackage versions back to ${major}.${minor}.x-dev" git commit -am "Back to dev." --no-verify +if [ "$?" -ne "0" ] ; then + error_exit +fi notes="