Skip to content

Commit 5ba1f64

Browse files
authored
Merge pull request #44 from cgwalters/xtask-lint-dbg
ci: Move lints into xtask
2 parents a972723 + dd2010e commit 5ba1f64

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ jobs:
2121
container: quay.io/coreos-assembler/fcos-buildroot:testing-devel
2222
steps:
2323
- uses: actions/checkout@v3
24-
- name: Code lints
25-
run: ./ci/lints.sh
2624
- name: Install deps
2725
run: ./ci/installdeps.sh
2826
# xref containers/containers-image-proxy-rs
@@ -34,6 +32,8 @@ jobs:
3432
run: cargo test --no-run
3533
- name: Individual checks
3634
run: (cd cli && cargo check) && (cd lib && cargo check)
35+
- name: Lints
36+
run: cargo xtask custom-lints
3737
- name: Run tests
3838
run: cargo test -- --nocapture --quiet
3939
- name: Manpage generation

ci/lints.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

xtask/src/xtask.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fs::File;
2-
use std::io::{BufRead, BufReader, BufWriter, Write};
2+
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
33
use std::process::{Command, Stdio};
44

55
use anyhow::{Context, Result};
@@ -12,21 +12,27 @@ const VENDORPATH: &str = "target/vendor.tar.zstd";
1212

1313
fn main() {
1414
if let Err(e) = try_main() {
15-
eprintln!("{e:?}");
15+
eprintln!("error: {e:?}");
1616
std::process::exit(1);
1717
}
1818
}
1919

20+
#[allow(clippy::type_complexity)]
21+
const TASKS: &[(&str, fn(&Shell) -> Result<()>)] = &[
22+
("vendor", vendor),
23+
("package", package),
24+
("package-srpm", package_srpm),
25+
("custom-lints", custom_lints),
26+
];
27+
2028
fn try_main() -> Result<()> {
2129
let task = std::env::args().nth(1);
2230
let sh = xshell::Shell::new()?;
2331
if let Some(cmd) = task.as_deref() {
24-
let f = match cmd {
25-
"vendor" => vendor,
26-
"package" => package,
27-
"package-srpm" => package_srpm,
28-
_ => print_help,
29-
};
32+
let f = TASKS
33+
.iter()
34+
.find_map(|(k, f)| (*k == cmd).then_some(*f))
35+
.unwrap_or(print_help);
3036
f(&sh)?;
3137
} else {
3238
print_help(&sh)?;
@@ -166,11 +172,22 @@ fn package_srpm(sh: &Shell) -> Result<()> {
166172
Ok(())
167173
}
168174

175+
fn custom_lints(sh: &Shell) -> Result<()> {
176+
// Verify there are no invocations of the dbg macro.
177+
let o = cmd!(sh, "git grep dbg\x21 *.rs").ignore_status().read()?;
178+
if !o.is_empty() {
179+
let mut stderr = std::io::stderr().lock();
180+
std::io::copy(&mut Cursor::new(o.as_bytes()), &mut stderr)?;
181+
eprintln!();
182+
anyhow::bail!("Found dbg\x21 macro");
183+
}
184+
Ok(())
185+
}
186+
169187
fn print_help(_sh: &Shell) -> Result<()> {
170-
eprintln!(
171-
"Tasks:
172-
- vendor
173-
"
174-
);
188+
println!("Tasks:");
189+
for (name, _) in TASKS {
190+
println!(" - {name}");
191+
}
175192
Ok(())
176193
}

0 commit comments

Comments
 (0)