Skip to content

Commit 2c42950

Browse files
authored
Fix: gitVersion is invalid when executing chaosd version (#205)
Signed-off-by: Cwen Yin <[email protected]> Signed-off-by: Cwen Yin <[email protected]>
1 parent 4cbe994 commit 2c42950

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

hack/version.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ set -euo pipefail
1717

1818
function chaosd::version::get_version_vars() {
1919
if [[ -n ${GIT_COMMIT-} ]] || GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then
20-
2120
# Use git describe to find the version based on tags.
22-
if [[ -n ${GIT_VERSION-} ]] || GIT_VERSION=$(git describe --tags --abbrev=14 "${GIT_COMMIT}^{commit}" 2>/dev/null); then
23-
DASHES_IN_VERSION=$(echo "${GIT_VERSION}" | sed "s/[^-]//g")
24-
if [[ "${DASHES_IN_VERSION}" == "---" ]] ; then
25-
# We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
26-
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\+\2/")
27-
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then
28-
# We have distance to base tag (v1.1.0-1-gCommitHash)
29-
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-g\([0-9a-f]\{14\}\)$/+\1/")
21+
# --always would show the unique abbr commit as fallback.
22+
if [[ -n ${GIT_VERSION-} ]] || GIT_VERSION=$(git describe --always --tags --abbrev=14 "${GIT_COMMIT}^{commit}" 2>/dev/null); then
23+
# if current commit is not on a certain tag
24+
if ! git describe --tags --exact-match >/dev/null 2>&1 ; then
25+
# GIT_VERSION=gitBranch-gitCommitHash
26+
IFS='-' read -ra GIT_ARRAY <<< "$GIT_VERSION"
27+
GIT_VERSION=$(git rev-parse --abbrev-ref HEAD)-${GIT_ARRAY[${#GIT_ARRAY[@]}-1]}
3028
fi
3129
fi
3230
fi

0 commit comments

Comments
 (0)