Skip to content

Commit

Permalink
Add support for patch versions of Bazel (e.g. 1.2.3-patch4) (bazelb…
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre authored Dec 8, 2021
1 parent d4aef0a commit 6183822
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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]+)$`)
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

0 comments on commit 6183822

Please sign in to comment.