From 01f5b03655cde9ecb5281972748e54d578504197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:24:05 +0100 Subject: [PATCH 1/7] add command to ci to list commands to run --- tools/ci/src/ci.rs | 6 +++ tools/ci/src/commands/mod.rs | 2 + tools/ci/src/commands/what_to_run.rs | 81 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tools/ci/src/commands/what_to_run.rs diff --git a/tools/ci/src/ci.rs b/tools/ci/src/ci.rs index 8b8556d90ac05..8d958330cb0c6 100644 --- a/tools/ci/src/ci.rs +++ b/tools/ci/src/ci.rs @@ -119,6 +119,8 @@ enum Commands { CompileFail(commands::CompileFailCommand), BenchCheck(commands::BenchCheckCommand), ExampleCheck(commands::ExampleCheckCommand), + // Controller (list commands that needs to run) + WhatToRun(commands::WhatToRunCommand), } impl Prepare for Commands { @@ -141,6 +143,10 @@ impl Prepare for Commands { Commands::CompileFail(subcommand) => subcommand.prepare(sh, args), Commands::BenchCheck(subcommand) => subcommand.prepare(sh, args), Commands::ExampleCheck(subcommand) => subcommand.prepare(sh, args), + Commands::WhatToRun(subcommand) => { + subcommand.run(sh, args); + vec![] + } } } } diff --git a/tools/ci/src/commands/mod.rs b/tools/ci/src/commands/mod.rs index 9247ab201627b..abdd0387dbcbb 100644 --- a/tools/ci/src/commands/mod.rs +++ b/tools/ci/src/commands/mod.rs @@ -14,6 +14,7 @@ pub use integration_test_clean::*; pub use lints::*; pub use test::*; pub use test_check::*; +pub use what_to_run::*; mod bench_check; mod clippy; @@ -31,3 +32,4 @@ mod integration_test_clean; mod lints; mod test; mod test_check; +mod what_to_run; diff --git a/tools/ci/src/commands/what_to_run.rs b/tools/ci/src/commands/what_to_run.rs new file mode 100644 index 0000000000000..46bf16724825a --- /dev/null +++ b/tools/ci/src/commands/what_to_run.rs @@ -0,0 +1,81 @@ +use argh::{FromArgValue, FromArgs}; +use xshell::Shell; + +use crate::args::Args; + +/// Decides which jobs to run +#[derive(FromArgs)] +#[argh(subcommand, name = "what-to-run")] +pub struct WhatToRunCommand { + /// which event triggered this run + #[argh(option)] + trigger: Trigger, + + /// which branch to diff against + #[argh(option)] + head: String, + + /// select tasks for a specific version of rust + #[argh(option)] + #[expect(dead_code)] + rust_version: RustVersion, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum RustVersion { + Stable, + Beta, + Nightly, +} + +impl FromArgValue for RustVersion { + fn from_arg_value(value: &str) -> Result { + match value { + "stable" => Ok(RustVersion::Stable), + "beta" => Ok(RustVersion::Beta), + "nightly" => Ok(RustVersion::Nightly), + _ => Err(format!("Unknown rust version: {}", value)), + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum Trigger { + Schedule, + MergeQueue, + ChangeRequest, + PushToBranch, +} + +impl FromArgValue for Trigger { + fn from_arg_value(value: &str) -> Result { + match value { + "schedule" => Ok(Trigger::Schedule), + "merge_group" => Ok(Trigger::MergeQueue), + "pull_request" => Ok(Trigger::ChangeRequest), + "push" => Ok(Trigger::PushToBranch), + _ => Err(format!("Unknown trigger: {}", value)), + } + } +} + +impl WhatToRunCommand { + pub fn run(&self, _sh: &Shell, _args: Args) { + let _diff = match self.trigger { + Trigger::Schedule | Trigger::PushToBranch => vec![], + Trigger::ChangeRequest | Trigger::MergeQueue => get_diff(&self.head), + }; + + // TODO: filter jobs to run based on diff, trigger and rust version + let mut jobs = Vec::new(); + jobs.push(r#""cargo run -p ci -- test""#); + jobs.push(r#""cargo run -p ci -- lints""#); + + println!("[{}]", jobs.join(", ")) + } +} + +fn get_diff(_head: &str) -> Vec { + // TODO: Implement diff logic between local state and head branch + vec![] +} From 059b88226cd1a55847b7882a048224d2ec92deb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:28:38 +0100 Subject: [PATCH 2/7] actions --- .github/workflows/ci2.yml | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/ci2.yml diff --git a/.github/workflows/ci2.yml b/.github/workflows/ci2.yml new file mode 100644 index 0000000000000..c4608983eefb0 --- /dev/null +++ b/.github/workflows/ci2.yml @@ -0,0 +1,66 @@ +name: CI v2 + +permissions: + contents: read + +on: + merge_group: + pull_request: + push: + branches: + - release-* + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + CARGO_PROFILE_TEST_DEBUG: 0 + CARGO_PROFILE_DEV_DEBUG: 0 + # If nightly is breaking CI, modify this variable to target a specific nightly version. + NIGHTLY_TOOLCHAIN: nightly + RUSTFLAGS: "-D warnings" + +jobs: + stable-prepare: + runs-on: ubuntu-latest + timeout-minutes: 30 + outputs: + jobs: ${{ steps.prepare.outputs.jobs }} + steps: + - uses: actions/checkout@v6 + - uses: dtolnay/rust-toolchain@stable + - name: Prepare CI jobs + id: prepare + run: | + echo "jobs=`cargo run -p ci -- what-to-run --trigger ${{ github.event_name }} --head ${{ github.head_ref }} --rust-version stable`" >> $GITHUB_OUTPUT + + stable-run: + runs-on: ubuntu-latest + timeout-minutes: 30 + needs: [stable-prepare] + strategy: + matrix: + job: ${{ fromJson(needs.stable-prepare.outputs.jobs) }} + steps: + - uses: actions/checkout@v6 + - uses: actions/cache/restore@v4 + with: + key: ${{ runner.os }}-ci-runner--${{ hashFiles('tools/ci/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-ci-runner--${{ hashFiles('tools/ci/Cargo.toml') }} + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + - uses: dtolnay/rust-toolchain@stable + - name: Run CI job + run: | + ${{ matrix.job }} + + stable-status: + runs-on: ubuntu-latest + needs: [stable-run] + if: always() + steps: + - run: ${{!contains(needs.*.result, 'failure')}} From da33741161ed6d34c2f48de99d84790c2dc420b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:33:00 +0100 Subject: [PATCH 3/7] linux dependencies --- .github/workflows/ci2.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci2.yml b/.github/workflows/ci2.yml index c4608983eefb0..db13f75f09f92 100644 --- a/.github/workflows/ci2.yml +++ b/.github/workflows/ci2.yml @@ -53,6 +53,8 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ + - name: Install Linux dependencies + uses: ./.github/actions/install-linux-deps - uses: dtolnay/rust-toolchain@stable - name: Run CI job run: | From 2f0db5743c14b9464e6f61e3fd2e0b88b9cc40f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:34:10 +0100 Subject: [PATCH 4/7] run all jobs --- .github/workflows/ci2.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci2.yml b/.github/workflows/ci2.yml index db13f75f09f92..55845bb40898d 100644 --- a/.github/workflows/ci2.yml +++ b/.github/workflows/ci2.yml @@ -38,6 +38,7 @@ jobs: timeout-minutes: 30 needs: [stable-prepare] strategy: + fail-fast: false matrix: job: ${{ fromJson(needs.stable-prepare.outputs.jobs) }} steps: From e3fec47d974aa75fa1aad6b0c35c66b2dcc7a6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:38:29 +0100 Subject: [PATCH 5/7] lints --- tools/ci/src/commands/what_to_run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci/src/commands/what_to_run.rs b/tools/ci/src/commands/what_to_run.rs index 46bf16724825a..9ef3e0a65ac0a 100644 --- a/tools/ci/src/commands/what_to_run.rs +++ b/tools/ci/src/commands/what_to_run.rs @@ -17,7 +17,7 @@ pub struct WhatToRunCommand { /// select tasks for a specific version of rust #[argh(option)] - #[expect(dead_code)] + #[expect(dead_code, reason = "todo")] rust_version: RustVersion, } @@ -71,7 +71,7 @@ impl WhatToRunCommand { jobs.push(r#""cargo run -p ci -- test""#); jobs.push(r#""cargo run -p ci -- lints""#); - println!("[{}]", jobs.join(", ")) + println!("[{}]", jobs.join(", ")); } } From 29256981fc2beeca837122317383f9e6a135f05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:40:59 +0100 Subject: [PATCH 6/7] some comments --- .github/workflows/ci2.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci2.yml b/.github/workflows/ci2.yml index 55845bb40898d..8ae4bfbbce9d9 100644 --- a/.github/workflows/ci2.yml +++ b/.github/workflows/ci2.yml @@ -20,6 +20,7 @@ env: RUSTFLAGS: "-D warnings" jobs: + # job to list the jobs to run on rust stable stable-prepare: runs-on: ubuntu-latest timeout-minutes: 30 @@ -33,6 +34,7 @@ jobs: run: | echo "jobs=`cargo run -p ci -- what-to-run --trigger ${{ github.event_name }} --head ${{ github.head_ref }} --rust-version stable`" >> $GITHUB_OUTPUT + # run all the jobs on stable stable-run: runs-on: ubuntu-latest timeout-minutes: 30 @@ -61,6 +63,7 @@ jobs: run: | ${{ matrix.job }} + # single job to report status, usable in branch protection rules stable-status: runs-on: ubuntu-latest needs: [stable-run] From a9182b67a2d563e13d5892f24b585ed4195776d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Fri, 5 Dec 2025 01:47:15 +0100 Subject: [PATCH 7/7] more lints --- tools/ci/src/commands/what_to_run.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/ci/src/commands/what_to_run.rs b/tools/ci/src/commands/what_to_run.rs index 9ef3e0a65ac0a..c5528fdc9603b 100644 --- a/tools/ci/src/commands/what_to_run.rs +++ b/tools/ci/src/commands/what_to_run.rs @@ -60,6 +60,11 @@ impl FromArgValue for Trigger { } impl WhatToRunCommand { + #[expect(clippy::print_stdout, reason = "goal is to print jobs to stdout")] + #[expect( + clippy::vec_init_then_push, + reason = "temp, will be better after the todo" + )] pub fn run(&self, _sh: &Shell, _args: Args) { let _diff = match self.trigger { Trigger::Schedule | Trigger::PushToBranch => vec![],