From 891c04d70b30ed4533785469b8bd2f5d6c17a68c Mon Sep 17 00:00:00 2001 From: "Alexandru N. Onea" Date: Tue, 9 Apr 2019 21:16:34 +0300 Subject: Add release action to version-bump.sh --- scripts/version-bump.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/version-bump.sh b/scripts/version-bump.sh index 6378801..287580b 100755 --- a/scripts/version-bump.sh +++ b/scripts/version-bump.sh @@ -31,10 +31,11 @@ print_usage() echo "Usage: $0 [OPTIONS] ACTION" echo echo "Available options:" - echo " -s,--script Format output in \"script\" mode (no trailing newline)." + echo " -s,--script Format output in \"script\" mode (no trailing newline)." echo echo "Available actions:" - echo " print [minor|major|patch] Print the current version." + echo " print [minor|major|patch] Print the current version." + echo " release [minor|major|patch] Bump the specified version part" echo echo "Please run this script from the project root folder." } @@ -44,9 +45,9 @@ print_usage() # Takes one argument: the matching version identifier in the version file. get_version_part() { - local V=$(grep -m 1 "^#define\([ \t]*\)${1}" ${VERSION_FILE} | sed 's/[^0-9]*//g') + local V=$(grep -m 1 "^#define\([ \t]*\)$1" ${VERSION_FILE} | sed 's/[^0-9]*//g') - [ ! -z ${V} ] || die "Could not get ${1} from ${VERSION_FILE}" + [ ! -z ${V} ] || die "Could not get $1 from ${VERSION_FILE}" echo ${V} } @@ -62,6 +63,32 @@ get_version() VERSION_PATCH=$(get_version_part "TINYALSA_VERSION_PATCH") } +# Commits the new version part to the version file. +# Takes two arguments: the version part identifier in the version file and the +# new version number. +commit_version_part() +{ + if [ -z $1 ] || [ -z $2 ]; then + return 0 + fi + + sed -i "s/\(^#define[ \t]*$1\)[ \t]*\([0-9]*\)/\1 $2/g" ${VERSION_FILE} \ + || die "Could not commit version"; + + return 0 +} + +# Commits the new version to the version file. +# Takes three arguments, the new version numbers for major, minor and patch +commit_version() +{ + commit_version_part "TINYALSA_VERSION_PATCH" $1 + commit_version_part "TINYALSA_VERSION_MINOR" $2 + commit_version_part "TINYALSA_VERSION_MAJOR" $3 + + return 0 +} + # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # Actions implementations / functions @@ -93,6 +120,40 @@ print_version() return 0 } +bump_version() +{ + get_version + + local PART="patch" + + if [ ! -z $1 ]; then + PART="$1" + fi + + case "$PART" in + major) + VERSION_MAJOR=$((VERSION_MAJOR+1)) + VERSION_MINOR=0 + VERSION_PATCH=0 + ;; + minor) + VERSION_MINOR=$((VERSION_MINOR+1)) + VERSION_PATCH=0 + ;; + patch) + VERSION_PATCH=$((VERSION_PATCH+1)) + ;; + *) + die "Unknown part \"$1\" (must be one of minor, major and patch)." + ;; + esac + + commit_version ${VERSION_PATCH} ${VERSION_MINOR} ${VERSION_MAJOR} + print_version + + return 0 +} + # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # # Command Line parsing @@ -110,6 +171,10 @@ parse_command() print_version "$2" exit $? ;; + release) + bump_version "$2" + exit $? + ;; *) die "Unsupported action \"$1\"." ;; -- cgit v1.2.3