From 86743163219785c4411740cbac4de1767d473a14 Mon Sep 17 00:00:00 2001 From: Isaac Bennetch Date: Thu, 16 Aug 2018 12:55:36 -0400 Subject: [PATCH] Add a helper script to automate most of the work when changing version numbers Signed-off-by: Isaac Bennetch --- scripts/set-version.sh | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 scripts/set-version.sh diff --git a/scripts/set-version.sh b/scripts/set-version.sh new file mode 100755 index 0000000000..dab40d0bf0 --- /dev/null +++ b/scripts/set-version.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# +# vim: expandtab sw=4 ts=4 sts=4: +# +# This requires Bash for the search and replace substitution to escape dots + +# Do not run as CGI +if [ -n "$GATEWAY_INTERFACE" ] ; then + echo 'Can not invoke as CGI!' + exit 1 +fi + +# Fail on undefined variables +set -u +# Fail on failure +set -e + +printHelp () { + echo + echo "Please pass the new version number as a command line argument such as" + echo "$0 -v 5.0.0-dev" + echo +} + +if [ $# -eq 0 ] +then + printHelp + exit 1 +fi + +if [ $1 = '-v' ] +then + newVersion=$2 +else + printHelp + exit 2 +fi + +# If we're in the scripts directory, we need to do all our work up a directory level +if [ "$(basename `pwd`)" = 'scripts' ] +then + dir='../' +else + dir='' +fi + +# There are half a dozen ways to do this, including individually recreating the line of +# each file (search for 'version =' in conf.py and replace it with 'version = 5.0.0-dev' +# for instance), and while that's more precise this should work with less to fix if a line changes. +# This method wasn't selected for any particular strength. + +oldVersion="$(grep 'version =' ${dir}doc/conf.py | cut -d "'" -f2)" + +echo "Changing from ${oldVersion} to ${newVersion}..." + +# Escape the dot for sed +oldVersion=${oldVersion//./\.} +newVersion=${newVersion//./\.} + +for f in README doc/conf.py libraries/classes/Config.php package.json +do + if ! grep --quiet "${oldVersion}" "${dir}${f}" + then + # There may be a better way to test for a failure of the substitution itself, such as using the 'q' directive with sed + # See https://stackoverflow.com/questions/15965073/return-code-of-sed-for-no-match + echo "FAILED! Substitution string ${oldVersion} not found in ${dir}${f}" + fi + sed -i "s/${oldVersion}/${newVersion}/g" "${dir}${f}" +done + + +echo +echo "Next, you need to manually edit ChangeLog to manually change the version number and set the release date, and verify the changes with 'git diff'." +echo "Suggested commit message: Prepare for version ${newVersion}" \ No newline at end of file