diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 942fc98dd8..49bec167a5 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -53,7 +53,7 @@ A hosted runner is also the only choice for a few things the pods cannot do: `mo These are the patterns that have cost real money here without validating anything more: - An `if: always()` summary or alert job on a self-hosted label inside a `workflow_run`-triggered workflow. The upstream workflow completes many times a day, the real jobs skip, and the summary still starts a pod each time. Gate it on the upstream job having run, and keep it on `ubuntu-latest`. -- Per-push workflows on `main`. A merge triggers the applicable `ci.yml` matrix and cache warming; `build.yml` development builds are scheduled or manual; with tens of merges a day that is as much self-hosted time as all pull requests together. Anything that does not verify the merged tree itself belongs on a schedule or behind a `paths` filter. +- Per-push workflows on `main`. A merge triggers cache warming and a `ci.yml` run, which validates the merged tree in full unless a merge-queue run already validated that tree; `build.yml` development builds are scheduled or manual; with tens of merges a day that is as much self-hosted time as all pull requests together. Anything that does not verify the merged tree itself belongs on a schedule or behind a `paths` filter. - `apt-get install` of tools the hosted image already ships. It is only needed on the minimal pod images. - A throttled `CARGO_BUILD_JOBS` on a 14-CPU pod. The limit exists for link-storm reasons documented in `ci.yml`; measure before raising it, and measure before lowering it further. - Tiny jobs on ARC pods. Each one pays roughly a minute of pod start-up before its first step; a compile-free job that takes ten seconds costs more to schedule than to run. diff --git a/docs/operations/release-pipeline.md b/docs/operations/release-pipeline.md index 5ac70cf71e..735028e388 100644 --- a/docs/operations/release-pipeline.md +++ b/docs/operations/release-pipeline.md @@ -14,7 +14,7 @@ The builder workflows (`build.yml`, `package.yml`, `docker.yml`, `helm-package.y ## Freeze and build -Select a reviewed source commit whose Cargo version equals the intended final version. Finish exact-source CI before dispatching the candidate. The candidate workflow itself must run from upstream main. Unrelated main commits do not require rebuilding an accepted source. +Select a reviewed source commit whose Cargo version equals the intended final version. Finish exact-source CI before dispatching the candidate: a successful `push` or `workflow_dispatch` run of `ci.yml` for that commit on `main` or the release branch whose `Quick Checks`, `Test and Lint` and `End-to-End Tests (full merge gate)` all succeeded. A commit that landed through the merge queue has a push run whose validation jobs were skipped as proven; `Quick Checks` and `Test and Lint` must still succeed there, and the evidence recorded is the successful `merge_group` run of that branch's queue whose head commit has the same tree, which must itself have passed all three jobs. `scripts/ci_merge_group_proof.py` defines that match for both the push plan and the candidate. The candidate workflow itself must run from upstream main. Unrelated main commits do not require rebuilding an accepted source. ```bash gh workflow run release-candidate.yml --ref main \ diff --git a/docs/testing/ci-gates.md b/docs/testing/ci-gates.md index d2274a3188..d2189bde46 100644 --- a/docs/testing/ci-gates.md +++ b/docs/testing/ci-gates.md @@ -72,7 +72,7 @@ The four site-replication state-writer concurrency proofs reserve the available | PR touching `paths` in `oidc-keycloak.yml` | `OIDC Keycloak live gate` | `oidc-keycloak.yml` `oidc-keycloak-live` | Report-only | `cargo build --locked -p rustfs --bin rustfs`, then `bash scripts/test/oidc_keycloak_live.sh ./target/debug/rustfs` | | PR touching `paths` in `targets-integration.yml` | `PostgreSQL, MySQL, AMQP, and NATS` | `targets-integration.yml` `targets-live` | Report-only | start the containers as in the job, export the `RUSTFS_TEST_*` DSNs, then the job's `cargo test --locked -p rustfs-targets --test -- --ignored --test-threads=1` commands | | PR, documentation-only selection | `Quick Checks`, `Typos`, `Test and Lint` | `ci.yml` `quick-checks`, `typos`, `required-checks` | Required directly or via aggregate | Quick Checks commands; `python3 scripts/ci_gate.py --self-test` | -| `merge_group`; push to `main` or `gateway/integration` | `End-to-End Tests (full merge gate)` | `ci.yml` `e2e-full` | Via aggregate on these events | `python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-full -p e2e_test` (CI adds `--binary "$RUSTFS_E2E_STARTUP_CAS_BINARY"` for the downloaded binary and sidecar) | +| `merge_group`; push to `main` or `gateway/integration` that no successful `merge_group` run of the same tree proved | `End-to-End Tests (full merge gate)` | `ci.yml` `e2e-full` | Via aggregate on these events; skipped on a proven push, whose evidence is the proving run | `python3 scripts/e2e_binary.py run --features e2e-test-hooks -- cargo nextest run --profile e2e-full -p e2e_test` (CI adds `--binary "$RUSTFS_E2E_STARTUP_CAS_BINARY"` for the downloaded binary and sidecar) | e2e filters live in `.config/nextest.toml`; extend a profile instead of adding a second selector. Before a profile runs, `scripts/check_test_wiring.py` compares its listing to the committed digest in `.config/e2e--selection.txt`, so a silent test drop fails closed. @@ -88,7 +88,7 @@ Scheduled lanes never block a PR. Their workflow-local gate fails the run. The v | Workflow (cadence) | Jobs | Verdict and artifacts | Registry monitor | Reproduce | |---|---|---|---|---| -| `ci.yml` (nightly) | full matrix, including the schedule/dispatch-only rio-v2 jobs `build-rustfs-debug-binary-rio-v2` and `e2e-tests-rio-v2` | strict aggregate; the full E2E lane runs on dispatch, merge groups, and main pushes | yes | dispatch `ci.yml` | +| `ci.yml` (nightly) | full matrix, including the schedule/dispatch-only rio-v2 jobs `build-rustfs-debug-binary-rio-v2` and `e2e-tests-rio-v2` | strict aggregate; the full E2E lane runs on dispatch, merge groups, and main pushes that no merge group proved | yes | dispatch `ci.yml` | | `cache-warm.yml` (every six hours, plus main pushes that change `Cargo.lock`, `rust-toolchain.toml` or the setup action) | `warm-ci-dev`, `warm-ci-feat-rio`, `warm-ci-feat-proto`, `warm-ci-uring` | no verdict; sole writer of the `rust-cache` keys that `ci.yml` restores | yes | dispatch `cache-warm.yml` | | `build.yml` (nightly) | `build-rustfs` over the six-target platform matrix in `prepare-platform-matrix` (four Linux, macOS aarch64, Windows x86_64) | build/package integrity | yes | dispatch `build.yml` with an exact platform set | | `e2e-replication-nightly.yml` (nightly) | `repl-nightly`, `cluster-nightly`, `protocols-nightly` | three independent gates; JUnit, membership listing, server logs | yes | `python3 scripts/e2e_binary.py build --bins`, then `python3 scripts/e2e_binary.py run -- cargo nextest run --profile e2e-repl-nightly -p e2e_test`; `--features e2e-test-hooks` on both steps with `--profile e2e-nightly`; `--features ftps,webdav,sftp` on both steps with `-j 1 --profile e2e-protocols` | diff --git a/scripts/ci_gate.py b/scripts/ci_gate.py index e41a594852..88d9e4c6ea 100644 --- a/scripts/ci_gate.py +++ b/scripts/ci_gate.py @@ -378,7 +378,7 @@ def configurations(jobs: dict[str, str]) -> list[dict]: def select_plan(event: str, base: str, head: str, ref: str, root: Path, action: str = "", rehearse_shards: bool = False, - proof: dict | None = None) -> dict: + *, proof: dict | None = None) -> dict: if event not in EVENTS or not SHA.fullmatch(head): raise ValueError("unsupported event or missing candidate SHA") tree = git(root, "rev-parse", f"{head}^{{tree}}").strip() @@ -898,7 +898,7 @@ def main() -> int: proof = None plan = select_plan(os.environ.get("GITHUB_EVENT_NAME", ""), os.environ.get("CI_BASE_SHA", ""), os.environ.get("GITHUB_SHA", ""), os.environ.get("GITHUB_REF", ""), Path.cwd(), - os.environ.get("CI_EVENT_ACTION", ""), os.environ.get("CI_REHEARSE_SHARDS", "false") == "true", proof) + os.environ.get("CI_EVENT_ACTION", ""), os.environ.get("CI_REHEARSE_SHARDS", "false") == "true", proof=proof) with open(os.environ["GITHUB_OUTPUT"], "a") as output: for name, value in (("mode", plan["mode"]), ("plan", json.dumps(plan, separators=(",", ":"))), ("connect", str(plan["connect"]).lower()), ("packages", json.dumps(plan["packages"], separators=(",", ":"))), diff --git a/scripts/ci_merge_group_proof.py b/scripts/ci_merge_group_proof.py index 1cb513a361..c2e65c7605 100644 --- a/scripts/ci_merge_group_proof.py +++ b/scripts/ci_merge_group_proof.py @@ -31,16 +31,24 @@ def lookup(repository: str, tree: str, branch: str, token: str, opener=None) -> if not isinstance(runs, list): return None for run in runs: - if (isinstance(run, dict) and run.get("event") == "merge_group" and run.get("status") == "completed" - and run.get("conclusion") == "success" and isinstance(run.get("head_branch"), str) - and run["head_branch"].startswith(f"gh-readonly-queue/{branch}/") - and isinstance(run.get("head_commit"), dict) and run["head_commit"].get("tree_id") == tree - and type(run.get("id")) is int and run["id"] > 0 and isinstance(run.get("html_url"), str) - and run["html_url"] == f"https://github.com/{repository}/actions/runs/{run['id']}"): + if proves(run, repository, branch, tree): return {"run_id": run["id"], "url": run["html_url"], "tree": tree} return None +def proves(run, repository: str, branch: str, tree: str) -> bool: + """Whether `run`, listed from ci.yml's runs, is a successful merge-queue run of `branch` in `repository` on `tree`. + + The push plan and the release pipeline both accept a tree on this rule alone. + """ + return (isinstance(run, dict) and run.get("event") == "merge_group" and run.get("status") == "completed" + and run.get("conclusion") == "success" and isinstance(run.get("head_branch"), str) + and run["head_branch"].startswith(f"gh-readonly-queue/{branch}/") + and isinstance(run.get("head_commit"), dict) and run["head_commit"].get("tree_id") == tree + and type(run.get("id")) is int and run["id"] > 0 and isinstance(run.get("html_url"), str) + and run["html_url"] == f"https://github.com/{repository}/actions/runs/{run['id']}") + + def main() -> int: """Print the proof for GITHUB_SHA on GITHUB_REF as JSON, or null; never fail the step.""" ref = os.environ.get("GITHUB_REF", "") diff --git a/scripts/release/pipeline.py b/scripts/release/pipeline.py index 64cb914fbc..761aceb066 100644 --- a/scripts/release/pipeline.py +++ b/scripts/release/pipeline.py @@ -12,6 +12,7 @@ from pathlib import Path import re import shutil import subprocess +import sys import tempfile import urllib.error import zipfile @@ -19,6 +20,9 @@ import zipfile import candidate as c import release_gate +sys.path.insert(0, str(c.ROOT / "scripts")) +import ci_merge_group_proof as proof + def current_run(workflow): c.require(os.environ.get("GITHUB_REPOSITORY") == c.REPOSITORY and os.environ.get("GITHUB_REF") == "refs/heads/main", @@ -44,9 +48,26 @@ def output_inputs(inputs): c.emit_output(field, inputs[field]) +CI_GATE = ("Quick Checks", "Test and Lint", "End-to-End Tests (full merge gate)") + + +def run_jobs(run): + jobs = [] + for page in range(1, 11): + batch = c.github(f"repos/{c.REPOSITORY}/actions/runs/{run['id']}/attempts/{run['run_attempt']}/jobs?per_page=100&page={page}")["jobs"] + jobs.extend(batch) + if len(batch) < 100: + break + return jobs + + +def succeeded(jobs, names): + selected = {name: [job for job in jobs if job.get("name") == name] for name in names} + return all(len(found) == 1 and found[0].get("status") == "completed" and found[0].get("conclusion") == "success" for found in selected.values()) + + def source_ci(source, version): runs = c.github(f"repos/{c.REPOSITORY}/actions/workflows/ci.yml/runs?head_sha={source}&status=success&per_page=10")["workflow_runs"] - required = {"Quick Checks", "Test and Lint", "End-to-End Tests (full merge gate)"} for run in runs: if (run.get("head_sha") != source or run.get("path") != ".github/workflows/ci.yml" or run.get("head_branch") not in ("main", f"release/{version}") @@ -54,15 +75,18 @@ def source_ci(source, version): or run.get("conclusion") != "success" or run.get("status") != "completed" or (run.get("repository") or {}).get("full_name") != c.REPOSITORY): continue - jobs = [] - for page in range(1, 11): - batch = c.github(f"repos/{c.REPOSITORY}/actions/runs/{run['id']}/attempts/{run['run_attempt']}/jobs?per_page=100&page={page}")["jobs"] - jobs.extend(batch) - if len(batch) < 100: - break - selected = {name: [job for job in jobs if job.get("name") == name] for name in required} - if all(len(found) == 1 and found[0].get("status") == "completed" and found[0].get("conclusion") == "success" for found in selected.values()): + jobs = run_jobs(run) + if succeeded(jobs, CI_GATE): return {"run_id": run["id"], "run_attempt": run["run_attempt"]} + # The full gate of a queue-landed commit may have run only in the merge-group run of its tree, which + # its push run skips as proven. That run is found again here (scripts/ci_merge_group_proof.py) and, + # if it passed the whole gate itself, is the evidence. + if run["event"] == "push" and succeeded(jobs, CI_GATE[:2]): + tree = c.command(["git", "rev-parse", "--verify", "--end-of-options", f"{source}^{{tree}}"], cwd=c.ROOT) + queued = c.github(f"repos/{c.REPOSITORY}/actions/workflows/ci.yml/runs?event=merge_group&status=success&per_page=100") + for proving in queued["workflow_runs"]: + if proof.proves(proving, c.REPOSITORY, run["head_branch"], tree) and succeeded(run_jobs(proving), CI_GATE): + return {"run_id": proving["id"], "run_attempt": proving["run_attempt"]} raise ValueError("no complete exact-source CI found; run ci.yml on main or the release branch before creating a candidate") diff --git a/scripts/release/test_pipeline.py b/scripts/release/test_pipeline.py index 168cccad8b..1669791a07 100644 --- a/scripts/release/test_pipeline.py +++ b/scripts/release/test_pipeline.py @@ -175,6 +175,56 @@ class SourceCITests(unittest.TestCase): with self.assertRaises(ValueError): pipeline.source_ci("a" * 40, "1.2.3") + def test_a_queue_landed_push_is_accepted_only_through_the_queue_run_of_its_tree(self): + tree = "d" * 40 + gate = ("Quick Checks", "Test and Lint", "End-to-End Tests (full merge gate)") + push = dict(run_metadata(60, "ci.yml", "a" * 40), event="push") + + def queued(run_id, branch, tree_id=tree): + return dict(run_metadata(run_id, "ci.yml", "a" * 40), event="merge_group", run_attempt=3, + head_branch=f"gh-readonly-queue/{branch}/pr-1-" + "c" * 40, head_commit={"tree_id": tree_id}, + html_url=f"https://github.com/{c.REPOSITORY}/actions/runs/{run_id}") + listing = [queued(62, "main", "e" * 40), queued(63, "release/1.2.3"), queued(61, "main")] + # Keyed by (run id, attempt): reading another attempt's jobs is a KeyError, not evidence. + jobs = {(60, 2): [{"name": name, "status": "completed", "conclusion": "skipped" if name == gate[2] else "success"} for name in gate]} + jobs.update({(run["id"], 3): [{"name": name, "status": "completed", "conclusion": "success"} for name in gate] for run in listing}) + + def api(path): + if "/jobs?" in path: + run_id, attempt = path.split("/runs/")[1].split("/jobs?")[0].split("/attempts/") + return {"jobs": jobs[(int(run_id), int(attempt))]} + return {"workflow_runs": listing if "event=merge_group" in path else [push]} + + def source_ci(): + with patch.object(c, "github", side_effect=api), patch.object(c, "command", return_value=tree) as git: + found = pipeline.source_ci("a" * 40, "1.2.3") + self.assertEqual(git.call_args.args[0], ["git", "rev-parse", "--verify", "--end-of-options", "a" * 40 + "^{tree}"]) + return found + self.assertEqual(source_ci(), {"run_id": 61, "run_attempt": 3}) + listing.reverse() + self.assertEqual(source_ci(), {"run_id": 61, "run_attempt": 3}) + push["head_branch"] = "release/1.2.3" + self.assertEqual(source_ci(), {"run_id": 63, "run_attempt": 3}) + del listing[listing.index(next(run for run in listing if run["id"] == 63))] + with self.assertRaises(ValueError): + source_ci() + push["head_branch"] = "main" + match = next(run for run in listing if run["id"] == 61) + refusals = [(match, "head_commit", {"tree_id": "e" * 40}), (match, "head_branch", "gh-readonly-queue/release/1.2.3/pr-1-x"), + (match, "conclusion", "failure"), (match, "event", "push"), (push, "event", "workflow_dispatch")] + for record, key, wrong in refusals: + old = record[key]; record[key] = wrong + with self.subTest(key=key, wrong=wrong), self.assertRaises(ValueError): + source_ci() + record[key] = old + for key, index, conclusion in (((61, 3), 2, "skipped"), ((61, 3), 0, "failure"), ((60, 2), 1, "failure")): + old = jobs[key][index]["conclusion"]; jobs[key][index]["conclusion"] = conclusion + with self.subTest(run=key, job=gate[index]), self.assertRaises(ValueError): + source_ci() + jobs[key][index]["conclusion"] = old + del jobs[(61, 3)][2] + with self.assertRaises(ValueError): + source_ci() class SupplyChainTests(unittest.TestCase): def test_actual_generator_uses_frozen_lock_and_all_package_formats(self): diff --git a/scripts/test_ci_merge_group_proof.py b/scripts/test_ci_merge_group_proof.py index e1477fa4ae..63d59f040c 100644 --- a/scripts/test_ci_merge_group_proof.py +++ b/scripts/test_ci_merge_group_proof.py @@ -61,6 +61,7 @@ class ProofTests(unittest.TestCase): {"conclusion": "failure"}, {"conclusion": "cancelled"}, {"conclusion": None}, {"status": "in_progress"}, {"event": "push"}, {"event": "pull_request"}, {"head_branch": "main"}, {"head_branch": "gh-readonly-queue/release/pr-1-x"}, + {"head_branch": "gh-readonly-queue/mainline/pr-1-x"}, {"head_branch": None}, {"id": "7"}, {"id": 0}, {"id": True}, {"html_url": "https://example.invalid/runs/7"}, {"html_url": None}): with self.subTest(changes=changes): diff --git a/scripts/test_ci_plan.py b/scripts/test_ci_plan.py index f2ed027811..4cc2435ae9 100644 --- a/scripts/test_ci_plan.py +++ b/scripts/test_ci_plan.py @@ -536,6 +536,13 @@ class GateTests(unittest.TestCase): with self.subTest(event=event), self.assertRaises(ValueError): gate.expected_results('proven', event, 'refs/heads/main') + def test_the_queue_run_that_proves_a_push_validates_everything_that_push_would(self): + queued = {job for job, result in gate.expected_results('full', 'merge_group', 'refs/heads/main').items() if result == 'success'} + for ref in gate.INTEGRATION_PUSH_REFS: + pushed = {job for job, result in gate.expected_results('full', 'push', ref).items() if result == 'success'} + with self.subTest(ref=ref): + self.assertLessEqual(pushed, queued) + def test_legacy_base_cannot_authorize_skipped_new_jobs(self): expected = gate.expected_results('full', 'pull_request', 'refs/heads/main') needs = {job: {'result': result} for job, result in expected.items()}