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

Add support for patch versions of Bazel (e.g. 1.2.3-patch4) #280

Merged
merged 1 commit into from
Dec 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bazelisk_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,42 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func TestResolveVersion(t *testing.T) {
s := setUp(t)
s.AddVersion("4.0.0", false, nil, nil)
s.Finish()

gcs := &repositories.GCSRepo{}
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0")

if err != nil {
t.Fatalf("Version resolution failed unexpectedly: %v", err)
}
expectedRC := "4.0.0"
if version != expectedRC {
t.Fatalf("Expected version %s, but got %s", expectedRC, version)
}
}

func TestResolvePatchVersion(t *testing.T) {
s := setUp(t)
s.AddVersion("4.0.0-patch1", false, nil, nil)
s.Finish()

gcs := &repositories.GCSRepo{}
repos := core.CreateRepositories(nil, gcs, nil, nil, nil, false)
version, _, err := repos.ResolveVersion(tmpDir, versions.BazelUpstream, "4.0.0-patch1")

if err != nil {
t.Fatalf("Version resolution failed unexpectedly: %v", err)
}
expectedRC := "4.0.0-patch1"
if version != expectedRC {
t.Fatalf("Expected version %s, but got %s", expectedRC, version)
}
}

func TestResolveLatestRcVersion(t *testing.T) {
s := setUp(t)
s.AddVersion("4.0.0", false, nil, nil)
Expand Down
3 changes: 3 additions & 0 deletions versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (

var (
releasePattern = regexp.MustCompile(`^(\d+)\.(x|\d+\.\d+)$`)
patchPattern = regexp.MustCompile(`^(\d+\.\d+\.\d+)-([\w\d]+)$`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start with a more restrictive regex and then maybe loosen it later. what about ...-patch\d+
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricting it to just -patch would not satisfy my needs unfortunately 😞 Do you feel strongly that it should be restrictive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine as-is.

candidatePattern = regexp.MustCompile(`^(\d+\.\d+\.\d+)rc(\d+)$`)
rollingPattern = regexp.MustCompile(`^\d+\.0\.0-pre\.\d{8}(\.\d+){1,2}$`)
latestReleasePattern = regexp.MustCompile(`^latest(?:-(?P<offset>\d+))?$`)
Expand Down Expand Up @@ -45,6 +46,8 @@ func Parse(fork, version string) (*Info, error) {
vi.IsRelative = true
vi.TrackRestriction = track
}
} else if patchPattern.MatchString(version) {
vi.IsRelease = true
} else if m := latestReleasePattern.FindStringSubmatch(version); m != nil {
vi.IsRelease = true
vi.IsRelative = true
Expand Down