Consolidate required CI gate (#115)
All checks were successful
CI / required (push) Successful in 3m55s
All checks were successful
CI / required (push) Successful in 3m55s
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use metacrate_ci_matrix::{
|
||||
audit, audit_api_surface, audit_artifacts, audit_dependencies, audit_documentation,
|
||||
audit_provenance, audit_release_candidate, load, run, workspace_root, write_api_baseline,
|
||||
write_documentation_report, write_provenance_reports,
|
||||
audit, audit_api_surface, audit_artifacts, audit_consolidated_ci, audit_dependencies,
|
||||
audit_documentation, audit_provenance, audit_release_candidate, load, run, run_release_gate,
|
||||
run_required_gate, workspace_root, write_api_baseline, write_documentation_report,
|
||||
write_provenance_reports,
|
||||
};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -12,12 +13,23 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)] // Flat CLI command routing is clearer than nested dispatch.
|
||||
fn execute() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let current = std::env::current_dir()?;
|
||||
let root = workspace_root(¤t).ok_or("could not locate the Cargo workspace")?;
|
||||
let matrix = load(&root)?;
|
||||
let mut arguments = std::env::args().skip(1);
|
||||
match arguments.next().as_deref() {
|
||||
Some("ci-audit") if arguments.next().is_none() => {
|
||||
audit_consolidated_ci(&root)?;
|
||||
println!("consolidated CI coverage and workflow split: ok");
|
||||
}
|
||||
Some("required-gate") => {
|
||||
gate_command(&root, arguments, "required", run_required_gate)?;
|
||||
}
|
||||
Some("release-gate") => {
|
||||
gate_command(&root, arguments, "release", run_release_gate)?;
|
||||
}
|
||||
Some("audit") if arguments.next().is_none() => {
|
||||
audit(&root, &matrix)?;
|
||||
println!(
|
||||
@@ -101,7 +113,7 @@ fn execute() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
_ => {
|
||||
return Err(
|
||||
"usage: ci-matrix audit | run PROFILE --evidence FILE | dependency-audit --evidence FILE | artifact-audit --artifact-dir DIR --package-dir DIR --evidence FILE | release-candidate-audit --evidence FILE | documentation-report | documentation-audit --evidence FILE | api-baseline-write | api-audit --evidence FILE | provenance-report | provenance-audit --evidence FILE"
|
||||
"usage: ci-matrix ci-audit | required-gate --evidence FILE | release-gate --evidence FILE | audit | run PROFILE --evidence FILE | dependency-audit --evidence FILE | artifact-audit --artifact-dir DIR --package-dir DIR --evidence FILE | release-candidate-audit --evidence FILE | documentation-report | documentation-audit --evidence FILE | api-baseline-write | api-audit --evidence FILE | provenance-report | provenance-audit --evidence FILE"
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
@@ -109,6 +121,27 @@ fn execute() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn gate_command(
|
||||
root: &Path,
|
||||
mut arguments: impl Iterator<Item = String>,
|
||||
gate: &str,
|
||||
run_gate: fn(&Path, &Path) -> metacrate_ci_matrix::Result<()>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let flag = arguments
|
||||
.next()
|
||||
.ok_or_else(|| format!("{gate}-gate requires --evidence FILE"))?;
|
||||
let evidence = arguments
|
||||
.next()
|
||||
.ok_or_else(|| format!("{gate}-gate requires --evidence FILE"))?;
|
||||
if flag != "--evidence" || arguments.next().is_some() {
|
||||
return Err(format!("usage: ci-matrix {gate}-gate --evidence FILE").into());
|
||||
}
|
||||
let evidence = absolute_or_rooted(root, &evidence);
|
||||
run_gate(root, &evidence)?;
|
||||
println!("{gate} CI gate: ok ({})", evidence.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn release_candidate_audit_command(
|
||||
root: &Path,
|
||||
mut arguments: impl Iterator<Item = String>,
|
||||
|
||||
Reference in New Issue
Block a user