From: Thanh Ha Date: Sat, 4 Mar 2017 23:52:16 +0000 (-0500) Subject: Convert version bump script to functions X-Git-Tag: v0.0.6~5 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F4069%2F2;p=releng%2Flftools.git Convert version bump script to functions Convert the version bump script to functions so that it can be sourced and reused more easily. Change-Id: I09dde2c7e51b6dc8b70bb5befbe22d1fdb947903 Signed-off-by: Thanh Ha --- diff --git a/shell/version b/shell/version index f40a4f9e..da17ae70 100755 --- a/shell/version +++ b/shell/version @@ -2,7 +2,7 @@ # @License EPL-1.0 ############################################################################## -# Copyright (c) 2014 The Linux Foundation and others. +# Copyright (c) 2014, 2017 The Linux Foundation and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 @@ -11,6 +11,7 @@ # # Contributors: # Colin Dixon - Initial implementation +# Thanh Ha - Convert to functions ############################################################################## # In general, versions should be: ..[-] @@ -37,32 +38,43 @@ # 2.) take all x.y.z-Helium versions to x.y.(z+1)-SNAPSHOT and # 3.) take all x.y.z-SNAPSHOT versions to x.(y+1).0-SNAPSHOT -USAGE="USAGE: versions \n\ -\n\ -mode - bump|release\n\ -tag - example: Helium-SR1" +print_version_usage() { + echo "Usage:" + echo " version bump Bump all versions in pom files" + echo " version release Convert all SNAPSHOTS to " + echo " example-tag: Helium-SR1" +} -if [ -z "$2" ] -then - echo -e "$USAGE" - exit 1 -fi +version() { + subcommand=$1; shift + FILENAMES="pom.xml repo-pom.xml features.xml" -MODE=$1 -RELEASE_TAG=$2 -FILENAMES="pom.xml repo-pom.xml features.xml" - - -if [ "$MODE" == "bump" ] -then - echo "Bumping versions..." - for name in $FILENAMES - do - # Notes: - # * bump date-based versions first to avoid date-only versions from being caught as x.y.z, - # * this assumes that a normal x.y.z version can't match YYYY.MM.DD, which is probably true - # * bump -SNAPSHOT versions first so that we don't double bump versions + case "$subcommand" in + bump ) + RELEASE_TAG=$1 + echo "Bumping versions..." + version_bump + exit 0 + ;; + release ) + RELEASE_TAG=$1 + echo "Bumping SNAPSHOTS to $RELEASE_TAG" + exit 0 + ;; + * ) + echo "Invalid command: $subcommand" 1>&2 + print_version_usage + exit 1 + ;; + esac +} +version_bump() { + # Notes: + # * bump date-based versions first to avoid date-only versions from being caught as x.y.z, + # * this assumes that a normal x.y.z version can't match YYYY.MM.DD, which is probably true + # * bump -SNAPSHOT versions first so that we don't double bump versions + for name in $FILENAMES; do # Changes YYYY.MM.DD.y.z-SNAPSHOT to YYYY.MM.DD.(y+1).0-SNAPSHOT in pom.xml files (if y or z is missing treat as 0) find . -type f -name "$name" -exec perl -i -pe "s/(\d\d\d\d\.\d\d\.\d\d)\.(\d+)\.(\d+)-SNAPSHOT/\$1.@{[1+\$2]}.0-SNAPSHOT/g" {} + find . -type f -name "$name" -exec perl -i -pe "s/(\d\d\d\d\.\d\d\.\d\d)\.(\d+)-SNAPSHOT/\$1.@{[1+\$2]}.0-SNAPSHOT/g" {} + @@ -80,15 +92,12 @@ then # Changes x.y.z-Helium to x.y.(z+1)-SNAPSHOT in pom.xml files (if z is missing treat as 0) find . -type f -name "$name" -exec perl -i -pe "s/([^\d.]\d+)\.(\d+)\.(\d+)-$RELEASE_TAG/\$1.\$2.@{[1+\$3]}-SNAPSHOT/g" {} + find . -type f -name "$name" -exec perl -i -pe "s/([^\d.]\d+)\.(\d+)-$RELEASE_TAG/\$1.\$2.1-SNAPSHOT/g" {} + - done -elif [ "$MODE" == "release" ] -then +} + +version_release() { for name in $FILENAMES do find . -type f -name "$name" -exec perl -i -pe "s/SNAPSHOT/$RELEASE_TAG/g" {} + done -else - echo -e "$USAGE" - exit 1 -fi +}