diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efe5618736..f47b9e228c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -338,8 +338,15 @@ jobs: # Ubuntu release's glibc would otherwise be served to the other. SCCACHE_AZURE_KEY_PREFIX: rocm-cli/build-and-test/${{ matrix.os }} SCCACHE_AZURE_RW_MODE: ${{ (github.event_name == 'push' || github.event_name == 'merge_group') && 'READ_WRITE' || 'READ_ONLY' }} - # Don't spend a Linux build/test cycle until the cheap lint gate is green. - needs: [changes, clippy, prek] + # Waits for `prek`, the cheap hygiene gate (no compile), but deliberately not + # for `clippy`: clippy compiles the workspace, which takes minutes where prek + # takes seconds, and this job heads the critical path (build, then E2E), so + # waiting for it delayed the whole run behind a check that rarely fails. The + # two run in parallel instead. That is acceptable because `clippy` stays a required + # check, so a lint failure still blocks the merge; what a clippy-red run loses + # is only the early skip of this job and of E2E, which now spend their runner + # time before the failure is known. + needs: [changes, prek] # A manual E2E dispatch skips this heavy job for a fast loop; the E2E jobs # tolerate a skipped build-and-test in their own `if:` guards. if: github.event_name != 'workflow_dispatch' @@ -527,9 +534,9 @@ jobs: os: [ubuntu-24.04, ubuntu-26.04] runs-on: ${{ matrix.os }} timeout-minutes: 20 - # Same lint gate as the Linux build job: don't spend a test cycle until the - # cheap checks are green. (The Windows jobs deliberately do not wait; see - # windows-debug.) + # Don't spend a test cycle until the cheap lint checks (clippy and prek) are + # green. (build-and-test waits only for prek and the Windows jobs wait for + # neither; see build-and-test and windows-debug.) needs: [changes, clippy, prek] # A manual E2E dispatch only exercises the E2E jobs; skip the rest. if: github.event_name != 'workflow_dispatch' @@ -634,12 +641,13 @@ jobs: # Neither job waits for `clippy` or `prek`. Those stay required checks in their # own right, so a lint failure still blocks the merge. What this trades is about # two and a half minutes of wall clock on every run, paid for with Windows runner - # time on pushes that turn out lint-red (the Linux jobs still wait). Windows runs - # its own clippy as its first compile step, so a clippy failure surfaces within - # minutes there; a `prek` failure (rustfmt, ruff, shellcheck, hygiene hooks) does - # not. A manual dispatch only exercises the E2E jobs, so both Windows jobs skip it - # — unless the dispatch asked for PR-style binaries, in which case both run, as on - # a pull request. + # time on pushes that turn out lint-red (`test`, `pr-linux-binaries` and + # `remote-ssh` still wait for both lint jobs; `build-and-test` waits for `prek` + # only). Windows runs its own clippy as its first compile step, so a clippy + # failure surfaces within minutes there; a `prek` failure (rustfmt, ruff, + # shellcheck, hygiene hooks) does not. A manual dispatch only exercises the E2E + # jobs, so both Windows jobs skip it — unless the dispatch asked for PR-style + # binaries, in which case both run, as on a pull request. windows-debug: name: Windows build and test (debug) runs-on: windows-latest @@ -1268,10 +1276,11 @@ jobs: os: [ubuntu-24.04, ubuntu-26.04] runs-on: ${{ matrix.os }} timeout-minutes: 30 - # Gated like the other heavy Linux jobs here (the Windows jobs deliberately do - # not wait; see `windows-debug`): a fast lint failure should short-circuit - # before this spends 30 minutes on a container and a cold cargo build, and a - # manual dispatch should stay a fast loop. + # Gated like `test` and `pr-linux-binaries` (`build-and-test` waits for `prek` + # only and the Windows jobs deliberately do not wait; see those jobs): a fast + # lint failure should short-circuit before this spends 30 minutes on a + # container and a cold cargo build, and a manual dispatch should stay a fast + # loop. needs: [changes, clippy, prek] if: github.event_name != 'workflow_dispatch' && needs.changes.outputs.heavy == 'true' steps: @@ -1321,9 +1330,11 @@ jobs: # `--emit=link`, which gives most of them a different cache key than the # build job's, and workspace crates go through clippy-driver, whose hash # differs from rustc's. Crates that must be fully linked for both (proc - # macros, and anything a build script needs) do hit. Sharing cannot poison - # either job: the compiler binary is part of every key. It is the 24.04 - # leg's prefix specifically, since this job runs on that image. + # macros, and anything a build script needs) do hit. The two jobs run in + # parallel, so on a cold cache each compiles those crates itself and the + # sharing pays off from the next run on. Sharing cannot poison either job: + # the compiler binary is part of every key. It is the 24.04 leg's prefix + # specifically, since this job runs on that image. env: RUSTC_WRAPPER: sccache SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.CACHE_AZURE_CONNECTION_STRING }} diff --git a/xtask/src/workflow_contract.rs b/xtask/src/workflow_contract.rs index d0bc3c8cd4..0dfc0146a5 100644 --- a/xtask/src/workflow_contract.rs +++ b/xtask/src/workflow_contract.rs @@ -5322,6 +5322,134 @@ fi } } + /// `build-and-test` heads the Linux critical path (build, then the mock E2E + /// lane that needs it), so it waits for `prek`, the cheap hygiene gate, but not + /// for `clippy`: the two run in parallel and `clippy` stays a required check of + /// its own. Putting `clippy` back in `needs:` would silently add its whole + /// runtime to every run, so the list is pinned exactly. The `clippy` job must + /// still exist, otherwise dropping it from `needs:` would have dropped the check. + #[test] + fn ci_build_and_test_waits_for_prek_but_not_clippy() { + let ci = read_workflow("ci.yml"); + let needs = yaml_value_at(&ci_job(&ci, "build-and-test"), 4, "needs") + .expect("build-and-test declares `needs:`"); + assert_eq!( + flattened_list_items(&needs), + ["changes", "prek"], + "build-and-test must need `changes` and `prek` and not `clippy`, which runs \ + alongside it; a lint failure is still caught by the required `clippy` check" + ); + ci_job(&ci, "clippy"); + } + + /// The other half of the ordering above: with `clippy` no longer ahead of + /// `build-and-test`, a clippy-red run reaches the E2E job, so what keeps a + /// failed or skipped build from being read as a pass is the E2E job's own + /// gate. The job must need `build-and-test`, and every step after the gate step + /// must follow the gate's decision. What the gate decides is checked by + /// `ci_e2e_gate_opens_only_once_build_and_test_ran_to_a_verdict`. + #[test] + fn ci_e2e_steps_after_the_gate_follow_its_decision() { + let ci = read_workflow("ci.yml"); + let e2e = ci_job(&ci, "e2e"); + let needs = yaml_value_at(&e2e, 4, "needs").expect("e2e declares `needs:`"); + assert_eq!( + flattened_list_items(&needs), + ["changes", "build-and-test"], + "the e2e job must need `build-and-test`, which it consumes" + ); + let steps = job_steps(&e2e).expect("e2e has steps"); + let gate_at = steps + .iter() + .position(|(name, _)| name == "Decide whether to run") + .expect("e2e has a gate step named `Decide whether to run`"); + assert!( + steps.len() > gate_at + 1, + "the e2e job has steps after its gate" + ); + for (name, step) in &steps[gate_at + 1..] { + assert!( + step_key(step, "if").contains("steps.gate.outputs.run == 'true'"), + "the e2e step `{name}` must follow the gate's decision, or a failed \ + build-and-test would still run it" + ); + } + } + + /// Run the e2e gate's own script, the way GitHub runs a step with no `shell:` + /// (`bash -e`), over every event and every `build-and-test` result. The gate + /// opens once `build-and-test` ran to a verdict, `success` or `failure`: it is + /// a matrix over both images and its result is the aggregate, so a failure on + /// one image must not skip the other's E2E. A `skipped` or `cancelled` build + /// never ran to a verdict, so it must not open the work on a push, a pull + /// request or a merge group; only a manual dispatch, which skips + /// `build-and-test` on purpose, opens it without one. + #[cfg(unix)] + #[test] + fn ci_e2e_gate_opens_only_once_build_and_test_ran_to_a_verdict() { + let ci = read_workflow("ci.yml"); + let steps = job_steps(&ci_job(&ci, "e2e")).expect("e2e has steps"); + let gate = steps + .iter() + .find(|(name, _)| name == "Decide whether to run") + .expect("e2e has a gate step named `Decide whether to run`"); + let script = preflight_body_code(&gate.1); + let run = |event: &str, build: &str, heavy: &str| -> String { + let script = script + .replace("${{ github.event_name }}", event) + .replace("${{ needs.build-and-test.result }}", build) + .replace("${{ needs.changes.outputs.heavy }}", heavy); + assert!( + !script.contains("${{"), + "the gate reads an expression this test does not substitute: {script}" + ); + let dir = tempfile::tempdir().expect("temp dir"); + let output = dir.path().join("github_output"); + std::fs::write(&output, "").expect("creating GITHUB_OUTPUT"); + let out = std::process::Command::new("bash") + .args(["-e", "-c", &script]) + .env("GITHUB_OUTPUT", &output) + .output() + .expect("running the e2e gate script"); + assert_eq!( + exit_code(out.status, "the e2e gate script"), + 0, + "the gate script must exit 0 for {event}/{build}/{heavy}" + ); + std::fs::read_to_string(&output) + .expect("reading GITHUB_OUTPUT") + .trim() + .to_owned() + }; + + for event in ["push", "pull_request", "merge_group"] { + for ran in ["success", "failure"] { + assert_eq!( + run(event, ran, "true"), + "run=true", + "{event}: a {ran} build-and-test ran to a verdict" + ); + assert_eq!( + run(event, ran, "false"), + "run=false", + "{event}: a {ran} build with no heavy change has no E2E work" + ); + } + for bad in ["skipped", "cancelled"] { + assert_eq!( + run(event, bad, "true"), + "run=false", + "{event}: a {bad} build-and-test never ran to a verdict and must not open the E2E work" + ); + } + } + // build-and-test is skipped on a dispatch, so the dispatch opens the gate + // without it; the job-level platform gate decides whether the job runs. + for build in ["success", "skipped", "failure"] { + assert_eq!(run("workflow_dispatch", build, ""), "run=true", "{build}"); + } + } + /// Drive the aggregator's script the way GitHub runs a step with no `shell:` /// (`bash -e`) over every result a work job can finish with. A skipped /// required check counts as passing, so the dangerous outcomes are the ones