Skip to content

Commit

Permalink
fix upgrade script to handle new format
Browse files Browse the repository at this point in the history
  • Loading branch information
wllmshao committed Feb 13, 2025
1 parent a039479 commit 01cff4c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@
set -o errexit -o nounset

UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0
UPGRADE_VERSION="v0"

version_gt() {
IFS='_' read -ra LEFT_PARTS <<< "${1#v}"
IFS='_' read -ra RIGHT_PARTS <<< "${2#v}"

for ((i=0; i < ${#LEFT_PARTS[@]} || i < ${#RIGHT_PARTS[@]}; i++)); do
LEFT_NUM=${LEFT_PARTS[i]:-0} # Default to 0 if missing
RIGHT_NUM=${RIGHT_PARTS[i]:-0} # Default to 0 if missing

if (( LEFT_NUM > RIGHT_NUM )); then
return 0 # Left is greater
elif (( LEFT_NUM < RIGHT_NUM )); then
return 1 # Right is greater
fi
done

return 1 # Equal versions, so not greater
}

for dir in "$UPGRADES_DIR"/*; do
if [ -d "$dir" ]; then
DIR_NAME=$(basename "$dir")
VERSION_NUMBER="${DIR_NAME#v}"
if [ "$VERSION_NUMBER" -gt "$UPGRADE_VERSION_NUMBER" ]; then
UPGRADE_VERSION_NUMBER=$VERSION_NUMBER

if version_gt "$DIR_NAME" "$UPGRADE_VERSION"; then
UPGRADE_VERSION="$DIR_NAME"
fi
fi
done

if [ -n "$UPGRADE_VERSION_NUMBER" ]; then
echo "Upgrade to version: $UPGRADE_VERSION_NUMBER"
else
echo "No upgrade version found in app/upgrades."
fi

UPGRADE_VERSION=v$UPGRADE_VERSION_NUMBER
UPGRADE_HEIGHT=$1

if [ -z "$1" ]; then
Expand Down

0 comments on commit 01cff4c

Please sign in to comment.