Skip to content

Commit

Permalink
cmd/atlas: support canary version (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonidavidson authored Jan 20, 2022
1 parent 6539f27 commit 4f30b53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/action/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package action

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"golang.org/x/mod/semver"
Expand All @@ -27,7 +28,12 @@ func init() {
// parse returns a user facing version and release notes url
func parse(version string) (string, string) {
if ok := semver.IsValid(version); !ok {
return "- development", "https://github.com/ariga/atlas/releases/tag/latest"
v := "- development"
s := strings.Split(version, "_")
if len(s) != 0 && s[len(s)-1] == "canary" {
v = version
}
return v, "https://github.com/ariga/atlas/releases/tag/latest"
}
return version, fmt.Sprintf("https://github.com/ariga/atlas/releases/tag/%s", version)
}
10 changes: 10 additions & 0 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ func TestCLI_Version(t *testing.T) {
),
expected: "atlas CLI version v1.2.3\nhttps://github.com/ariga/atlas/releases/tag/v1.2.3\n",
},
{
name: "canary",
cmd: exec.Command("go", "run",
"-ldflags",
"-X ariga.io/atlas/cmd/action.version=v0.3.0_6539f2704b5d_canary",
"ariga.io/atlas/cmd/atlas",
"version",
),
expected: "atlas CLI version v0.3.0_6539f2704b5d_canary\nhttps://github.com/ariga/atlas/releases/tag/latest\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 4f30b53

Please sign in to comment.