From a0cdda6fa9be17963a1fb2be436b23213a635891 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Mon, 1 Nov 2021 19:08:05 +0000 Subject: [PATCH] Add more features to the version script --- scripts/version.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index 5713c0a..efd1929 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -4,18 +4,17 @@ # usage() { - echo "Usage: $0 [short]" + echo "Usage: $0 [short|hash]" echo echo "Determine the correct version number for the current build" exit 0 } -# TODO: search for the top dir that contains the VERSION file? -VER_FILE_SHORT=$(cat VERSION) +VER_FILE_DIR=$(dirname "$0")/.. +VER_FILE_SHORT=$(cat "${VER_FILE_DIR}/VERSION") if git status >/dev/null; then VER_GIT_SHORT=$(git describe --abbrev=0) - VER_GIT=$(git describe --abbrev=7 --dirty) if [ "$VER_FILE_SHORT" != "$VER_GIT_SHORT" ]; then echo "Error: VERSION file does not match tag version ($VER_FILE_SHORT != $VER_GIT_SHORT)" @@ -23,13 +22,18 @@ if git status >/dev/null; then fi VER_SHORT="$VER_GIT_SHORT" - VER="$VER_GIT" + VER_HASH=$(git rev-parse --short HEAD) + VER=$(git describe --abbrev=7 --dirty) else VER_SHORT="$VER_FILE_SHORT" + VER_HASH="HEAD" VER="$VER_FILE_SHORT" fi case "$1" in + hash) + echo "$VER_HASH" + ;; short) echo "$VER_SHORT" ;;