Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move upgradeable check to using semVer/pre #1110

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 latestSemVer.Compare(currentSemVer) == 1 && latestSemVer.Prerelease() == currentSemVer.Prerelease()

}
48 changes: 48 additions & 0 deletions cmd/chart/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,60 @@ 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",
latest: "1.0.0",
expected: false,
},
{
title: "both are rootless different version'",
current: "1.0.0-rootless",
latest: "1.0.1-rootless",
expected: true,
},
{
title: "both are rootless same version'",
current: "1.0.0-rootless",
latest: "1.0.0-rootless",
expected: false,
},
{
title: "both are rc same version'",
current: "1.0.0-rc",
latest: "1.0.0-rc",
expected: false,
},
{
title: "both are rc different version'",
current: "1.0.0-rc",
latest: "1.0.1-rc",
expected: true,
},
{
title: "both are rc with suffix & same version'",
current: "1.0.0-rc1",
latest: "1.0.0-rc2",
expected: false,
},
{
title: "both are rc with suffix & different version'",
current: "1.0.0-rc1",
latest: "1.0.1-rc2",
expected: false,
},
}

for _, tc := range tests {
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
12 changes: 6 additions & 6 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5927,38 +5927,38 @@ func Test_DownloaClusterawsadm(t *testing.T) {

tool := getTool(name, tools)

const toolVersion = "v2.0.2"
const toolVersion = "v2.6.1"

tests := []test{
{
os: "linux",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.0.2/clusterawsadm_v2.0.2_linux_amd64`,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/clusterawsadm-linux-amd64`,
},
{
os: "darwin",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.0.2/clusterawsadm_v2.0.2_darwin_amd64`,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/clusterawsadm-darwin-amd64`,
},
{
os: "linux",
arch: archARM64,
version: toolVersion,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.0.2/clusterawsadm_v2.0.2_linux_arm64`,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/clusterawsadm-linux-arm64`,
},
{
os: "darwin",
arch: archDarwinARM64,
version: toolVersion,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.0.2/clusterawsadm_v2.0.2_darwin_arm64`,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/clusterawsadm-darwin-arm64`,
},
{
os: "ming",
arch: arch64bit,
version: toolVersion,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.0.2/clusterawsadm_v2.0.2_windows_amd64.exe`,
url: `https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.6.1/clusterawsadm-windows-amd64.exe`,
},
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3344,11 +3344,9 @@ https://github.com/{{.Owner}}/{{.Repo}}/releases/download/{{.Version}}/{{.Name}}
{{$ext = ".exe"}}
{{- end -}}

clusterawsadm_{{.Version}}_{{$os}}_{{$arch}}{{$ext}}
clusterawsadm-{{$os}}-{{$arch}}{{$ext}}
`,
})
// https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.5.0/clusterawsadm-v2.5.0-linux_amd64
// https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/v2.5.0/clusterawsadm_v2.5.0_linux_amd64
tools = append(tools,
Tool{
Owner: "schollz",
Expand Down