Add a way to disable remote flags using an environment variable. (#1760)
Setting the environment variable `BAZELCI_LOCAL_RUN` to `true` will
cause `bazelci.py runner` to not add remote flags such as
`--remote_executor` or `--remote_cache`, and to not attempt uploads
using buildkite-agent.
This allows purely local test runs to verify bazelci task configurations
or to call the tests from another CI system.
Example of use:
```
export BUILDKITE_ORGANIZATION_SLUG=bazel
export BUILDKITE_COMMIT=HEAD
export BUILDKITE_BRANCH=main
export BAZELCI_LOCAL_RUN=true
bazelci.py runner --file_config=rules_android/.bazelci/presubmit.yml --task=ubuntu2004
```
Without this change, the script will attempt to use remote execution
(without having the necessary credentials), and will attempt to upload
failing test logs to buildkite (but without being in an environment
where that is possible).
TODO: We might want to separate these concepts at a later date, but it'd
be even better to split the test runner into a wholely separate python
module first.
diff --git a/buildkite/bazelci.py b/buildkite/bazelci.py
index 0ef497c..baebdbd 100755
--- a/buildkite/bazelci.py
+++ b/buildkite/bazelci.py
@@ -1170,6 +1170,14 @@
"""
return is_trueish(os.environ.get("USE_BAZELISK_MIGRATE"))
+def local_run_only():
+ """
+ If BAZELCI_LOCAL_RUN is set, run bazelci in local-only mode, with no attempt
+ to use remote cache/execution, and no attempt to upload test results. Only
+ compatible with `bazelci.py runner`, not other subcommands.
+ """
+ return is_trueish(os.environ.get("BAZELCI_LOCAL_RUN", "false"))
+
def bazelisk_flags():
return ["--migrate"] if use_bazelisk_migrate() else []
@@ -1658,6 +1666,8 @@
def upload_bazel_binary(platform):
+ if local_run_only():
+ return
print_collapsed_group(":gcloud: Uploading Bazel Under Test")
if platform == "windows":
binary_dir = r"bazel-bin\src"
@@ -1672,6 +1682,8 @@
def merge_and_upload_kythe_kzip(platform, index_upload_gcs):
+ if local_run_only():
+ return
print_collapsed_group(":gcloud: Uploading kythe kzip")
kzips = glob("bazel-out/*/extra_actions/**/*.kzip", recursive=True)
@@ -2071,11 +2083,13 @@
def compute_flags(platform, flags, bep_file, bazel_binary, enable_remote_cache=False):
aggregated_flags = common_build_flags(bep_file, platform)
- if not remote_enabled(flags):
- if platform.startswith("rbe_"):
- aggregated_flags += rbe_flags(flags, accept_cached=enable_remote_cache)
- else:
- aggregated_flags += remote_caching_flags(platform, accept_cached=enable_remote_cache)
+
+ if not local_run_only():
+ if not remote_enabled(flags):
+ if platform.startswith("rbe_"):
+ aggregated_flags += rbe_flags(flags, accept_cached=enable_remote_cache)
+ else:
+ aggregated_flags += remote_caching_flags(platform, accept_cached=enable_remote_cache)
aggregated_flags += flags
for i, flag in enumerate(aggregated_flags):
@@ -2590,6 +2604,8 @@
def upload_test_logs_from_bep(bep_file, tmpdir, monitor_flaky_tests):
+ if local_run_only():
+ return
bazelci_agent_binary = download_bazelci_agent(tmpdir)
execute_command(
[
@@ -2605,6 +2621,8 @@
def upload_json_profile(json_profile_path, tmpdir):
+ if local_run_only():
+ return
if not os.path.exists(json_profile_path):
return
print_collapsed_group(":gcloud: Uploading JSON Profile")
@@ -2612,6 +2630,8 @@
def upload_corrupted_outputs(capture_corrupted_outputs_dir, tmpdir):
+ if local_run_only():
+ return
if not os.path.exists(capture_corrupted_outputs_dir):
return
print_collapsed_group(":gcloud: Uploading corrupted outputs")