Skip to content

Commit

Permalink
improve gitVersion format (#1297)
Browse files Browse the repository at this point in the history
Signed-off-by: cwen0 <cwenyin0@gmail.com>
  • Loading branch information
cwen0 committed Dec 17, 2020
1 parent 8d8dce8 commit f7e0c63
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions hack/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ set -euo pipefail

function chaos_mesh::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/")
if [[ "${DASHES_IN_VERSION}" != "" ]] ; 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 f7e0c63

Please sign in to comment.