Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions tag.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

# Error exit
#
function error_exit() {
echo -e "${red}FAILURE${reset}"
exit 1
}

# @param $1
# Replacement pattern
# @param $2
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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."
Expand All @@ -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="<ul>\n\n $( git log --format='<li><a href=%x22https://git.drupalcode.org/project/drupal/commit/%H%x22>%s</a></li>%n' ${v}^...${p} ) \n\n</ul>\n\n"

Expand All @@ -99,6 +138,9 @@ if hash pbcopy 2>/dev/null; then
else
echo -e "$notes"
fi

echo -e "\n\n${green}SUCCESS${reset}"

echo -e "To push use:\n"
echo -e "git push origin $v ${major}.${minor}.x"
echo -e "\n"