From 54236e5d7aa67cdc0a9d67ad34acba8180885dec Mon Sep 17 00:00:00 2001 From: Jsp <98713940+JspIIV@users.noreply.github.com> Date: Tue, 1 Sep 2026 10:28:44 +0300 Subject: [PATCH] fix(arcup): a release is newer than its own pre-release version_gt strips the pre-release tag from both arguments before comparing, so 0.3.0 and 0.3.0-rc.1 reduce to the same numbers, fall through every comparison and reach the final `return 1`. SemVer orders a release above any pre-release of the same version, so the answer should be true. The effect is on anyone running a pre-release of the installer. check_installer_up_to_date never tells them the release shipped, and update_arcup refuses to move: if ! version_gt "$remote_version" "$ARCUP_INSTALLER_VERSION"; then so `arcup --self-update` from 0.3.0-rc.1 to 0.3.0 reports it is already current. The existing tests cover the two cases that already worked and not this one. Keep the pre-release tags aside and, when major.minor.patch are equal, treat an empty tag as the higher precedence. Ordering two pre-releases of the same version is left alone, since no caller compares them. Installer version bumped per the note at the top of the script. --- arcup/arcup | 20 +++++++++++++++++++- arcup/test_arcup.sh | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arcup/arcup b/arcup/arcup index 3590cd36..9ba5f146 100755 --- a/arcup/arcup +++ b/arcup/arcup @@ -6,7 +6,7 @@ set -euo pipefail # NOTE: if you make modifications to this script, please increment the version number. # WARNING: the SemVer pattern: major.minor.patch must be followed as we use it to determine if the script is up to date. -ARCUP_INSTALLER_VERSION="0.2.0" +ARCUP_INSTALLER_VERSION="0.2.1" REPO="${ARC_REPO:-circlefin/arc-node}" if [[ -n "${ARC_REPO:-}" ]] && [[ ! "$ARC_REPO" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then @@ -264,6 +264,17 @@ version_gt() { # Remove 'v' prefix if present local ver1="${1#v}" local ver2="${2#v}" + + # Keep the pre-release tags aside: SemVer orders a release above any + # pre-release of the same major.minor.patch. + local pre1="" pre2="" + if [[ "$ver1" == *-* ]]; then + pre1="${ver1#*-}" + fi + if [[ "$ver2" == *-* ]]; then + pre2="${ver2#*-}" + fi + ver1="${ver1%%-*}" ver2="${ver2%%-*}" @@ -281,6 +292,13 @@ EOF [ "$patch1" -gt "$patch2" ] && return 0 [ "$patch1" -lt "$patch2" ] && return 1 + # Same major.minor.patch. A release outranks a pre-release of it, so + # 0.3.0 is newer than 0.3.0-rc.1. Two pre-releases of the same version + # are not ordered here; no caller compares them. + if [ -z "$pre1" ] && [ -n "$pre2" ]; then + return 0 + fi + return 1 } diff --git a/arcup/test_arcup.sh b/arcup/test_arcup.sh index 49021191..75d528e8 100755 --- a/arcup/test_arcup.sh +++ b/arcup/test_arcup.sh @@ -64,6 +64,16 @@ test_version_comparison() { fail "same prerelease base is not newer" fi pass "same prerelease base is not newer" + + if ! version_gt "0.3.0" "0.3.0-rc.1"; then + fail "release is newer than its prerelease" + fi + pass "release is newer than its prerelease" + + if ! version_gt "v0.3.0" "v0.3.0-rc.2"; then + fail "release is newer than its prerelease with v prefix" + fi + pass "release is newer than its prerelease with v prefix" } test_target_mapping() {