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

Test whether version.txt contains semantic version #871

Merged
merged 1 commit into from Dec 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions internal/cmd/cmd_version.go
Expand Up @@ -14,12 +14,9 @@ var CmdVersion = &Cmd{
Args: []string{"[VERSION_AT_LEAST]"},
Aliases: []string{"--version"},
Action: actionSimple(func(env Env, args []string) error {
semVersion := "v" + version
semVersion := ensureVPrefixed(version)
if len(args) > 1 {
atLeast := args[1]
if !strings.HasPrefix(atLeast, "v") {
atLeast = "v" + atLeast
}
atLeast := ensureVPrefixed(args[1])
if !semver.IsValid(atLeast) {
return fmt.Errorf("%s is not a valid semver version", atLeast)
}
Expand All @@ -33,3 +30,10 @@ var CmdVersion = &Cmd{
return nil
}),
}

func ensureVPrefixed(version string) string {
if !strings.HasPrefix(version, "v") {
return "v" + version
}
return version
}
15 changes: 15 additions & 0 deletions internal/cmd/cmd_version_test.go
@@ -0,0 +1,15 @@
package cmd

import (
"golang.org/x/mod/semver"
"io/ioutil"
"testing"
)

func TestVersionDotTxt(t *testing.T) {
version, _ := ioutil.ReadFile("../../version.txt")

if !semver.IsValid(ensureVPrefixed(string(version))) {
t.Fatalf(`version.txt does not contain a valid semantic version: %q`, version)
}
}
2 changes: 1 addition & 1 deletion version.txt
@@ -1 +1 @@
2.30.2
2.30.2