update get-version to understand submodule tags (#4229)
This commit is contained in:
parent
6a945294e3
commit
ad7e4817e1
|
@ -8,6 +8,7 @@ fi
|
|||
|
||||
COMMITISH=$1
|
||||
DIRTY_TAG=""
|
||||
EXACT=0
|
||||
|
||||
# Figure out if the worktree is dirty, we run update-index first
|
||||
# as we've seen cases in Travis where not doing so causes git to
|
||||
|
@ -19,7 +20,34 @@ fi
|
|||
|
||||
# If we have an exact tag, just use it.
|
||||
if git describe --tags --exact-match "${COMMITISH}" >/dev/null 2>&1; then
|
||||
echo -n "$(git describe --tags --exact-match "${COMMITISH}")"
|
||||
EXACT=1
|
||||
TAG=$(git describe --tags --exact-match "${COMMITISH}")
|
||||
# Otherwise, increment the minor version version (if the package is 1.X or later) or the
|
||||
# patch version (if the package is pre 1.0), add the -alpha tag and some
|
||||
# commit metadata. If there's no existing tag, pretend a v0.0.0 was
|
||||
# there so we'll produce v0.0.1-dev builds.
|
||||
elif git describe --tags --abbrev=0 "${COMMITISH}" > /dev/null 2>&1; then
|
||||
TAG=$(git describe --tags --abbrev=0 "${COMMITISH}")
|
||||
else
|
||||
TAG="v0.0.0"
|
||||
fi
|
||||
|
||||
# Check to see if the latest tag is for a submodule and transform to semver tolerant
|
||||
# e.g: submodule/submodule/.../v.X.X.X
|
||||
# sdk/v1.1.1 -> v1.1.1
|
||||
IFS='/'
|
||||
read -a tagsplit <<< "${TAG}"
|
||||
|
||||
if echo "${#tagsplit[@]}" > /dev/null 2>&1 -gt 1;
|
||||
then
|
||||
TAG=${tagsplit[${#tagsplit[@]}-1]}
|
||||
fi
|
||||
|
||||
# if we found an exact match, return it at this point
|
||||
# after we have removed any submodule prefixes.
|
||||
if [ $EXACT -eq 1 ]
|
||||
then
|
||||
echo -n "${TAG}"
|
||||
if [ ! -z "${DIRTY_TAG}" ]; then
|
||||
echo -n "+${DIRTY_TAG}"
|
||||
fi
|
||||
|
@ -28,16 +56,6 @@ if git describe --tags --exact-match "${COMMITISH}" >/dev/null 2>&1; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# Otherwise, increment the minor version version (if the package is 1.X or later) or the
|
||||
# patch version (if the package is pre 1.0), add the -alpha tag and some
|
||||
# commit metadata. If there's no existing tag, pretend a v0.0.0 was
|
||||
# there so we'll produce v0.0.1-dev builds.
|
||||
if git describe --tags --abbrev=0 "${COMMITISH}" > /dev/null 2>&1; then
|
||||
TAG=$(git describe --tags --abbrev=0 "${COMMITISH}")
|
||||
else
|
||||
TAG="v0.0.0"
|
||||
fi
|
||||
|
||||
# Strip off any pre-release tag we might have (e.g. from doing a -rc build)
|
||||
TAG=${TAG%%-*}
|
||||
|
||||
|
|
|
@ -9,10 +9,15 @@ $dirty=($LASTEXITCODE -ne 0)
|
|||
try {
|
||||
git describe --tags --exact-match >$null 2>$null
|
||||
# If we get here the above did not throw, so we can use the exact tag
|
||||
$tag = "$(git describe --tags --exact-match)"
|
||||
# Remove any sub-module prefixes
|
||||
if ($tag.LastIndexOf("/") -ne -1) {
|
||||
$tag=$tag.Substring($tag.LastIndexOf("/")+1)
|
||||
}
|
||||
if ($dirty) {
|
||||
Write-Output "$(git describe --tags --exact-match)+dirty"
|
||||
Write-Output "$tag+dirty"
|
||||
} else {
|
||||
Write-Output "$(git describe --tags --exact-match)"
|
||||
Write-Output "$tag"
|
||||
}
|
||||
} catch {
|
||||
# Otherwise, take the existing tag, increment the patch version and append the timestamp of the commit and hash
|
||||
|
@ -25,6 +30,11 @@ try {
|
|||
$tag="v0.0.0"
|
||||
}
|
||||
|
||||
# Remove any sub-module prefixes
|
||||
if ($tag.LastIndexOf("/") -ne -1) {
|
||||
$tag=$tag.Substring($tag.LastIndexOf("/")+1)
|
||||
}
|
||||
|
||||
# Remove any pre-release tag
|
||||
if ($tag.LastIndexOf("-") -ne -1) {
|
||||
$tag=$tag.Substring(0, $tag.LastIndexOf("-"))
|
||||
|
|
Loading…
Reference in a new issue