Skip to content

Commit

Permalink
Move upgradeable check to using semVer/pre
Browse files Browse the repository at this point in the history
The number of tag version edge cases requiring exception from being upgraded
was increasing to the point where constantly adding to the exception list was
no longer a viable approach.

This change alters how the upgradability of a tag is assessed by parsing the
current and latest tags into SemVers and then assessing the `pre` field of the
version to determine whether either of the tags are a special case.  In order
to achieve this it is necessary to move `latest` out to be a case all of itself
as this would not be nicely handled by NewVersion().

Signed-off-by: Richard Gee <richard@technologee.co.uk>
  • Loading branch information
rgee0 committed Aug 8, 2024
1 parent 73ca223 commit 7396123
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/chart/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ func updateImages(iName string, v bool) (bool, string, error) {

func tagIsUpgradeable(currentTag, latestTag string) bool {

return latestTag != currentTag && !strings.Contains(strings.ToLower(latestTag), "-rc") && !strings.EqualFold(currentTag, "latest")
if strings.EqualFold(currentTag, "latest") {
return false
}

currentSemVer, _ := semver.NewVersion(currentTag)
latestSemVer, _ := semver.NewVersion(latestTag)

return latestTag != currentTag && len(latestSemVer.Prerelease()) == 0 && len(currentSemVer.Prerelease()) == 0

}
12 changes: 12 additions & 0 deletions cmd/chart/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ func Test_tagIsUpgradable(t *testing.T) {
latest: "1.0.0-rc",
expected: false,
},
{
title: "current is rootless",
current: "1.0.0-rootless",
latest: "1.1.0",
expected: false,
},
{
title: "latest is rootless",
current: "1.0.0",
latest: "1.1.0-rootless",
expected: false,
},
{
title: "current is 'latest'",
current: "latest",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/alexellis/arkade

go 1.22
go 1.22.0

require (
github.com/Masterminds/semver v1.5.0
Expand Down

0 comments on commit 7396123

Please sign in to comment.