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

Relax parsing of go version #132

Merged
merged 1 commit into from
Feb 13, 2023
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
12 changes: 4 additions & 8 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ type Runner struct {
logger *log.Logger
}

var versionRegexp = regexp.MustCompile(`go?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?`)
var versionRegexp = regexp.MustCompile(`^go version.* go((?:[0-9]+)(?:\.[0-9]+)?(?:\.[0-9]+)?)`)

// parseGoVersion ignores pre-release identifiers immediately following the
// patch version since we don't expect goVersionOutput to be SemVer-compliant.
func parseGoVersion(goVersionOutput string) (*semver.Version, error) {
el := strings.Fields(strings.TrimRight(goVersionOutput, "\n"))
if len(el) < 2 {
goVersion := versionRegexp.FindStringSubmatch(goVersionOutput)
if goVersion == nil {
return nil, errors.Newf("unexpected go version output; expected 'go version go<semver> ...; found %v", strings.TrimRight(goVersionOutput, "\n"))
}
goVersion := versionRegexp.FindString(el[2])
if goVersion == "" {
return nil, errors.New("unexpected go version format")
}
return semver.NewVersion(strings.TrimPrefix(goVersion, "go"))
return semver.NewVersion(goVersion[1])
}

func isSupportedVersion(v *semver.Version) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestParseAndIsSupportedVersion(t *testing.T) {
{output: "go version go1.16rc1 linux/amd64"},
{output: "go version go2 linux/amd64"},
{output: "go version go2.1 linux/amd64"},
{output: "go version devel go1.21-02d8ebda83 Mon Feb 6 22:13:07 2023 +0000 linux/amd64"},
} {
t.Run(tcase.output, func(t *testing.T) {
errs := merrors.New()
Expand Down