blob: a3cc54bb8ce967b0de3403ba8d34e452ba757cea [file] [log] [blame]
#!/bin/bash -e -u
echo >&2 'Usage: release-make [ --release <version> ] [ --next <version> ]'
echo >&2 'Creates and tags a release based on the current branch.'
echo >&2 'Arguments are optional - if omitted, the script tries to work out the correct versions.'
echo >&2 'release <version> should be a full version number, such as 3.6.0-RC1'
echo >&2 'next <version> should be a snapshot version number, such as 3.6.0-RC2-SNAPSHOT'
echo >&2 'This command will preview what it is going to do and require confirmation before it makes changes.'
[ $# -eq 0 ] && echo >&2 "No arguments given, so I'm going to try and figure it out myself. Invoke with the --help option if you want to find how to invoke this script."
while [ $# -gt 0 ]; do
case $1 in
--release) shift; release_tag_ver=$1;;
--next) shift; release_branch_ver=$1;;
*) usage; exit 1;;
# Some magic to derive the anticipated version of the release.
# Use xpath to query the version number in the pom
type -P $xpath &>/dev/null && {
set +e
current_version=$( xpath pom.xml '/project/version/text()' 2>/dev/null )
set -e
} || {
echo "Cannot guess version number as $xpath command not found."
# If the user didn't supply the release version, strip -SNAPSHOT off the current version and use that
[ -z "$release_tag_ver" ] && release_tag_ver=${current_version%-SNAPSHOT}
# More magic, this time to guess the next version.
# If the user didn't supply the next version, modify the digits off the end of the release to increment by one and append -SNAPSHOT
[ -z "$release_branch_ver" ] && release_branch_ver=$( echo ${release_tag_ver} | perl -n -e 'if (/^(.*)(\d+)$/) { print $1.($2+1)."-SNAPSHOT\n" }' )
current_branch=$( git name-rev --name-only HEAD )
echo "The release is on the branch: ${current_branch}"
echo "The current version (detected) is: ${current_version}"
echo "The release version is: ${release_tag_ver}"
echo "Development on the release branch continues with version: ${release_branch_ver}"
echo -n 'Enter "y" if this is correct, anything else to abort: '
read input
[ "$input" == "y" ] || { echo >&2 Aborted. ; exit 1 ; }
# Warn if the current branch is master
[ ${current_branch} == "master" ] && {
echo Current branch is ${current_branch}. Usually, releases are made from a release branch.
echo -n 'Enter "y" if this is correct, anything else to abort: '
read input
[ "$input" == "y" ] || { echo >&2 Aborted. ; exit 1 ; }
# Release prepare
mvn release:clean release:prepare -PExample,Launcher,Four,Three --batch-mode -DautoVersionSubmodules=true -DreleaseVersion=${release_tag_ver} -DdevelopmentVersion=${release_branch_ver}
# Release perform
mvn release:perform -PExample,Launcher,Four,Three --batch-mode