From 6ae5512db3ed4309fd948e1c69ac51e2d4d9925d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 2 Mar 2015 14:27:35 +0100 Subject: [PATCH] [Project] setVersion.sh can now also commit --- li.strolch.dev/release.sh | 32 +++++++++---------- li.strolch.dev/setVersion.sh | 60 +++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/li.strolch.dev/release.sh b/li.strolch.dev/release.sh index 656aa8e19..6694b7035 100755 --- a/li.strolch.dev/release.sh +++ b/li.strolch.dev/release.sh @@ -80,20 +80,20 @@ push="${p}" # log what we are doing -echo "root=${root}" -echo "old_version=${old_version}" -echo "new_version=${new_version}" -echo "branch=${branch}" -echo "release_branch=${release_branch}" +echo "INFO: root=${root}" +echo "INFO: old_version=${old_version}" +echo "INFO: new_version=${new_version}" +echo "INFO: branch=${branch}" +echo "INFO: release_branch=${release_branch}" if [ -n "${create_release_branch}" ] ; then - echo "Creating release branch." + echo "INFO: Creating release branch." else - echo "NOT creating release branch." + echo "INFO: NOT creating release branch." fi if [ -n "${push}" ] ; then - echo "Pushing to origin." + echo "INFO: Pushing to origin." else - echo "NOT pushing to origin." + echo "INFO: NOT pushing to origin." fi echo "" @@ -192,7 +192,7 @@ fi # build with new version -echo "Building new version ${new_version}..." +echo -e "\nINFO: Building new version ${new_version}..." if ! build ; then fail fi @@ -220,7 +220,7 @@ echo -e "\nINFO: Committing and tagging..." if ! git add . ; then fail fi -if ! git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then +if ! git commit -m "[Project] Bumped version from ${old_version} to ${new_version}" ; then fail fi if ! git tag ${new_version} ; then @@ -229,7 +229,7 @@ fi # create bundle for new version -echo "Creating bundle for version ${new_version}..." +echo -e "\nINFO: Creating bundle for version ${new_version}..." if ! createBundle ; then fail fi @@ -269,11 +269,11 @@ if [ -n "${push}" ] ; then git push origin ${new_version} else echo -e "\nINFO: To push tags perform the following:" - echo -e "git push origin ${new_version}" - echo -e "git submodule foreach git push origin ${new_version}" + echo -e " git push origin ${new_version}" + echo -e " git submodule foreach git push origin ${new_version}" echo -e "\nINFO: Or to delete the tags:" - echo -e "git submodule foreach git tag -d ${new_version}" - echo -e "git tag -d ${new_version}" + echo -e " git submodule foreach git tag -d ${new_version}" + echo -e " git tag -d ${new_version}" fi diff --git a/li.strolch.dev/setVersion.sh b/li.strolch.dev/setVersion.sh index 46cff5176..8c6b0f0cf 100755 --- a/li.strolch.dev/setVersion.sh +++ b/li.strolch.dev/setVersion.sh @@ -1,15 +1,45 @@ #!/bin/bash -if [ "$#" != "2" ] ; then - echo "ERROR: Wrong arguments!" - echo "Usage: $0 " - exit 1 -fi if [ ! $(which xmlstarlet) ] ; then echo "ERROR: xmlstarlet is missing!" exit 1 fi +function usage() { + echo "Usage: $0 [-c] [-o ] [-n ]" 1>&2; + echo " -c commit" + echo " -o old version e.g. 1.0.0-SNAPSHOT" + echo " -n new version e.g. 1.0.0-RC3" + echo "" + exit 1; +} + +# get arguments +while getopts ":b:o:n:r:cp" arg; do + case "${arg}" in + c) + c="true" + ;; + o) + o=${OPTARG} + ;; + n) + n=${OPTARG} + ;; + *) + echo "ERROR: Unknown arg ${arg}" + usage + ;; + esac +done +shift $((OPTIND-1)) + +# validate arguments +if [ -z "${o}" ] || [ -z "${n}" ] ; then + echo "ERROR: Missing an argument!" + usage +fi + #if ! mvn -f pom.xml versions:set -DnewVersion="${1}" -DallowSnapshots=true -DgenerateBackupPoms=false ; then # echo "ERROR: Failed to change version in root!" # exit 1 @@ -19,8 +49,9 @@ fi # exit 1 #fi -old_version="$1" -new_version="$2" +old_version="${o}" +new_version="${n}" +commit="${c}" declare SCRIPT_NAME="${0##*/}" declare SCRIPT_DIR="$(cd ${0%/*} ; pwd)" @@ -93,6 +124,21 @@ if ! sed -i.bck "s/${old_version}/${new_version}/" "${create_script}" 2>/dev/nul fi rm -f "${create_script}.bck" + +# Commit new version +if [ -n "${commit}" ] ; then + echo "INFO: Committing new version ${new_version}" + git submodule foreach git add . + git submodule foreach git commit -m "[Project] Bumped version from ${old_version} to ${new_version}" + git submodule foreach git push origin develop + git add . + git commit -m "[Project] Bumped version from ${old_version} to ${new_version}" + git push origin develop +else + echo "INFO: NOT committing new version" +fi + + echo -e "\nINFO: Bumped version from ${old_version} to ${new_version}" exit 0