Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit 4ac1444

Browse files
committed
Strip leading 'v' from git tags if present.
As discussed at: golang/go#32945 https://semver.org/#is-v123-a-semantic-version Go and semver disagree about handling of a leading 'v' on version strings. This patch allows robotest to play nicely with both.
1 parent ba7f76b commit 4ac1444

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

version.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ COMMITS_SINCE_LAST_TAG=`git rev-list ${COMMIT_WITH_LAST_TAG}..HEAD --count`
2929
BUILD_METADATA=`git rev-parse --short=8 HEAD`
3030
DIRTY_AFFIX=$(git diff --quiet || echo '-dirty')
3131

32+
# strip leading v from git tag, see:
33+
# https://github.com/golang/go/issues/32945
34+
# https://semver.org/#is-v123-a-semantic-version
35+
if [[ "$SHORT_TAG" == v* ]]; then
36+
SEMVER_TAG="${SHORT_TAG:1}"
37+
else
38+
SEMVER_TAG="${SHORT_TAG}"
39+
fi
40+
3241
if [[ "$LONG_TAG" == "$SHORT_TAG" ]] ; then # the current commit is tagged as a release
33-
echo "${SHORT_TAG}${DIRTY_AFFIX}"
42+
echo "${SEMVER_TAG}${DIRTY_AFFIX}"
3443
elif [[ "$SHORT_TAG" != *-* ]] ; then # the current ref is a decendent of a regular version
3544
SHORT_TAG=$(increment_patch ${SHORT_TAG})
36-
echo "$SHORT_TAG-dev.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
45+
echo "$SEMVER_TAG-dev.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
3746
else # the current ref is a decendent of a pre-release version (e.g. rc, alpha, or beta)
38-
echo "$SHORT_TAG.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
47+
echo "$SEMVER_TAG.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
3948
fi

0 commit comments

Comments
 (0)