Skip to content

Commit

Permalink
Fix: gitVersion is invalid when executing chaosd version (#205)
Browse files Browse the repository at this point in the history
Signed-off-by: Cwen Yin <cwenyin0@gmail.com>

Signed-off-by: Cwen Yin <cwenyin0@gmail.com>
  • Loading branch information
cwen0 committed Aug 16, 2022
1 parent 4cbe994 commit 2c42950
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions hack/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ set -euo pipefail

function chaosd::version::get_version_vars() {
if [[ -n ${GIT_COMMIT-} ]] || GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then

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

0 comments on commit 2c42950

Please sign in to comment.