From 72f1367077ca9ed31332b71330fddd4754c8ad5e Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sat, 28 Nov 2026 15:42:27 -0700 Subject: [PATCH] ci: add Linux Buildkite fast-test generator --- .buildkite/BUILD.bazel | 15 +++++++++ .buildkite/pipeline.py | 46 ++++++++++++++++++++++++++ .buildkite/pipeline_test.py | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 .buildkite/BUILD.bazel create mode 100755 .buildkite/pipeline.py create mode 100755 .buildkite/pipeline_test.py diff --git a/.buildkite/BUILD.bazel b/.buildkite/BUILD.bazel new file mode 100644 index 0000000000..e15e83695b --- /dev/null +++ b/.buildkite/BUILD.bazel @@ -0,0 +1,15 @@ +load("//python:py_test.bzl", "py_test") + +py_test( + name = "pipeline_test", + srcs = [ + "pipeline.py", + "pipeline_test.py", + ], + imports = ["."], + main = "pipeline_test.py", + target_compatible_with = select({ + "@platforms//os:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), +) diff --git a/.buildkite/pipeline.py b/.buildkite/pipeline.py new file mode 100755 index 0000000000..a29368425e --- /dev/null +++ b/.buildkite/pipeline.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Generate initial Linux fast-test jobs for the shared Buildkite pipeline. + +Usage: .buildkite/pipeline.py | buildkite-agent pipeline upload + +Emits Buildkite JSON using only the Python standard library; no input files +or credentials are required. This supplements BazelCI rather than replacing +its platform, nested-workspace, coverage, or integration-test matrix. +""" + +from __future__ import annotations + +import json +from typing import TypedDict + +_BAZEL_VERSIONS = ("7.x", "8.x", "9.x") + + +def pipeline() -> dict[str, list[_Step]]: + """Return Linux root-workspace fast tests for supported Bazel versions.""" + steps: list[_Step] = [] + for version in _BAZEL_VERSIONS: + steps.append( + { + "label": f":python: Linux / Bazel {version} (fast tests)", + "key": f"linux-bazel-{version[0]}", + "env": {"USE_BAZEL_VERSION": version}, + "command": "set -euo pipefail\nbazel test --config=ci --config=fast-tests //...", + } + ) + return {"steps": steps} + + +class _Step(TypedDict): + # Display name in Buildkite. + label: str + # Stable identifier for the supported Bazel major version. + key: str + # Bazelisk version selection for the job. + env: dict[str, str] + # Shell command run from the root workspace. + command: str + + +if __name__ == "__main__": + print(json.dumps(pipeline(), indent=2)) diff --git a/.buildkite/pipeline_test.py b/.buildkite/pipeline_test.py new file mode 100755 index 0000000000..33537a7d7e --- /dev/null +++ b/.buildkite/pipeline_test.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Check generated jobs and failure propagation without starting Bazel. + +Usage: python3 -m unittest discover -s .buildkite -p '*_test.py' +""" + +import json +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +import pipeline + + +class PipelineTest(unittest.TestCase): + def test_executable_emits_json(self): + result = subprocess.run( + [str(Path(__file__).with_name("pipeline.py").resolve())], + capture_output=True, + text=True, + check=True, + ) + config = json.loads(result.stdout) + steps = config["steps"] + self.assertEqual(len(steps), 3) + self.assertEqual( + [step["env"]["USE_BAZEL_VERSION"] for step in steps], + ["7.x", "8.x", "9.x"], + ) + self.assertEqual( + [step["key"] for step in steps], + ["linux-bazel-7", "linux-bazel-8", "linux-bazel-9"], + ) + + def test_commands_preserve_arguments_and_bazel_failure(self): + # A real executable stands in for Bazel; no build server is started. + with tempfile.TemporaryDirectory() as directory: + bazel = Path(directory) / "bazel" + bazel.write_text('#!/bin/sh\nprintf "%s\\n" "$@"\nexit "$FAKE_EXIT"\n') + bazel.chmod(0o755) + for step in pipeline.pipeline()["steps"]: + for exit_code in (0, 1, 3, 37): + with self.subTest(version=step["env"], exit_code=exit_code): + env = dict(os.environ, **step["env"]) + env["PATH"] = directory + os.pathsep + env["PATH"] + env["FAKE_EXIT"] = str(exit_code) + result = subprocess.run( + ["bash", "-c", step["command"]], + env=env, + capture_output=True, + text=True, + check=False, + ) + self.assertEqual(result.returncode, exit_code) + self.assertEqual( + result.stdout, + "test\n--config=ci\n--config=fast-tests\n//...\n", + ) + + +if __name__ == "__main__": + unittest.main()