diff --git a/scripts/version.sh b/scripts/version.sh index 9574e47..4d082b9 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,6 +1,6 @@ #!/bin/bash -# this script updateds version information +# this script updates version information # version details export BUILD_DATE=`date -u +'%Y-%m-%dT%H:%M:%S%:z'` @@ -9,13 +9,18 @@ export GIT_SHA=`git rev-parse HEAD` export GIT_SHA_SHORT=`git rev-parse --short HEAD` export VERSION_PKG="github.com/mycontroller-org/esphome_api/cli/version" -# update tag, if available -if [ ${GIT_BRANCH} = "HEAD" ]; then +# update tag, if available (detached HEAD on a release tag, e.g. v1.4.0) +if [ "${GIT_BRANCH}" = "HEAD" ]; then export GIT_BRANCH=`git describe --abbrev=0 --tags` fi -# update version number -export VERSION=`echo ${GIT_BRANCH} | awk 'match($0, /([0-9]*\.[0-9]*)$/) { print substr($0, RSTART, RLENGTH) }'` +# Prefer full semver X.Y.Z (e.g. v1.4.0 -> 1.4.0). +# Do not use X.Y at end of string: that turns v1.4.0 into 4.0. +export VERSION=`echo "${GIT_BRANCH}" | awk 'match($0, /[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH); exit }'` +if [ -z "$VERSION" ]; then + # fallback: major.minor only (e.g. branch release/1.4) + export VERSION=`echo "${GIT_BRANCH}" | awk 'match($0, /[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH); exit }'` +fi if [ -z "$VERSION" ]; then # takes version from versions file and adds devel suffix with that STATIC_VERSION=`grep esphomectl= versions.txt | awk -F= '{print $2}'` diff --git a/versions.txt b/versions.txt index 3570c54..f4abd71 100644 --- a/versions.txt +++ b/versions.txt @@ -1,2 +1,2 @@ # this version number will be used for development builds -esphomectl=1.4 \ No newline at end of file +esphomectl=1.4.0 \ No newline at end of file