Skip to content

Commit

Permalink
CI grouping test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Nov 30, 2023
1 parent 1f18cf4 commit db2eaff
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions xtask/src/runchecks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,31 @@ fn run_command(command: &str, args: &[&str], command_error: &str, child_error: &
handle_child_process(command, child_error);
}

// Start section print in CI
fn start_group(title: String) {
if std::env::var("CI").is_ok() {
println!("::group::{}", title);
} else {
println!("\n\n{}", title);
}
}

fn end_group() {
if std::env::var("CI").is_ok() {
println!("::endgroup::");
}
}

// Define and run rustup command
fn rustup(command: &str, target: &str) {
start_group(format!("Rustup: {} add {}", command, target));
run_command(
"rustup",
&[command, "add", target],
"Failed to run rustup",
"Failed to wait for rustup child process",
)
);
end_group();
}

// Define and run a cargo command
Expand Down Expand Up @@ -133,7 +150,7 @@ fn cargo_doc(params: Params) {

// Build and test a crate in a no_std environment
fn build_and_test_no_std<const N: usize>(crate_name: &str, extra_args: [&str; N]) {
println!("\nRun checks for `{}` crate", crate_name);
start_group(format!("Checks: {} (no_std)", crate_name));

// Run cargo build --no-default-features
cargo_build(Params::from(["-p", crate_name, "--no-default-features"]) + extra_args);
Expand Down Expand Up @@ -162,6 +179,8 @@ fn build_and_test_no_std<const N: usize>(crate_name: &str, extra_args: [&str; N]
ARM_TARGET,
]) + extra_args,
);

end_group();
}

// Setup code coverage
Expand Down Expand Up @@ -227,17 +246,21 @@ fn burn_core_std() {
println!("\n\nRun checks for burn-core crate with tch and wgpu backend");

// Run cargo test --features test-tch
start_group("Test: burn-core (tch)".to_string());
cargo_test(["-p", "burn-core", "--features", "test-tch"].into());
end_group();

// Run cargo test --features test-wgpu
if std::env::var("DISABLE_WGPU").is_err() {
start_group("Test: burn-core (wgpu)".to_string());
cargo_test(["-p", "burn-core", "--features", "test-wgpu"].into());
end_group();
}
}

// Test burn-dataset features
fn burn_dataset_features_std() {
println!("\n\nRun checks for burn-dataset features");
start_group("Checks: burn-dataset (all-features)".to_string());

// Run cargo build --all-features
cargo_build(["-p", "burn-dataset", "--all-features"].into());
Expand All @@ -247,13 +270,17 @@ fn burn_dataset_features_std() {

// Run cargo doc --all-features
cargo_doc(["-p", "burn-dataset", "--all-features"].into());

end_group();
}

// Test burn-candle with accelerate (macOS only)
// Leverages the macOS Accelerate framework: https://developer.apple.com/documentation/accelerate
#[cfg(target_os = "macos")]
fn burn_candle_accelerate() {
start_group("Checks: burn-candle (accelerate)".to_string());
cargo_test(["-p", "burn-candle", "--features", "accelerate"].into());
end_group();
}

fn std_checks() {
Expand All @@ -274,22 +301,28 @@ fn std_checks() {
cargo_clippy();

// Build each workspace
start_group("Build: workspaces".to_string());
if disable_wgpu {
cargo_build(["--workspace", "--exclude=xtask", "--exclude=burn-wgpu"].into());
} else {
cargo_build(["--workspace", "--exclude=xtask"].into());
}
end_group();

// Produce documentation for each workspace
start_group("Docs: workspaces".to_string());
cargo_doc(["--workspace"].into());
end_group();

// Setup code coverage
if is_coverage {
setup_coverage();
}

// Test each workspace
start_group("Test: workspaces".to_string());
cargo_test(["--workspace"].into());
end_group();

// Test burn-candle with accelerate (macOS only)
#[cfg(target_os = "macos")]
Expand Down

0 comments on commit db2eaff

Please sign in to comment.