Skip to content

Add argument to ci for test threads and build jobs #16145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2cf22b5
add argument to ci for test threads
BenjaminBrienen Oct 28, 2024
e2c30c3
build jobs
BenjaminBrienen Oct 28, 2024
07ad724
Merge branch 'main' into test-threads-in-ci-doc-test
BenjaminBrienen Oct 28, 2024
3a06f8e
use --jobs
BenjaminBrienen Oct 29, 2024
8aaf9ae
Merge branch 'test-threads-in-ci-doc-test' of github.com:BenjaminBrie…
BenjaminBrienen Oct 29, 2024
bad41ef
Merge branch 'main' into test-threads-in-ci-doc-test
BenjaminBrienen Oct 29, 2024
69716d6
spacing
BenjaminBrienen Oct 29, 2024
76bbf8e
test threads spacing
BenjaminBrienen Oct 29, 2024
57e29f0
Merge branch 'main' into test-threads-in-ci-doc-test
BenjaminBrienen Nov 6, 2024
fe4e0de
Merge branch 'main' into test-threads-in-ci-doc-test
BenjaminBrienen Nov 10, 2024
6f2f6d5
Merge branch 'main' into test-threads-in-ci-doc-test
BenjaminBrienen Jan 2, 2025
3b76bef
Update test.rs
BenjaminBrienen Jan 2, 2025
459146d
Update bench_check.rs
BenjaminBrienen Jan 14, 2025
0a243bc
Update clippy.rs
BenjaminBrienen Jan 14, 2025
7c2fb9d
Update compile_check.rs
BenjaminBrienen Jan 14, 2025
2be4e6a
Update compile_check_no_std.rs
BenjaminBrienen Jan 14, 2025
73aaf78
Update doc_check.rs
BenjaminBrienen Jan 14, 2025
74f72e9
Update doc_test.rs
BenjaminBrienen Jan 14, 2025
59c9127
Update example_check.rs
BenjaminBrienen Jan 14, 2025
9c795ea
Update format.rs
BenjaminBrienen Jan 14, 2025
1709ea0
Update test.rs
BenjaminBrienen Jan 14, 2025
d7d808d
Update test_check.rs
BenjaminBrienen Jan 14, 2025
8600341
Update format.rs
BenjaminBrienen Jan 15, 2025
9bd9930
Update doc_check.rs
BenjaminBrienen Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tools/ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ license = "MIT OR Apache-2.0"
[dependencies]
argh = "0.1"
xshell = "0.2"
bitflags = "2.3"

[lints]
workspace = true
5 changes: 5 additions & 0 deletions tools/ci/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct Args {
pub keep_going: bool,
pub test_threads: Option<u8>,
}
92 changes: 55 additions & 37 deletions tools/ci/src/ci.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
args::Args,
commands,
prepare::{Flag, Prepare, PreparedCommand},
prepare::{Prepare, PreparedCommand},
};
use argh::FromArgs;

Expand All @@ -13,6 +14,23 @@ pub struct CI {
/// continue running commands even if one fails
#[argh(switch)]
keep_going: bool,

/// parallelism of `cargo test`
#[argh(option)]
test_threads: Option<u8>,

/// sets `RUST_BUILD_JOBS`
#[argh(option)]
build_jobs: Option<u8>,
}

impl From<&CI> for Args {
fn from(value: &CI) -> Self {
Args {
keep_going: value.keep_going,
test_threads: value.test_threads,
}
}
}

