Allow specific pipelines to run at higher priority (#2106)
Also formatted bazelci.py
diff --git a/buildkite/bazelci.py b/buildkite/bazelci.py
index b408ea2..66f70fe 100755
--- a/buildkite/bazelci.py
+++ b/buildkite/bazelci.py
@@ -484,6 +484,10 @@
_SHARD_RE = re.compile(r"(.+) \(shard (\d+)\)")
_SLOWEST_N_TARGETS = 20
+# Pipelines with elevated priority. Values are project slugs,
+# i.e. "org_slug/pipeline_slug".
+_PRIORITY_PIPELINES = frozenset(["bazel/google-bazel-presubmit"])
+
class BuildkiteException(Exception):
"""
@@ -580,11 +584,13 @@
if retry_after:
wait_time = int(retry_after)
else:
- wait_time = (2 ** attempt) # Exponential backoff if no RateLimit-Reset header
+ wait_time = 2**attempt # Exponential backoff if no RateLimit-Reset header
time.sleep(wait_time)
else:
- raise BuildkiteException("Failed to open {}: {} - {}".format(url, ex.code, ex.reason))
+ raise BuildkiteException(
+ "Failed to open {}: {} - {}".format(url, ex.code, ex.reason)
+ )
raise BuildkiteException(f"Failed to open {url} after {retries} retries.")
@@ -968,7 +974,9 @@
else:
file_config = new_path
- imported_config = load_config(http_url=http_url, file_config=file_config, allow_imports=False, bazel_version=bazel_version)
+ imported_config = load_config(
+ http_url=http_url, file_config=file_config, allow_imports=False, bazel_version=bazel_version
+ )
namespace = import_name.partition(".")[0]
tasks = {}
@@ -2669,7 +2677,9 @@
process.kill()
-def create_step(label, commands, platform, shards=1, soft_fail=None, concurrency=None, concurrency_group=None):
+def create_step(
+ label, commands, platform, shards=1, soft_fail=None, concurrency=None, concurrency_group=None
+):
if "docker-image" in PLATFORMS[platform]:
step = create_docker_step(
label,
@@ -2685,6 +2695,12 @@
"agents": {"queue": PLATFORMS[platform]["queue"]},
}
+ project_slug = "{}/{}".format(
+ os.getenv("BUILDKITE_ORGANIZATION_SLUG"), os.getenv("BUILDKITE_PIPELINE_SLUG")
+ )
+ if project_slug in _PRIORITY_PIPELINES:
+ step["priority"] = 1
+
if shards > 1:
# %N means shard counting starts at 1, not 0
step["label"] += " (shard %N)"
@@ -4351,7 +4367,11 @@
runner.add_argument("--task", action="store", type=str, default="")
runner.add_argument("--file_config", type=str)
runner.add_argument("--http_config", type=str)
- runner.add_argument("--overwrite_bazel_version", type=str, help="Overwrite the bazel version in the config file.")
+ runner.add_argument(
+ "--overwrite_bazel_version",
+ type=str,
+ help="Overwrite the bazel version in the config file.",
+ )
runner.add_argument("--git_repository", type=str)
runner.add_argument(
"--git_commit", type=str, help="Reset the git repository to this commit after cloning it"
@@ -4456,7 +4476,9 @@
old_bazel = task_config.get("old_bazel")
if old_bazel:
new_bazel = task_config.get("bazel")
- print_collapsed_group(f":bazel: Bazel version overridden from {old_bazel} to {new_bazel}")
+ print_collapsed_group(
+ f":bazel: Bazel version overridden from {old_bazel} to {new_bazel}"
+ )
execute_commands(
task_config=task_config,