openhab-distro icon indicating copy to clipboard operation
openhab-distro copied to clipboard

Windows update script fails to account for milestone builds in current version check

Open j-vaughn opened this issue 2 years ago • 1 comments

When the current version of OpenHAB is a milestone build, the milestone is not added back to to the concatenation of the reconstructed $CurrentVersion. This causes the script to prompt for reinstallation vs updating if you're updating from the x.y.z.M1 build to the x.y.z build.

image

This example is taken from 3.2.0.M1 with the following version.properties

openHAB Distribution Version Information
----------------------------------------
build-no        : Milestone Build
online-repo     : https://openhab.jfrog.io/openhab/libs-milestone

Repository        Version
----------------------------------------
openhab-distro  : 3.2.0.M1
openhab-core    : 3.2.0.M1
openhab-addons  : 3.2.0.M1
karaf           : 4.3.2

https://github.com/openhab/openhab-distro/blob/557b8205aa5ebe179d170e757740406ab90f0510/distributions/openhab/src/main/resources/bin/update.ps1#L404

    if ($parts[2].EndsWith("-SNAPSHOT", "CurrentCultureIgnoreCase")) {
        $CurrentVersion = $parts[0] + "." + $parts[1] + "." + $parts[2].Substring(0, $parts[2].Length - "-SNAPSHOT".Length);
    }
    else {
        $CurrentVersion = $parts[0] + "." + $parts[1] + "." + $parts[2]
    }
    Write-Host -ForegroundColor Yellow "The current version is $CurrentVersion" 

j-vaughn avatar Jun 10 '22 13:06 j-vaughn

I modified the concatenation of CurrentVersion to include the milestone:

    if ($parts[2].EndsWith("-SNAPSHOT", "CurrentCultureIgnoreCase")) {
        $CurrentVersion = $parts[0] + "." + $parts[1] + "." + $parts[2].Substring(0, $parts[2].Length - "-SNAPSHOT".Length);
    }
    else {
        $CurrentVersion = $parts[0] + "." + $parts[1] + "." + $parts[2]
        if($parts.length -eq 4) {
		$CurrentVersion = $CurrentVersion + "." + $parts[3]
	}
    }
    Write-Host -ForegroundColor Yellow "The current version is $CurrentVersion"   

The addition of the milestone to the CurrentVersion variable results in NormalizeVersionNumber rejecting it for not being 3 parts

$parts = $VersionNumber.Split(".")
if ($parts.Length -eq 2) {
    $parts += "0"
}
if ($parts.Length -ne 3) {
    throw "$VersionNumber is not formatted correctly (d.d.d)"
}

Modifying this (probably impacts other parts of the script yet to be seen) to be if( -not ($parts.Length -eq 3 -or $parts.Length -eq 4) gets the script to progress and the script now prompts for a downgrade due to "3.2.0" -lt "3.2.0.M1" being $True. Proceeding with the "downgrade" is successful and upgraded 3.2.0.M1 to 3.2.0.

I went back and looked and it appears the reinstallation warning ("Current version is equal to specified version ($OHVersionName). If you continue, you will REINSTALL $OHVersionName rather than upgrade.") is just a warning and actually has no impact. This made me think the way forward would be to just proceed as a "reinstallation" without all of the other modifications above, but there are other implications (such as the temporary backup being stored as 3.2.0 instead of 3.2.0.M1 which seem less than ideal)

j-vaughn avatar Jun 10 '22 14:06 j-vaughn