impl CI {
Expand All @@ -22,9 +40,14 @@ impl CI {
/// This is usually related to differing toolchains and configuration.
pub fn run(self) {
let sh = xshell::Shell::new().unwrap();
let mut prepared_commands = self.prepare(&sh);

let prepared_commands = self.prepare(&sh);

if let Some(build_jobs) = self.build_jobs {
prepared_commands = prepared_commands
.into_iter()
.map(|pc| pc.with_env_var("RUST_BUILD_JOBS", build_jobs.to_string().leak()))
.collect();
}
let mut failures = vec![];

for command in prepared_commands {
Expand Down Expand Up @@ -59,28 +82,23 @@ impl CI {
}

fn prepare<'a>(&self, sh: &'a xshell::Shell) -> Vec<PreparedCommand<'a>> {
let mut flags = Flag::empty();

if self.keep_going {
flags |= Flag::KEEP_GOING;
}

let args = self.into();
match &self.command {
Some(command) => command.prepare(sh, flags),
Some(command) => command.prepare(sh, args),
None => {
// Note that we are running the subcommands directly rather than using any aliases
let mut cmds = vec![];
cmds.append(&mut commands::FormatCommand::default().prepare(sh, flags));
cmds.append(&mut commands::ClippyCommand::default().prepare(sh, flags));
cmds.append(&mut commands::TestCommand::default().prepare(sh, flags));
cmds.append(&mut commands::TestCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::DocCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::DocTestCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileCheckNoStdCommand::default().prepare(sh, flags));
cmds.append(&mut commands::CompileFailCommand::default().prepare(sh, flags));
cmds.append(&mut commands::BenchCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::ExampleCheckCommand::default().prepare(sh, flags));
cmds.append(&mut commands::FormatCommand::default().prepare(sh, args));
cmds.append(&mut commands::ClippyCommand::default().prepare(sh, args));
cmds.append(&mut commands::TestCommand::default().prepare(sh, args));
cmds.append(&mut commands::TestCheckCommand::default().prepare(sh, args));
cmds.append(&mut commands::DocCheckCommand::default().prepare(sh, args));
cmds.append(&mut commands::DocTestCommand::default().prepare(sh, args));
cmds.append(&mut commands::CompileCheckCommand::default().prepare(sh, args));
cmds.append(&mut commands::CompileCheckNoStdCommand::default().prepare(sh, args));
cmds.append(&mut commands::CompileFailCommand::default().prepare(sh, args));
cmds.append(&mut commands::BenchCheckCommand::default().prepare(sh, args));
cmds.append(&mut commands::ExampleCheckCommand::default().prepare(sh, args));
cmds
}
}
Expand Down Expand Up @@ -110,23 +128,23 @@ enum Commands {
}

impl Prepare for Commands {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
match self {
Commands::Lints(subcommand) => subcommand.prepare(sh, flags),
Commands::Doc(subcommand) => subcommand.prepare(sh, flags),
Commands::Compile(subcommand) => subcommand.prepare(sh, flags),

Commands::Format(subcommand) => subcommand.prepare(sh, flags),
Commands::Clippy(subcommand) => subcommand.prepare(sh, flags),
Commands::Test(subcommand) => subcommand.prepare(sh, flags),
Commands::TestCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::DocCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::DocTest(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileCheckNoStd(subcommand) => subcommand.prepare(sh, flags),
Commands::CompileFail(subcommand) => subcommand.prepare(sh, flags),
Commands::BenchCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::ExampleCheck(subcommand) => subcommand.prepare(sh, flags),
Commands::Lints(subcommand) => subcommand.prepare(sh, args),
Commands::Doc(subcommand) => subcommand.prepare(sh, args),
Commands::Compile(subcommand) => subcommand.prepare(sh, args),

Commands::Format(subcommand) => subcommand.prepare(sh, args),
Commands::Clippy(subcommand) => subcommand.prepare(sh, args),
Commands::Test(subcommand) => subcommand.prepare(sh, args),
Commands::TestCheck(subcommand) => subcommand.prepare(sh, args),
Commands::DocCheck(subcommand) => subcommand.prepare(sh, args),
Commands::DocTest(subcommand) => subcommand.prepare(sh, args),
Commands::CompileCheck(subcommand) => subcommand.prepare(sh, args),
Commands::CompileCheckNoStd(subcommand) => subcommand.prepare(sh, args),
Commands::CompileFail(subcommand) => subcommand.prepare(sh, args),
Commands::BenchCheck(subcommand) => subcommand.prepare(sh, args),
Commands::ExampleCheck(subcommand) => subcommand.prepare(sh, args),
}
}
}
4 changes: 2 additions & 2 deletions tools/ci/src/commands/bench_check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct BenchCheckCommand {}

impl Prepare for BenchCheckCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(
sh,
Expand Down
4 changes: 2 additions & 2 deletions tools/ci/src/commands/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct ClippyCommand {}

impl Prepare for ClippyCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(
sh,
Expand Down
15 changes: 8 additions & 7 deletions tools/ci/src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
args::Args,
commands::{
BenchCheckCommand, CompileCheckCommand, CompileFailCommand, ExampleCheckCommand,
TestCheckCommand,
},
Flag, Prepare, PreparedCommand,
Prepare, PreparedCommand,
};
use argh::FromArgs;

Expand All @@ -13,13 +14,13 @@ use argh::FromArgs;
pub struct CompileCommand {}

impl Prepare for CompileCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
let mut commands = vec![];
commands.append(&mut CompileFailCommand::default().prepare(sh, flags));
commands.append(&mut BenchCheckCommand::default().prepare(sh, flags));
commands.append(&mut ExampleCheckCommand::default().prepare(sh, flags));
commands.append(&mut CompileCheckCommand::default().prepare(sh, flags));
commands.append(&mut TestCheckCommand::default().prepare(sh, flags));
commands.append(&mut CompileFailCommand::default().prepare(sh, args));
commands.append(&mut BenchCheckCommand::default().prepare(sh, args));
commands.append(&mut ExampleCheckCommand::default().prepare(sh, args));
commands.append(&mut CompileCheckCommand::default().prepare(sh, args));
commands.append(&mut TestCheckCommand::default().prepare(sh, args));
commands
}
}
4 changes: 2 additions & 2 deletions tools/ci/src/commands/compile_check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct CompileCheckCommand {}

impl Prepare for CompileCheckCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(sh, "cargo check --workspace"),
"Please fix compiler errors in output above.",
Expand Down
4 changes: 2 additions & 2 deletions tools/ci/src/commands/compile_check_no_std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand Down Expand Up @@ -27,7 +27,7 @@ impl Default for CompileCheckNoStdCommand {
}

impl Prepare for CompileCheckNoStdCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
let target = self.target.as_str();
let mut commands = Vec::new();

Expand Down
8 changes: 4 additions & 4 deletions tools/ci/src/commands/compile_fail.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,9 +8,9 @@ use xshell::cmd;
pub struct CompileFailCommand {}

impl Prepare for CompileFailCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
let no_fail_fast = flags
.contains(Flag::KEEP_GOING)
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
let no_fail_fast = args
.keep_going
.then_some("--no-fail-fast")
.unwrap_or_default();

Expand Down
9 changes: 5 additions & 4 deletions tools/ci/src/commands/doc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
args::Args,
commands::{DocCheckCommand, DocTestCommand},
Flag, Prepare, PreparedCommand,
Prepare, PreparedCommand,
};
use argh::FromArgs;

Expand All @@ -10,10 +11,10 @@ use argh::FromArgs;
pub struct DocCommand {}

impl Prepare for DocCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
let mut commands = vec![];
commands.append(&mut DocTestCommand::default().prepare(sh, flags));
commands.append(&mut DocCheckCommand::default().prepare(sh, flags));
commands.append(&mut DocTestCommand::default().prepare(sh, args));
commands.append(&mut DocCheckCommand::default().prepare(sh, args));
commands
}
}
4 changes: 2 additions & 2 deletions tools/ci/src/commands/doc_check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct DocCheckCommand {}

