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

Commit

Permalink
Strip leading 'v' from git tags if present.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wadells committed May 13, 2020
1 parent 2091caa commit a3bf28b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ COMMITS_SINCE_LAST_TAG=`git rev-list ${COMMIT_WITH_LAST_TAG}..HEAD --count`
BUILD_METADATA=`git rev-parse --short=8 HEAD`
DIRTY_AFFIX=$(git diff --quiet || echo '-dirty')

# strip leading v from git tag, see:
# https://github.com/golang/go/issues/32945
# https://semver.org/#is-v123-a-semantic-version
if [[ "$SHORT_TAG" == v* ]]; then
SEMVER_TAG="${SHORT_TAG:1}"
else
SEMVER_TAG="${SHORT_TAG}"
fi

if [[ "$LONG_TAG" == "$SHORT_TAG" ]] ; then # the current commit is tagged as a release
echo "${SHORT_TAG}${DIRTY_AFFIX}"
echo "${SEMVER_TAG}${DIRTY_AFFIX}"
elif [[ "$SHORT_TAG" != *-* ]] ; then # the current ref is a decendent of a regular version
SHORT_TAG=$(increment_patch ${SHORT_TAG})
echo "$SHORT_TAG-dev.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
echo "$SEMVER_TAG-dev.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
else # the current ref is a decendent of a pre-release version (e.g. rc, alpha, or beta)
echo "$SHORT_TAG.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
echo "$SEMVER_TAG.${COMMITS_SINCE_LAST_TAG}+${BUILD_METADATA}${DIRTY_AFFIX}"
fi

0 comments on commit a3bf28b

Please sign in to comment.