Skip to content

Commit 4b7c8e6

Browse files
committed
Group CI steps when running in GitHub actions
The output of `cargo xtask ci` is quite noisy and it can be hard to see exactly what has failed. This change adds GitHub actions workflow grouping to make it a bit easier to read. https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#grouping-log-lines
1 parent 5e1e7af commit 4b7c8e6

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

xtask/src/ci.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ fn install_targets() {
2525
/// Install global dependencies
2626
fn install_dependencies() {
2727
for dependency in DEPENDENCIES {
28-
let mut cargo = Command::new("cargo");
29-
cargo.args(&["install", dependency]);
30-
let status = cargo
31-
.status()
32-
.map_err(|e| format!("couldn't execute {:?}: {}", cargo, e))
33-
.unwrap();
34-
assert!(status.success(),);
28+
let exists = Command::new("which")
29+
.arg(dependency)
30+
.output()
31+
.expect("failed to execute");
32+
if !exists.status.success() {
33+
let mut cargo = Command::new("cargo");
34+
cargo.args(&["install", dependency]);
35+
let status = cargo
36+
.status()
37+
.map_err(|e| format!("couldn't execute {:?}: {}", cargo, e))
38+
.unwrap();
39+
assert!(status.success(),);
40+
}
3541
}
3642
}
3743

@@ -154,16 +160,35 @@ fn build_example(manifest_path: &path::PathBuf, feature: Option<String>, target:
154160
);
155161
}
156162

163+
fn start_group(is_ci: bool, name: &str) {
164+
if is_ci {
165+
println!("::group::{}", name);
166+
}
167+
}
168+
169+
fn end_group(is_ci: bool) {
170+
if is_ci {
171+
println!("::endgroup::");
172+
}
173+
}
174+
175+
fn wrap_in_group(is_ci: bool, name: &str, callable: &dyn Fn()) {
176+
start_group(is_ci, name);
177+
callable();
178+
end_group(is_ci);
179+
}
180+
157181
pub fn ci() {
158-
install_targets();
159-
install_dependencies();
182+
let is_ci = env::var("CI").map_or(false, |ci| ci == "true");
160183

161184
// move up if we're running from inside xtask
162185
if env::current_dir().unwrap().ends_with("xtask") {
163186
env::set_current_dir("..").unwrap();
164187
}
165188

166-
build_crates();
167-
build_run_doc_tests();
168-
build_examples();
189+
wrap_in_group(is_ci, "install targets", &install_targets);
190+
wrap_in_group(is_ci, "install dependencies", &install_dependencies);
191+
wrap_in_group(is_ci, "build crates", &build_crates);
192+
wrap_in_group(is_ci, "build examples", &build_examples);
193+
wrap_in_group(is_ci, "run doc tests", &build_run_doc_tests);
169194
}

0 commit comments

Comments
 (0)