impl Prepare for DocCheckCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(
sh,
Expand Down
18 changes: 13 additions & 5 deletions tools/ci/src/commands/doc_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,14 +8,22 @@ use xshell::cmd;
pub struct DocTestCommand {}

impl Prepare for DocTestCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
let no_fail_fast = flags
.contains(Flag::KEEP_GOING)
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
let no_fail_fast = args
.keep_going
.then_some("--no-fail-fast")
.unwrap_or_default();

let test_threads = args
.test_threads
.map(|test_threads| format!("--test-threads={test_threads}"))
.unwrap_or_default();

vec![PreparedCommand::new::<Self>(
cmd!(sh, "cargo test --workspace --doc {no_fail_fast}"),
cmd!(
sh,
"cargo test --workspace --doc {no_fail_fast} -- {test_threads}"
),
"Please fix failing doc tests in output above.",
)]
}
Expand Down
4 changes: 2 additions & 2 deletions tools/ci/src/commands/example_check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct ExampleCheckCommand {}

impl Prepare for ExampleCheckCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(sh, "cargo check --workspace --examples"),
"Please fix compiler errors for examples in output above.",
Expand Down
4 changes: 2 additions & 2 deletions tools/ci/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Flag, Prepare, PreparedCommand};
use crate::{args::Args, Prepare, PreparedCommand};
use argh::FromArgs;
use xshell::cmd;

Expand All @@ -8,7 +8,7 @@ use xshell::cmd;
pub struct FormatCommand {}

impl Prepare for FormatCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, _args: Args) -> Vec<PreparedCommand<'a>> {
vec![PreparedCommand::new::<Self>(
cmd!(sh, "cargo fmt --all -- --check"),
"Please run 'cargo fmt --all' to format your code.",
Expand Down
9 changes: 5 additions & 4 deletions tools/ci/src/commands/lints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
args::Args,
commands::{ClippyCommand, FormatCommand},
Flag, Prepare, PreparedCommand,
Prepare, PreparedCommand,
};
use argh::FromArgs;

Expand All @@ -10,10 +11,10 @@ use argh::FromArgs;
pub struct LintsCommand {}

impl Prepare for LintsCommand {
fn prepare<'a>(&self, sh: &'a xshell::Shell, flags: Flag) -> Vec<PreparedCommand<'a>> {
fn prepare<'a>(&self, sh: &'a xshell::Shell, args: Args) -> Vec<PreparedCommand<'a>> {
let mut commands = vec![];
commands.append(&mut FormatCommand::default().prepare(sh, flags));
commands.append(&mut ClippyCommand::default().prepare(sh, flags));
commands.append(&mut FormatCommand::default().prepare(sh, args));
commands.append(&mut ClippyCommand::default().prepare(sh, args));
commands
}
}
Loading