Skip to content

Commit

Permalink
Discard releases when reading candidates (#190)
Browse files Browse the repository at this point in the history
This commit fixes two related problems: when version equaled "last_rc", Bazelisk-Go would not discard release versions, and it would return the "release" suffix as part of the version label.

Fixes #189
  • Loading branch information
fweikert authored Oct 23, 2020
1 parent dba981e commit 3b5aa44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 18 additions & 0 deletions bazelisk_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ func TestResolveLatestRcVersion(t *testing.T) {
}
}

func TestResolveLatestRcVersion_WithFullRelease(t *testing.T) {
s := setUp(t)
s.AddVersion("4.0.0", true, 1, 2, 3)
s.Finish()

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

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

func TestResolveLatestVersion_TwoLatestVersionsDoNotHaveAReleaseYet(t *testing.T) {
s := setUp(t)
s.AddVersion("4.0.0", true)
Expand Down
12 changes: 10 additions & 2 deletions repositories/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func listDirectoriesInReleaseBucket(prefix string) ([]string, bool, error) {
func getVersionsFromGCSPrefixes(versions []string) []string {
result := make([]string, len(versions))
for i, v := range versions {
result[i] = strings.ReplaceAll(v, "/", "")
noSlashes := strings.ReplaceAll(v, "/", "")
result[i] = strings.TrimSuffix(noSlashes, "release")
}
return result
}
Expand Down Expand Up @@ -163,7 +164,14 @@ func (gcs *GCSRepo) GetCandidateVersions(bazeliskHome string) ([]string, error)
return []string{}, fmt.Errorf("could not list release candidates for latest release: %v", err)
}

return getVersionsFromGCSPrefixes(rcPrefixes), nil
rcs := make([]string, 0)
for _, v := range getVersionsFromGCSPrefixes(rcPrefixes) {
// Remove full releases
if strings.Contains(v, "rc") {
rcs = append(rcs, v)
}
}
return rcs, nil
}

// DownloadCandidate downloads the given release candidate into the specified location and returns the absolute path.
Expand Down

0 comments on commit 3b5aa44

Please sign in to comment.