Skip to content

Commit

Permalink
Support last_downstream_green Bazel binary. (bazelbuild#45)
Browse files Browse the repository at this point in the history
* Support last_downstream_green Bazel binary.

This commit modifies both Bazelisk implementations to support the
"last_downstream_green" version identifier, which refers to a Bazel
binary built at the most recent commit that passed the downstream
pipeline on CI (https://buildkite.com/bazel/bazel-at-head-plus-downstream).

Part of bazelbuild/continuous-integration#583.

* Fix wrong handling of slashes.

* Slash fix, part 2.

* Add test for last_downstream_green
  • Loading branch information
fweikert authored and philwo committed Apr 3, 2019
1 parent de217bc commit c6a1dcb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Bazelisk currently understands the following formats for version labels:
- A version number like `0.17.2` means that exact version of Bazel. It can also
be a release candidate version like `0.20.0rc3`.
- `last_green` refers to the Bazel binary that was built at the most recent commit that passed [Bazel CI](https://buildkite.com/bazel/bazel-bazel). Ideally this binary should be very close to Bazel-at-head.
- `last_downstream_green` points to the most recent Bazel binary that builds and tests all [downstream projects](https://buildkite.com/bazel/bazel-at-head-plus-downstream) successfully.


In the future I will add support for release candidates and for building Bazel from source at a given commit.
Expand Down
11 changes: 7 additions & 4 deletions bazelisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ func resolveVersionLabel(bazeliskHome, bazelVersion string) (string, bool, error
// 1. The label of a Blaze release (if the label resolves to a release) or a commit (for unreleased binaries),
// 2. Whether the first value refers to a commit,
// 3. An error.
if bazelVersion == "last_green" {
commit, err := getLastGreenCommit()
lastGreenCommitPathSuffixes := map[string]string{"last_green": "github.com/bazelbuild/bazel.git/bazel-bazel", "last_downstream_green": "downstream_pipeline"}
if pathSuffix, ok := lastGreenCommitPathSuffixes[bazelVersion]; ok {
commit, err := getLastGreenCommit(pathSuffix)
if err != nil {
return "", false, fmt.Errorf("cannot resolve last green commit: %v", err)
}
Expand All @@ -197,8 +198,10 @@ func resolveVersionLabel(bazeliskHome, bazelVersion string) (string, bool, error
return bazelVersion, false, nil
}

func getLastGreenCommit() (string, error) {
content, err := readRemoteFile("https://storage.googleapis.com/bazel-untrusted-builds/last_green_commit/github.com/bazelbuild/bazel.git/bazel-bazel")
const lastGreenBasePath = "https://storage.googleapis.com/bazel-untrusted-builds/last_green_commit/"

func getLastGreenCommit(pathSuffix string) (string, error) {
content, err := readRemoteFile(lastGreenBasePath + pathSuffix)
if err != nil {
return "", fmt.Errorf("could not determine last green commit: %v", err)
}
Expand Down
13 changes: 8 additions & 5 deletions bazelisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

LATEST_PATTERN = re.compile(r"latest(-(?P<offset>\d+))?$")

LAST_GREEN_COMMIT_FILE = "https://storage.googleapis.com/bazel-untrusted-builds/last_green_commit/github.com/bazelbuild/bazel.git/bazel-bazel"
LAST_GREEN_COMMIT_BASE_PATH = "https://storage.googleapis.com/bazel-untrusted-builds/last_green_commit/"

LAST_GREEN_COMMIT_PATH_SUFFIXES = {"last_green" : "github.com/bazelbuild/bazel.git/bazel-bazel", "last_downstream_green" : "downstream_pipeline"}

BAZEL_GCS_PATH_PATTERN = (
"https://storage.googleapis.com/bazel-builds/artifacts/{platform}/{commit}/bazel"
Expand Down Expand Up @@ -91,8 +93,9 @@ def resolve_version_label_to_number_or_commit(bazelisk_directory, version):
of an unreleased Bazel binary,
2. An indicator for whether the returned version refers to a commit.
"""
if version == "last_green":
return get_last_green_commit(), True
suffix = LAST_GREEN_COMMIT_PATH_SUFFIXES.get(version)
if suffix:
return get_last_green_commit(suffix), True

if "latest" in version:
match = LATEST_PATTERN.match(version)
Expand All @@ -111,8 +114,8 @@ def resolve_version_label_to_number_or_commit(bazelisk_directory, version):
return version, False


def get_last_green_commit():
return read_remote_text_file(LAST_GREEN_COMMIT_FILE).strip()
def get_last_green_commit(path_suffix):
return read_remote_text_file(LAST_GREEN_COMMIT_BASE_PATH + path_suffix).strip()


def get_releases_json(bazelisk_directory):
Expand Down
15 changes: 15 additions & 0 deletions bazelisk_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ function test_bazel_last_green() {
(echo "FAIL: 'bazelisk version' of an unreleased binary must not print a build label."; exit 1)
}

function test_bazel_last_downstream_green() {
setup

USE_BAZEL_VERSION="last_downstream_green" \
BAZELISK_HOME="$BAZELISK_HOME" \
bazelisk version 2>&1 | tee log

! grep "Build label:" log || \
(echo "FAIL: 'bazelisk version' of an unreleased binary must not print a build label."; exit 1)
}

echo "# test_bazel_version"
test_bazel_version
echo
Expand All @@ -135,3 +146,7 @@ echo
echo "# test_bazel_last_green"
test_bazel_last_green
echo

echo "# test_bazel_last_downstream_green"
test_bazel_last_downstream_green
echo

0 comments on commit c6a1dcb

Please sign in to comment.