From 1e3e22456bd609e6f18d0b6ae6d6d8119dfa5ff6 Mon Sep 17 00:00:00 2001 From: AMF Date: Fri, 16 Sep 2022 13:19:30 +0600 Subject: [PATCH 1/3] fix: remove a patch number from the recommendation link --- pkg/commands/artifact/run.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/commands/artifact/run.go b/pkg/commands/artifact/run.go index 07addfc3ea1..539807884cd 100644 --- a/pkg/commands/artifact/run.go +++ b/pkg/commands/artifact/run.go @@ -3,6 +3,7 @@ package artifact import ( "context" "errors" + "fmt" "os" "github.com/hashicorp/go-multierror" @@ -564,7 +565,6 @@ func canonicalVersion(ver string) string { if v.IsPreRelease() || v.Metadata() != "" { return devVersion } - - // Add "v" prefix, "0.34.0" => "v0.34.0" for the url - return "v" + ver + // Add "v" prefix and cut a patch number, "0.34.0" => "v0.34" for the url + return fmt.Sprintf("v%d.%d", v.Major(), v.Minor()) } From 15f46fa724ae2b452fe17abecd5430e927e01634 Mon Sep 17 00:00:00 2001 From: AMF Date: Fri, 16 Sep 2022 14:00:13 +0600 Subject: [PATCH 2/3] add a test to clarify logic --- pkg/commands/artifact/run_test.go | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 pkg/commands/artifact/run_test.go diff --git a/pkg/commands/artifact/run_test.go b/pkg/commands/artifact/run_test.go new file mode 100644 index 00000000000..f40816fbe90 --- /dev/null +++ b/pkg/commands/artifact/run_test.go @@ -0,0 +1,48 @@ +package artifact + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCanonicalVersion(t *testing.T) { + tests := []struct { + title string + input string + want string + }{ + { + title: "good way", + input: "0.34.0", + want: "v0.34", + }, + { + title: "version with v", + input: "v0.34.0", + want: "v0.34", + }, + { + title: "dev version", + input: devVersion, + want: devVersion, + }, + { + title: "pre-release", + input: "v0.34.0-beta1+snapshot-1", + want: devVersion, + }, + { + title: "no version", + input: "", + want: devVersion, + }, + } + + for _, test := range tests { + t.Run(test.title, func(t *testing.T) { + got := canonicalVersion(test.input) + require.Equal(t, test.want, got) + }) + } +} From fc26b52e0b6f64bf203b438ec2a7d825152515dc Mon Sep 17 00:00:00 2001 From: AMF Date: Fri, 16 Sep 2022 14:04:56 +0600 Subject: [PATCH 3/3] fix a test with `v` in version --- pkg/commands/artifact/run_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/artifact/run_test.go b/pkg/commands/artifact/run_test.go index f40816fbe90..02d35a53d44 100644 --- a/pkg/commands/artifact/run_test.go +++ b/pkg/commands/artifact/run_test.go @@ -18,9 +18,9 @@ func TestCanonicalVersion(t *testing.T) { want: "v0.34", }, { - title: "version with v", + title: "version with v - isn't right semver version", input: "v0.34.0", - want: "v0.34", + want: devVersion, }, { title: "dev version",