Skip to content

Commit

Permalink
testsuite: add script for finding the previous release tag
Browse files Browse the repository at this point in the history
Change-Id: I744f33dc14fc195b82a0b502277d7ce9f10e0fca
  • Loading branch information
egonelbre authored and andriikotko committed Mar 15, 2024
1 parent 0edef4e commit a11998d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions testsuite/find-previous-major-release-tag.sh
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
34 changes: 34 additions & 0 deletions testsuite/find-previous-release-tag.sh
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

0 comments on commit a11998d

Please sign in to comment.