-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testsuite: add script for finding the previous release tag
Change-Id: I744f33dc14fc195b82a0b502277d7ce9f10e0fca
- Loading branch information
1 parent
0edef4e
commit a11998d
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
set -ueo pipefail | ||
|
||
# This script finds the previous major tag from the current HEAD position. | ||
|
||
closestHeadVersion="$(git describe --tags)" | ||
|
||
sortedTags="$(git tag --list --sort -version:refname)" | ||
|
||
verlte() { | ||
# sort and get the first result | ||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | ||
} | ||
verlt() { | ||
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
} | ||
|
||
closestZeroVersion="$(echo $closestHeadVersion | cut -d '.' -f 1-2).0" | ||
|
||
IFS=$'\n' | ||
for tag in $sortedTags | ||
do | ||
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
# it's not a proper version so ignore | ||
continue | ||
fi | ||
|
||
# the first less than our closest head should be our latest version | ||
if verlt $tag $closestZeroVersion; then | ||
echo $tag | ||
exit 0 | ||
fi | ||
done | ||
|
||
echo "did not find an appropriate release tag" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
set -ueo pipefail | ||
|
||
# This script finds the previous tag from the current HEAD position. | ||
|
||
closestHeadVersion="$(git describe --tags)" | ||
|
||
sortedTags="$(git tag --list --sort -version:refname)" | ||
|
||
verlte() { | ||
# sort and get the first result | ||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | ||
} | ||
verlt() { | ||
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | ||
} | ||
|
||
IFS=$'\n' | ||
for tag in $sortedTags | ||
do | ||
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
# it's not a proper version so ignore | ||
continue | ||
fi | ||
|
||
# the first less than our closest head should be our latest version | ||
if verlt $tag $closestHeadVersion; then | ||
echo $tag | ||
exit 0 | ||
fi | ||
done | ||
|
||
echo "did not find an appropriate release tag" | ||
exit 1 |