Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .buildkite/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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": [],
}),
)
46 changes: 46 additions & 0 deletions .buildkite/pipeline.py
Original file line number Diff line number Diff line change
@@ -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))
64 changes: 64 additions & 0 deletions .buildkite/pipeline_test.py
Original file line number Diff line number Diff line change
@@ -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()
Loading