Add more features to the version script

This commit is contained in:
Hamish Coleman 2021-11-01 19:08:05 +00:00
parent f7d6be51cf
commit a0cdda6fa9

View File

@ -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"
;;