From 72cf036f4ca93b46b6b8a92b5378d1251751ccfe Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 28 Oct 2024 16:04:35 +0100 Subject: [PATCH 1/5] ci: Check all possible combinations --- .github/workflows/ci.yml | 2 +- xtask/src/main.rs | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5fbefb..cf23c27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Generate and check project - run: cd xtask && cargo run -- check ${{ matrix.chip }} + run: cd xtask && cargo run -- check ${{ matrix.chip }} --all test: runs-on: ubuntu-latest diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 51dc685..c0bbdc4 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,6 +21,9 @@ enum Commands { /// Target chip to check #[arg(value_enum)] chip: Chip, + /// Verify all possible options combinations + #[arg(short, long)] + all: bool, }, } @@ -35,18 +38,18 @@ fn main() -> Result<()> { let workspace = workspace.parent().unwrap().canonicalize()?; match Cli::parse().command { - Commands::Check { chip } => check(&workspace, chip), + Commands::Check { chip, all } => check(&workspace, chip, all), } } // ---------------------------------------------------------------------------- // CHECK -fn check(workspace: &Path, chip: Chip) -> Result<()> { +fn check(workspace: &Path, chip: Chip, all: bool) -> Result<()> { log::info!("CHECK: {chip}"); const PROJECT_NAME: &str = "test"; - for options in options_for_chip(chip) { + for options in options_for_chip(chip, all) { log::info!("WITH OPTIONS: {options:?}"); // We will generate the project in a temporary directory, to avoid @@ -86,7 +89,7 @@ fn check(workspace: &Path, chip: Chip) -> Result<()> { Ok(()) } -fn options_for_chip(chip: Chip) -> Vec> { +fn options_for_chip(chip: Chip, all: bool) -> Vec> { let default_options: Vec> = vec![ vec![], // No options vec!["alloc".into()], @@ -96,7 +99,7 @@ fn options_for_chip(chip: Chip) -> Vec> { vec!["probe-rs".into()], ]; - match chip { + let available_options = match chip { Chip::Esp32h2 => default_options .iter() .filter(|opts| !opts.contains(&"wifi".to_string())) @@ -108,6 +111,29 @@ fn options_for_chip(chip: Chip) -> Vec> { .cloned() .collect::>(), _ => default_options, + }; + if !all { + return available_options; + } else { + // Return all the combination of availble options + let mut result = vec![]; + for i in 0..(1 << available_options.len()) { + let mut options = vec![]; + for j in 0..available_options.len() { + if i & (1 << j) != 0 { + options.extend(available_options[j].clone()); + } + } + result.push(options); + } + // Filter all the items that contains wifi and ble + let result = result + .into_iter() + .filter(|opts| { + !opts.contains(&"wifi".to_string()) || !opts.contains(&"ble".to_string()) + }) + .collect::>(); + return result; } } From c96cb5110e9a5b7ad59a80132ee4a20cdc0934c8 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 29 Oct 2024 10:27:01 +0100 Subject: [PATCH 2/5] feat: Remove the temporary directory --- xtask/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c0bbdc4..0ef2e56 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -54,7 +54,8 @@ fn check(workspace: &Path, chip: Chip, all: bool) -> Result<()> { // We will generate the project in a temporary directory, to avoid // making a mess when this subcommand is executed locally: - let project_path = tempfile::tempdir()?.into_path(); + let project_dir = tempfile::tempdir()?; + let project_path = project_dir.path(); log::info!("PROJECT PATH: {project_path:?}"); // Generate a project targeting the specified chip and using the @@ -84,6 +85,8 @@ fn check(workspace: &Path, chip: Chip, all: bool) -> Result<()> { .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output()?; + + project_dir.close()?; } Ok(()) From 27c437df1423e4def50c8fe2ea8bcb54cba86ec7 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 29 Oct 2024 11:19:00 +0100 Subject: [PATCH 3/5] feat: Rename flag and add scheduled CI check --- .github/workflows/ci.yml | 10 +++++++++- xtask/src/main.rs | 15 +++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf23c27..0cab16a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,8 @@ on: pull_request: paths-ignore: - "**/README.md" + schedule: + - cron: "50 7 * * *" workflow_dispatch: env: @@ -53,7 +55,13 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Generate and check project - run: cd xtask && cargo run -- check ${{ matrix.chip }} --all + if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' + run: cd xtask && cargo run -- check ${{ matrix.chip }} + + - name: Generate and check project (all combinations) + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + run: cd xtask && cargo run -- check ${{ matrix.chip }} --all-combinations + test: runs-on: ubuntu-latest diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 0ef2e56..3db42ca 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -23,7 +23,7 @@ enum Commands { chip: Chip, /// Verify all possible options combinations #[arg(short, long)] - all: bool, + all_combinations: bool, }, } @@ -38,18 +38,21 @@ fn main() -> Result<()> { let workspace = workspace.parent().unwrap().canonicalize()?; match Cli::parse().command { - Commands::Check { chip, all } => check(&workspace, chip, all), + Commands::Check { + chip, + all_combinations, + } => check(&workspace, chip, all_combinations), } } // ---------------------------------------------------------------------------- // CHECK -fn check(workspace: &Path, chip: Chip, all: bool) -> Result<()> { +fn check(workspace: &Path, chip: Chip, all_combinations: bool) -> Result<()> { log::info!("CHECK: {chip}"); const PROJECT_NAME: &str = "test"; - for options in options_for_chip(chip, all) { + for options in options_for_chip(chip, all_combinations) { log::info!("WITH OPTIONS: {options:?}"); // We will generate the project in a temporary directory, to avoid @@ -92,7 +95,7 @@ fn check(workspace: &Path, chip: Chip, all: bool) -> Result<()> { Ok(()) } -fn options_for_chip(chip: Chip, all: bool) -> Vec> { +fn options_for_chip(chip: Chip, all_combinations: bool) -> Vec> { let default_options: Vec> = vec![ vec![], // No options vec!["alloc".into()], @@ -115,7 +118,7 @@ fn options_for_chip(chip: Chip, all: bool) -> Vec> { .collect::>(), _ => default_options, }; - if !all { + if !all_combinations { return available_options; } else { // Return all the combination of availble options From 2e066820f426e7985924768fb04d1625cc48e474 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 29 Oct 2024 12:15:27 +0100 Subject: [PATCH 4/5] ci: Add input to workflow_dispatch --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cab16a..2c3ed5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,11 @@ on: schedule: - cron: "50 7 * * *" workflow_dispatch: + inputs: + all_combinations: + description: 'Checks all combinations of options' + required: true + type: boolean env: CARGO_TERM_COLOR: always @@ -55,11 +60,11 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Generate and check project - if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' + if: github.event_name != 'schedule' && !inputs.all_combinations run: cd xtask && cargo run -- check ${{ matrix.chip }} - name: Generate and check project (all combinations) - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: github.event_name == 'schedule' || inputs.all_combinations run: cd xtask && cargo run -- check ${{ matrix.chip }} --all-combinations From 00e33932778485e20ad3c10fea081b2afcf93e53 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 29 Oct 2024 13:30:29 +0100 Subject: [PATCH 5/5] refactor: Run cargo check instead of build --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3db42ca..21b106b 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -67,7 +67,7 @@ fn check(workspace: &Path, chip: Chip, all_combinations: bool) -> Result<()> { // Ensure that the generated project builds without errors: Command::new("cargo") - .args(["build", "--release"]) + .args(["check", "--release"]) .current_dir(project_path.join(PROJECT_NAME)) .stdout(Stdio::inherit()) .stderr(Stdio::inherit())