cargo-governor 1.2.0

Machine-First, LLM-Ready, CI/CD-Native release automation tool for Rust crates
Documentation
//! Pre-publish checks

use crate::error::Result;
use std::path::PathBuf;

/// Run a single pre-publish check
pub fn run_check(workspace_path: &str, check: &str) -> Result<()> {
    let args = match check {
        "test" => &["cargo", "test", "--all-features"][..],
        "clippy" => &[
            "cargo",
            "clippy",
            "--all-targets",
            "--all-features",
            "--",
            "-D",
            "warnings",
        ][..],
        "fmt" => &["cargo", "fmt", "--check"][..],
        "doc" => &["cargo", "doc", "--no-deps", "--all-features"][..],
        "build" => &["cargo", "build", "--all-features"][..],
        _ => {
            return Err(crate::error::Error::Config(format!(
                "Unknown check: {check}"
            )));
        }
    };
    run_command(workspace_path, args)?;
    Ok(())
}

/// Run a command in the workspace
fn run_command(workspace_path: &str, args: &[&str]) -> Result<std::process::ExitStatus> {
    use command_group::CommandGroup;

    let output = std::process::Command::new(args[0])
        .args(&args[1..])
        .current_dir(PathBuf::from(workspace_path))
        .group_spawn()
        .map_err(|e| crate::error::Error::Io(format!("Failed to spawn {args:?}: {e}")))?
        .wait()
        .map_err(|e| crate::error::Error::Io(format!("Failed to wait for {args:?}: {e}")))?;

    if output.success() {
        Ok(output)
    } else {
        Err(crate::error::Error::CheckFailed(format!(
            "Command {:?} failed with exit code {:?}",
            args,
            output.code()
        )))
    }
}