-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmain.rs
More file actions
65 lines (49 loc) · 1.58 KB
/
Copy pathmain.rs
File metadata and controls
65 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Collection of repo-specific CI checks.
use std::{path::PathBuf, process::Command, str::FromStr};
use clap::Parser;
mod lints_enabled;
/// Run CI checks on all crates.
#[derive(clap::Parser)]
pub struct Args {
/// Set the directory to treat as the repo root.
///
/// If omitted, shells out to `git rev-parse --show-toplevel` from the cwd.
#[clap(long, short)]
root: Option<PathBuf>,
}
/// Alias for a check function, which performs some check on the repo and may return an
/// error.
pub type CheckFn = fn(&Args) -> BoxResult<()>;
/// The set of check fns to run.
pub const CHECK_FNS: &[(&str, CheckFn)] = &[("lints_enabled", lints_enabled::run)];
/// Convenience alias for `Result` with a boxed `std::error::Error`.
pub type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;
/// Return the path to the root of the repo by shelling out to `git rev-parse`.
pub fn repo_root() -> BoxResult<PathBuf> {
let output = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.output()?;
let s = core::str::from_utf8(&output.stdout)?.trim();
let path = PathBuf::from_str(s)?;
Ok(path)
}
fn main() {
let args = Args::parse();
let root = args
.root
.clone()
.ok_or("no root")
.or_else(|_| repo_root())
.unwrap();
std::env::set_current_dir(&root).unwrap();
let mut failed = false;
for (name, f) in CHECK_FNS {
if let Err(e) = f(&args) {
failed = true;
eprintln!("check {name}: {e}");
}
}
if failed {
std::process::exit(1);
}
}