Skip to content

Commit

Permalink
ci: Move lints into xtask
Browse files Browse the repository at this point in the history
Honestly just to reduce the code statistics; be nice to have
zero shell script in the repo 😃

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Jan 27, 2023
1 parent 7676574 commit dd2010e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
container: quay.io/coreos-assembler/fcos-buildroot:testing-devel
steps:
- uses: actions/checkout@v3
- name: Code lints
run: ./ci/lints.sh
- name: Install deps
run: ./ci/installdeps.sh
# xref containers/containers-image-proxy-rs
Expand All @@ -34,6 +32,8 @@ jobs:
run: cargo test --no-run
- name: Individual checks
run: (cd cli && cargo check) && (cd lib && cargo check)
- name: Lints
run: cargo xtask custom-lints
- name: Run tests
run: cargo test -- --nocapture --quiet
- name: Manpage generation
Expand Down
9 changes: 0 additions & 9 deletions ci/lints.sh

This file was deleted.

22 changes: 18 additions & 4 deletions xtask/src/xtask.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
use std::process::{Command, Stdio};

use anyhow::{Context, Result};
Expand All @@ -12,23 +12,25 @@ const VENDORPATH: &str = "target/vendor.tar.zstd";

fn main() {
if let Err(e) = try_main() {
eprintln!("{e:?}");
eprintln!("error: {e:?}");
std::process::exit(1);
}
}

const TASKS: &[(&'static str, fn(&Shell) -> Result<()>)] = &[
#[allow(clippy::type_complexity)]
const TASKS: &[(&str, fn(&Shell) -> Result<()>)] = &[
("vendor", vendor),
("package", package),
("package-srpm", package_srpm),
("custom-lints", custom_lints),
];

fn try_main() -> Result<()> {
let task = std::env::args().nth(1);
let sh = xshell::Shell::new()?;
if let Some(cmd) = task.as_deref() {
let f = TASKS
.into_iter()
.iter()
.find_map(|(k, f)| (*k == cmd).then_some(*f))
.unwrap_or(print_help);
f(&sh)?;
Expand Down Expand Up @@ -170,6 +172,18 @@ fn package_srpm(sh: &Shell) -> Result<()> {
Ok(())
}

fn custom_lints(sh: &Shell) -> Result<()> {
// Verify there are no invocations of the dbg macro.
let o = cmd!(sh, "git grep dbg\x21 *.rs").ignore_status().read()?;
if !o.is_empty() {
let mut stderr = std::io::stderr().lock();
std::io::copy(&mut Cursor::new(o.as_bytes()), &mut stderr)?;
eprintln!();
anyhow::bail!("Found dbg\x21 macro");
}
Ok(())
}

fn print_help(_sh: &Shell) -> Result<()> {
println!("Tasks:");
for (name, _) in TASKS {
Expand Down

0 comments on commit dd2010e

Please sign in to comment.