-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testsuite: more robust find-previous-release script
Fixes #6847 Change-Id: Ieba2959b233a8185f92b1bdc1a188d5fd074feb1
- Loading branch information
Showing
8 changed files
with
393 additions
and
109 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,117 @@ | ||
#!/usr/bin/env bash | ||
set -ueo pipefail | ||
|
||
find_major_release= | ||
if [[ "${1:-}" == "--major" || "${1:-}" == "-major" ]]; then | ||
find_major_release=1 | ||
fi | ||
|
||
debug= | ||
minimum_checked_version="v1.50.0" | ||
|
||
trace() { | ||
if [ $debug ]; then | ||
>&2 echo "$1" | ||
fi | ||
} | ||
|
||
verlte() { | ||
# sort and check against the first result | ||
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | ||
} | ||
|
||
find_release_on_strand() { | ||
local query=$2 | ||
local furthest_ancestor=$3 | ||
local furthest_ancestor_hash=$(git rev-list -n 1 $furthest_ancestor) | ||
local main=${4:-""} | ||
|
||
trace " # find_release_on_strand $query $furthest_ancestor $main" | ||
|
||
local query_tag=$(git describe --tags --exact-match $query 2> /dev/null) | ||
local query_parent_tag=$(git describe --tags --exact-match "$query^" 2> /dev/null) | ||
|
||
trace " # current $query_tag:$query_parent_tag" | ||
|
||
for tag in $(git tag --list --sort -version:refname) | ||
do | ||
# trace " # checking out $tag" | ||
# Check whether it's a proper version, if it's not then skip. | ||
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
# trace " # skipping $tag because it is not a proper release" | ||
continue | ||
fi | ||
|
||
if verlte "$tag" "$minimum_checked_version"; then | ||
# trace " # skipping $tag because it is a really old release" | ||
continue | ||
fi | ||
|
||
# We want to exclude tags that are not descendants of furthest_ancestor. | ||
if ! git merge-base --is-ancestor $furthest_ancestor $tag; then | ||
trace " # skipping $tag because $query is furthest ancestor of $tag" | ||
continue | ||
fi | ||
|
||
# We want to exclude tags that are descendants of query. | ||
if git merge-base --is-ancestor $query $tag; then | ||
trace " # skipping $tag because $query is parent of $tag" | ||
continue | ||
fi | ||
|
||
# We want to exclude tags that are descendants of query's parent, if | ||
# the query is tagged and the query's parent is not tagged. this is the | ||
# special case for scripts/tag-release.sh tagging behavior. | ||
|
||
if [ "$query_tag" ]; then | ||
if ! [ "$query_parent_tag" ]; then | ||
if git merge-base --is-ancestor "$query^" $tag; then | ||
trace " # skipping $tag because $query is tag-release special case" | ||
continue | ||
fi | ||
fi | ||
fi | ||
|
||
if [ "$main" ]; then | ||
# I we are not yet evaluating the main branch, we want to exclude tags | ||
# that branched off the main branch later than we did. | ||
tag_branching_point=$(git merge-base $main $tag) | ||
if [ $tag_branching_point != $furthest_ancestor_hash ]; then | ||
if git merge-base --is-ancestor $furthest_ancestor $tag_branching_point; then | ||
trace " # skipping $tag because it branched off from main later than $query" | ||
continue | ||
fi | ||
fi | ||
fi | ||
|
||
eval "$1=\$tag" | ||
return 0 | ||
done | ||
} | ||
|
||
main="main" | ||
if ! git rev-parse --verify $main; then | ||
main=remotes/origin/main | ||
fi | ||
|
||
query="HEAD" | ||
if [[ $find_major_release ]]; then | ||
query=$(git merge-base $main HEAD) | ||
fi | ||
|
||
release="" | ||
find_release_on_strand release $query $(git merge-base $main $query) $main | ||
if [ "$release" ]; then | ||
echo "$release" | ||
exit 0 | ||
fi | ||
|
||
root=$(git rev-list --max-parents=0 $query) | ||
find_release_on_strand release $(git merge-base $main $query) $root "" | ||
if [ "$release" ]; then | ||
echo "$release" | ||
exit 0 | ||
fi | ||
|
||
echo "did not find appropriate previous 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,145 @@ | ||
#!/usr/bin/env bash | ||
set -ueo pipefail | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX) | ||
cleanup() { | ||
rm -rf "$TMPDIR" | ||
} | ||
trap cleanup EXIT INT | ||
|
||
cd $TMPDIR | ||
|
||
# Create the testing git repo. | ||
|
||
commit() { | ||
from=$1 | ||
to=$2 | ||
tag=${3:-""} | ||
|
||
git checkout -q $from | ||
git checkout -b $to | ||
git commit --allow-empty -m"$from -> $to [$tag]" | ||
|
||
if [ "$tag" ]; then | ||
git tag $3 | ||
fi | ||
} | ||
|
||
git -c init.defaultBranch=main -c user.name="User" -c user.email="user@test" init . | ||
git config user.name "User" | ||
git config user.email "user@test" | ||
git config advice.detachedHead false | ||
git commit --allow-empty -m"R" | ||
|
||
# COMMIT GRAPH UNDER TEST | ||
# | ||
# _ v1.98.0-rc - v1.98.0 - m2c - v1.98.1 - m2e - v1.98.2 | ||
# / | ||
# R - m0[v1.97.0] - m1 - m2 - m3 - m4 - m5 - m6 - m7 - m8[main] | ||
# \ \ \ | ||
# \ - x - v1.99.0-rc - v1.99.0 - v1.99.1 | ||
# \ \ | ||
# \- v1.97.1 - v1.97.2 - y | ||
|
||
commit main m0 v1.97.0 | ||
|
||
commit m0 m1 | ||
commit m1 m2 | ||
commit m2 m3 | ||
commit m3 m4 | ||
commit m4 m5 | ||
commit m5 m6 | ||
commit m6 m7 | ||
commit m7 m8 | ||
|
||
commit m0 m0a v1.97.1 | ||
commit m0a m0b v1.97.2 | ||
|
||
commit m2 m2a v1.98.0-rc | ||
commit m2a m2b v1.98.0 | ||
commit m2b m2c | ||
commit m2c m2d v1.98.1 | ||
commit m2d m2e | ||
commit m2e m2f v1.98.2 | ||
|
||
commit m3 x | ||
|
||
commit m6 m6a v1.99.0-rc | ||
commit m6a m6b v1.99.0 | ||
commit m6b m6c v1.99.1 | ||
|
||
commit m6a y | ||
|
||
git checkout -q main | ||
git reset --hard m8 | ||
|
||
# Do the testing stuff. | ||
|
||
check() { | ||
echo "checking at '$1' expecting '$2'" | ||
|
||
git checkout -q $1 | ||
got=$($SCRIPTDIR/find-previous-release.sh || true) | ||
|
||
if [[ $got != $2 ]]; | ||
then | ||
echo " FAILED got '$got'" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_major() { | ||
echo "checking -major at '$1' expecting '$2'" | ||
|
||
git checkout -q $1 | ||
got=$($SCRIPTDIR/find-previous-release.sh --major || true) | ||
|
||
if [[ $got != $2 ]]; | ||
then | ||
echo " FAILED got '$got'" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check main v1.99.1 | ||
check m7 v1.99.1 | ||
|
||
check v1.99.1 v1.99.0 | ||
check v1.99.0-rc v1.98.2 | ||
check v1.99.0 v1.98.2 | ||
check y v1.99.1 | ||
|
||
check m6 v1.98.2 | ||
check m5 v1.98.2 | ||
check m4 v1.98.2 | ||
check m3 v1.98.2 | ||
check x v1.98.2 | ||
|
||
check v1.98.2 v1.98.1 | ||
check m2e v1.98.1 | ||
check v1.98.1 v1.98.0 | ||
check m2c v1.98.0 | ||
check v1.98.0 v1.97.2 | ||
check v1.98.0-rc v1.97.2 | ||
|
||
check m2 v1.97.2 | ||
check m1 v1.97.2 | ||
|
||
check v1.97.2 v1.97.1 | ||
check v1.97.1 v1.97.0 | ||
|
||
check_major v1.99.1 v1.98.2 | ||
check_major v1.99.0-rc v1.98.2 | ||
check_major v1.99.0 v1.98.2 | ||
|
||
check_major v1.98.2 v1.97.2 | ||
check_major v1.98.1 v1.97.2 | ||
check_major v1.98.0 v1.97.2 | ||
|
||
check v1.97.0 "did not find appropriate previous release tag" | ||
check m0 "did not find appropriate previous release tag" | ||
|
||
check_major v1.97.0 "did not find appropriate previous release tag" | ||
|
||
echo "SUCCESS" |
Oops, something went wrong.