BCR: Block fewer builds (#2717)
Only block builds with shell/batch commands in their yml configs, not
all yml changes.
Co-authored-by: Xùdōng Yáng <wyverald@gmail.com>
diff --git a/buildkite/bazel-central-registry/bcr_presubmit.py b/buildkite/bazel-central-registry/bcr_presubmit.py
index 0740937..972d8e6 100755
--- a/buildkite/bazel-central-registry/bcr_presubmit.py
+++ b/buildkite/bazel-central-registry/bcr_presubmit.py
@@ -555,7 +555,7 @@
with open(get_presubmit_yml(module_name, module_version), "rt") as f:
presubmit_content = f.read()
- if "shell_commands" in presubmit_content:
+ if bazelci.contains_user_commands(presubmit_content):
risky_presubmit_yml_files.add(f"modules/{module_name}/{module_version}/presubmit.yml")
configs = get_anonymous_module_task_config(module_name, module_version)
diff --git a/buildkite/bazelci.py b/buildkite/bazelci.py
index fbef75d..3ac234b 100755
--- a/buildkite/bazelci.py
+++ b/buildkite/bazelci.py
@@ -3305,6 +3305,13 @@
modified_files = get_modified_files(os.getenv("BUILDKITE_COMMIT"))
modified_config_files = [f for f in modified_files if is_config_file(f)]
+
+ if os.getenv("BUILDKITE_PIPELINE_SLUG", "") == "bazel-central-registry":
+ # Blocking all yml changes in BCR PRs would be too annoying,
+ # so we only block those with shell/batch commands.
+ # This is the same behavior as in bcr_presubmit.py.
+ modified_config_files = [p for p in modified_config_files if is_risky_bcr_config(p)]
+
if modified_config_files:
steps.append(
{
@@ -3320,6 +3327,15 @@
return ".bazelci" in path or path.endswith(".yml")
+def is_risky_bcr_config(path):
+ with open(path, "rt") as f:
+ return contains_user_commands(f.read())
+
+
+def contains_user_commands(yml_content):
+ return "shell_commands" in yml_content or "batch_commands" in yml_content
+
+
def create_buildifier_step(buildifier_config):
buildifier_env_vars = {}
if isinstance(buildifier_config, str):