use super::super::args::RunArgs;
use super::pipeline::{execute_pipeline, PipelineInput};
use super::pipeline_error::elapsed_ms;
use super::reporting::{
build_summary_from_artifacts, maybe_export_baseline, print_pipeline_summary,
};
use super::run_output::write_extended_run_json;
use std::path::PathBuf;
use std::time::Instant;
pub(crate) async fn run(args: RunArgs, legacy_mode: bool) -> anyhow::Result<i32> {
let version = args.exit_codes;
let run_json_path = PathBuf::from("run.json");
let input = PipelineInput::from_run(&args);
let execution = match execute_pipeline(&input, legacy_mode).await {
Ok(ok) => ok,
Err(e) => return e.into_exit_code(version, !args.no_verify, &run_json_path),
};
let cfg = execution.cfg;
let artifacts = execution.artifacts;
let outcome = execution.outcome;
let timings = execution.timings;
let report_start = Instant::now();
write_extended_run_json(&artifacts, &outcome, &run_json_path, None)?;
let summary_path = run_json_path
.parent()
.map(|p| p.join("summary.json"))
.unwrap_or_else(|| PathBuf::from("summary.json"));
let mut summary =
build_summary_from_artifacts(&outcome, !args.no_verify, &artifacts, Some(&timings), None);
match args.format {
super::super::args::OutputFormat::Text => {
print_pipeline_summary(&artifacts, args.explain_skip, &summary);
}
super::super::args::OutputFormat::Json => {
println!("{}", assay_core::report::json::render_json(&artifacts)?);
}
}
maybe_export_baseline(&args.export_baseline, &args.config, &cfg, &artifacts);
let report_ms = elapsed_ms(report_start);
summary = build_summary_from_artifacts(
&outcome,
!args.no_verify,
&artifacts,
Some(&timings),
Some(report_ms),
);
assay_core::report::summary::write_summary(&summary, &summary_path)?;
Ok(outcome.exit_code)
}