Skip to content

Commit 3cef5b8

Browse files
committed
Fix ghe-host-check unsupported version test by sorting supported versions
1 parent bec5f58 commit 3cef5b8

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

test/test-ghe-host-check.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,30 @@ begin_test "ghe-host-check detects unsupported GitHub Enterprise Server versions
6363
# Use the modified releases string as needed
6464
supported=$(echo "$releases_with_replacement" | jq -r 'select(."'${bu_major_minor}'")')
6565
# shellcheck disable=SC2207 # Command required as alternatives fail
66-
keys=($(echo "$releases_with_replacement" | jq -r 'keys[]'))
66+
keys=($(echo "$releases_with_replacement" | jq -r '. | keys_unsorted | sort_by( split(".") | map(tonumber) )[]'))
6767

6868
if [ -z "$supported" ]
6969
then
7070
#BACKUP_UTILS_VERSION WAS NOT FOUND IN LATEST.JSON, CHECK IF ITS GREATER THAN LAST VERSION
71-
if [ "$(version $bu_major_minor)" -ge "$(version ${keys[$((${#keys[@]}))]})" ]; then
71+
if [ "$(version $bu_major_minor)" -ge "$(version ${keys[-1]})" ]; then
7272
GHE_TEST_REMOTE_VERSION="$bu_major_minor.0" ghe-host-check
73-
GHE_TEST_REMOTE_VERSION="${keys[$(( ${#keys[@]}))]}.0" ghe-host-check
74-
GHE_TEST_REMOTE_VERSION="${keys[$(( ${#keys[@]} - 1 ))]}.0" ghe-host-check
73+
# Test most recent 2 versions
74+
GHE_TEST_REMOTE_VERSION="${keys[-1]}.0" ghe-host-check
75+
GHE_TEST_REMOTE_VERSION="${keys[-2]}.0" ghe-host-check
7576
fi
7677
else
7778
#BACKUP_UTILS_VERSION WAS FOUND IN LATEST.JSON
7879
ix=0
79-
for i in "${keys[@]}";do
80+
for i in "${keys[@]}";do
8081
if [ "$i" == "$bu_major_minor" ];then
8182
break
8283
fi
8384
ix=$(( $ix + 1 ))
8485
done
8586
GHE_TEST_REMOTE_VERSION="${keys[$ix]}.0" ghe-host-check
86-
# sometimes when the latest.json is updated during a release this test gets broken.
87-
if [ "${keys[$(( $ix - 1 ))]}" != "latest" ]; then
88-
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 1 ))]}.0" ghe-host-check
89-
fi
87+
# Test previous 2 supported versions
88+
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 1 ))]}.0" ghe-host-check
9089
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 2 ))]}.0" ghe-host-check
91-
9290
fi
9391
! GHE_TEST_REMOTE_VERSION=11.340.36 ghe-host-check
9492
GHE_TEST_REMOTE_VERSION=$bu_version_major.$bu_version_minor.999 ghe-host-check

0 commit comments

Comments
 (0)