Skip to content

Commit

Permalink
testsuite/: fix finding previous versions in non-latest branches
Browse files Browse the repository at this point in the history
Change-Id: I044504b816c9e2d8cacb08b481ec4b1df8b0330c
  • Loading branch information
egonelbre committed Mar 11, 2024
1 parent 3166506 commit 99f2f6b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
9 changes: 5 additions & 4 deletions testsuite/backward-compatibility/start-sim.sh
Expand Up @@ -66,8 +66,11 @@ install_sim_noquic(){
# and for the current branch code
git worktree add -f "$BRANCH_DIR" HEAD

latestReleaseCommit="$(git rev-list --exclude='*rc*' --tags --max-count=1)"
latestReleaseTag=$(git describe --tags "$latestReleaseCommit")
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

latestReleaseTag=$($SCRIPTDIR/../find-previous-release-tag.sh)
latestReleaseCommit=$(git rev-list -n1 $latestReleaseTag)

echo "Checking out latest release tag: $latestReleaseTag"
git worktree add -f "$RELEASE_DIR" "$latestReleaseCommit"

Expand All @@ -82,8 +85,6 @@ cat > "$RELEASE_DIR"/private/version/release.go <<EOF
package version
EOF

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

pushd $RELEASE_DIR
install_sim_noquic "$RELEASE_DIR"/bin
popd
Expand Down
6 changes: 4 additions & 2 deletions testsuite/backward-compatibility/start-up.sh
Expand Up @@ -37,8 +37,10 @@ RELEASE_BIN="$STORJ_NETWORK_DIR/bin/release"
# replace this with a standard go install once go allows install cross-compiled binaries when GOBIN is set
# https://github.com/golang/go/issues/57485
git worktree add -f "$STORJ_NETWORK_DIR"/branch HEAD
latestReleaseCommit="$(git rev-list --exclude='*rc*' --tags --max-count=1)"
latestReleaseTag=$(git describe --tags "$latestReleaseCommit")

latestReleaseTag=$($SCRIPTDIR/../find-previous-release-tag.sh)
latestReleaseCommit=$(git rev-list -n1 $latestReleaseTag)

echo "Checking out latest release tag: $latestReleaseTag"
git worktree add -f "$STORJ_NETWORK_DIR"/release "$latestReleaseCommit"
pushd "$STORJ_NETWORK_DIR"/release
Expand Down
34 changes: 25 additions & 9 deletions testsuite/find-previous-major-release-tag.sh
@@ -1,12 +1,6 @@
#!/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`" ]
Expand All @@ -15,18 +9,40 @@ verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}

closestZeroVersion="$(echo $closestHeadVersion | cut -d '.' -f 1-2).0"
# This script finds the previous major tag from the current HEAD position.

closest_head_version="$(git describe --tags)"

sorted_tags="$(git tag --list --sort -version:refname)"

# this is ugly, but we use this approach to detect whether we are
# on a main branch, if that's the case, then we'll output the
# latest release version.
if [[ $closest_head_version =~ ^v1\.91\.0\-alpha ]]; then
for tag in $sorted_tags
do
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo $tag
exit 0
fi
done

echo "did not find an appropriate release tag from main branch"
exit 1
fi

closest_zero_version="$(echo $closest_head_version | cut -d '.' -f 1-2).0"

IFS=$'\n'
for tag in $sortedTags
for tag in $sorted_tags
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
if verlt $tag $closest_zero_version; then
echo $tag
exit 0
fi
Expand Down
49 changes: 31 additions & 18 deletions testsuite/find-previous-release-tag.sh
@@ -1,32 +1,45 @@
#!/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)"
set -uo pipefail

verlte() {
# sort and get the first result
# sort and check against the first result
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}

# This script finds the previous tag from the current HEAD position.

closest_head_version="$(git describe --tags)"

sorted_tags="$(git tag --list --sort -version:refname)"

# this is ugly, but we use this approach to detect whether we are
# on a main branch, if that's the case, then we'll output the
# latest release version.
if [[ $closest_head_version =~ ^v1\.91\.0\-alpha ]]; then
for tag in $sorted_tags
do
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo $tag
exit 0
fi
done

echo "did not find an appropriate release tag from main branch"
exit 1
fi

IFS=$'\n'
for tag in $sortedTags
for tag in $sorted_tags
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
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# the first less than our closest head should be our latest version
if verlt $tag $closest_head_version; then
echo $tag
exit 0
fi
fi
done

Expand Down
4 changes: 1 addition & 3 deletions testsuite/rolling-upgrade/start-sim.sh
Expand Up @@ -54,9 +54,7 @@ git fetch --tags
current_commit=$(git rev-parse HEAD)
stage1_release_version=$(git tag -l --sort -version:refname | grep -v rc | head -1)
if [[ $BRANCH_NAME = v* ]]; then
current_major_release_version=$(git describe --tags $current_commit | cut -d '.' -f 1-2)
previous_release_version=$(git describe --tags `git rev-list --exclude='*rc*' --exclude=$current_major_release_version* --tags --max-count=1`)
stage1_release_version=$previous_release_version
stage1_release_version=$($SCRIPTDIR/../find-previous-major-release-tag.sh)
fi
stage1_sat_version=$stage1_release_version
stage1_uplink_version=$stage1_release_version
Expand Down

0 comments on commit 99f2f6b

Please sign in to comment.