Skip to content

Commit 78c9225

Browse files
authored
Small CI tool improvements (#12841)
# Objective - The CI tool is slowly getting more difficult to maintain and could use a bit of refactoring. ## Solution - Do a first pass of small improvements. ## For Reviewers This PR is best reviewed commit-by-commit, because I separate it into a collection of small changes. :)
1 parent 11817f4 commit 78c9225

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

tools/ci/src/main.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
//! CI script used for Bevy.
22
33
use bitflags::bitflags;
4-
use core::panic;
54
use std::collections::BTreeMap;
65
use xshell::{cmd, Cmd, Shell};
76

87
bitflags! {
8+
/// A collection of individual checks that can be run in CI.
99
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
1010
struct Check: u32 {
11-
const FORMAT = 0b00000001;
12-
const CLIPPY = 0b00000010;
13-
const COMPILE_FAIL = 0b00000100;
14-
const TEST = 0b00001000;
15-
const DOC_TEST = 0b00010000;
16-
const DOC_CHECK = 0b00100000;
17-
const BENCH_CHECK = 0b01000000;
18-
const EXAMPLE_CHECK = 0b10000000;
19-
const COMPILE_CHECK = 0b100000000;
20-
const CFG_CHECK = 0b1000000000;
21-
const TEST_CHECK = 0b10000000000;
11+
const FORMAT = 1 << 0;
12+
const CLIPPY = 1 << 1;
13+
const COMPILE_FAIL = 1 << 2;
14+
const TEST = 1 << 3;
15+
const DOC_TEST = 1 << 4;
16+
const DOC_CHECK = 1 << 5;
17+
const BENCH_CHECK = 1 << 6;
18+
const EXAMPLE_CHECK = 1 << 7;
19+
const COMPILE_CHECK = 1 << 8;
20+
const CFG_CHECK = 1 << 9;
21+
const TEST_CHECK = 1 << 10;
2222
}
23-
}
2423

25-
bitflags! {
24+
/// A collection of flags that can modify how checks are run.
2625
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2726
struct Flag: u32 {
28-
const KEEP_GOING = 0b00000001;
27+
/// Forces certain checks to continue running even if they hit an error.
28+
const KEEP_GOING = 1 << 0;
2929
}
3030
}
3131

@@ -80,27 +80,30 @@ fn main() {
8080
// the executable, so it is ignored. Any parameter may either be a flag or the name of a battery of tests
8181
// to include.
8282
let (mut checks, mut flags) = (Check::empty(), Flag::empty());
83+
84+
// Skip first argument, which is usually the path of the executable.
8385
for arg in std::env::args().skip(1) {
84-
if let Some((_, flag)) = flag_arguments.iter().find(|(flag_arg, _)| *flag_arg == arg) {
85-
flags.insert(*flag);
86-
continue;
87-
}
8886
if let Some((_, check)) = arguments.iter().find(|(check_arg, _)| *check_arg == arg) {
8987
// Note that this actually adds all of the constituent checks to the test suite.
9088
checks.insert(*check);
91-
continue;
89+
} else if let Some((_, flag)) = flag_arguments.iter().find(|(flag_arg, _)| *flag_arg == arg)
90+
{
91+
flags.insert(*flag);
92+
} else {
93+
// We encountered an invalid parameter:
94+
eprintln!(
95+
"Invalid argument: {arg:?}.\n\
96+
Valid parameters: {}.",
97+
// Skip first argument so it can be added in fold(), when displaying as a comma separated list.
98+
arguments[1..]
99+
.iter()
100+
.map(|(s, _)| s)
101+
.chain(flag_arguments.iter().map(|(s, _)| s))
102+
.fold(arguments[0].0.to_owned(), |c, v| c + ", " + v)
103+
);
104+
105+
return;
92106
}
93-
// We encountered an invalid parameter:
94-
println!(
95-
"Invalid argument: {arg:?}.\n\
96-
Valid parameters: {}.",
97-
arguments[1..]
98-
.iter()
99-
.map(|(s, _)| s)
100-
.chain(flag_arguments.iter().map(|(s, _)| s))
101-
.fold(arguments[0].0.to_owned(), |c, v| c + ", " + v)
102-
);
103-
return;
104107
}
105108

106109
// If no checks are specified, we run every check

0 commit comments

Comments
 (0)