From 01cff4c438ae44e34c8ce115aa705f9051fcafb0 Mon Sep 17 00:00:00 2001 From: wllmshao Date: Thu, 13 Feb 2025 11:47:39 -0500 Subject: [PATCH] fix upgrade script to handle new format --- .../run_upgrade_commands.sh | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh b/contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh index 241e9afe634..c2e1b1a0185 100755 --- a/contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh +++ b/contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh @@ -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