diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:13:39 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:13:39 +0800 |
| commit | 8ea8e13f1a6b2a2942b78127e23d6783c5188ca5 (patch) | |
| tree | 01cc8dde8cb8c90529c8d5f66dc57a08ed7cdc26 /mingling_ci/src/task | |
| parent | 570b2bc1710c0ab8a68ad69a6121144e4f5e3aca (diff) | |
refactor(ci-new): generalize report entries from packages to items
Rename package-based terminology and structures to item-based, allowing
arbitrary items with associated locations instead of only crate
packages.
Locations are now carried through report files and included in generated
reports, with the fallback to `—` removed.
Diffstat (limited to 'mingling_ci/src/task')
| -rw-r--r-- | mingling_ci/src/task/cmd_build.rs | 4 | ||||
| -rw-r--r-- | mingling_ci/src/task/cmd_clippy.rs | 4 | ||||
| -rw-r--r-- | mingling_ci/src/task/cmd_test.rs | 4 | ||||
| -rw-r--r-- | mingling_ci/src/task/run.rs | 30 |
4 files changed, 25 insertions, 17 deletions
diff --git a/mingling_ci/src/task/cmd_build.rs b/mingling_ci/src/task/cmd_build.rs index a74c323..f37699c 100644 --- a/mingling_ci/src/task/cmd_build.rs +++ b/mingling_ci/src/task/cmd_build.rs @@ -9,14 +9,14 @@ use mingling::{ use crate::Next; use crate::res::Manifests; -use crate::task::run::run_parallel_checks; +use crate::task::run::{location, run_parallel_checks}; #[command(node = "build-all")] pub async fn build_all(manifests: &Manifests) -> Next { let tasks = manifests .package_dirs .iter() - .map(|(name, path)| (name.clone(), build_args(path))) + .map(|(name, path)| (name.clone(), location(path), build_args(path))) .collect(); let fail_count = run_parallel_checks("Build-All", "Building", tasks).await; ResultBuildAll { fail_count }.to_chain() diff --git a/mingling_ci/src/task/cmd_clippy.rs b/mingling_ci/src/task/cmd_clippy.rs index 0a4282b..7256bef 100644 --- a/mingling_ci/src/task/cmd_clippy.rs +++ b/mingling_ci/src/task/cmd_clippy.rs @@ -9,14 +9,14 @@ use mingling::{ use crate::Next; use crate::res::Manifests; -use crate::task::run::run_parallel_checks; +use crate::task::run::{location, run_parallel_checks}; #[command(node = "clippy-all")] pub async fn clippy_all(manifests: &Manifests) -> Next { let tasks = manifests .package_dirs .iter() - .map(|(name, path)| (name.clone(), clippy_args(path))) + .map(|(name, path)| (name.clone(), location(path), clippy_args(path))) .collect(); let fail_count = run_parallel_checks("Clippy-All", "Clippy", tasks).await; ResultClippyAll { fail_count }.to_chain() diff --git a/mingling_ci/src/task/cmd_test.rs b/mingling_ci/src/task/cmd_test.rs index 3ed193c..5b9f55a 100644 --- a/mingling_ci/src/task/cmd_test.rs +++ b/mingling_ci/src/task/cmd_test.rs @@ -9,7 +9,7 @@ use mingling::{ use crate::Next; use crate::res::{Manifests, ResCrateConfig}; -use crate::task::run::run_parallel_checks; +use crate::task::run::{location, run_parallel_checks}; #[command(node = "test-all")] pub async fn test_all(manifests: &Manifests, config: &ResCrateConfig) -> Next { @@ -21,7 +21,7 @@ pub async fn test_all(manifests: &Manifests, config: &ResCrateConfig) -> Next { || test_args(path), |cmd| cmd.iter().map(|s| OsString::from(s.as_str())).collect(), ); - (name.clone(), args) + (name.clone(), location(path), args) }) .collect(); let fail_count = run_parallel_checks("Test-All", "Testing", tasks).await; diff --git a/mingling_ci/src/task/run.rs b/mingling_ci/src/task/run.rs index d00334d..bf83d3b 100644 --- a/mingling_ci/src/task/run.rs +++ b/mingling_ci/src/task/run.rs @@ -1,10 +1,18 @@ use std::ffi::OsString; +use std::path::Path; use colored::Colorize; use indicatif::{ProgressBar, ProgressStyle}; use crate::reporter::{self, ReportResult}; +/// The manifest's parent directory, e.g. `./mingling` — the report location +/// for a crate-based item. +pub(crate) fn location(path: &Path) -> String { + path.parent() + .map_or_else(|| ".".to_string(), |d| d.to_string_lossy().into_owned()) +} + /// Outcome of a `cargo` subcommand. struct CargoResult { ok: bool, @@ -14,13 +22,13 @@ struct CargoResult { /// Runs the given cargo task list in parallel. /// -/// Each task is a `(name, args)` pair; progress and failures go to stderr: a -/// failing task prints its output immediately and writes its report entry at -/// the same time. Returns the number of failing tasks. +/// Each task is an `(item, location, argv)` triple; progress and failures go +/// to stderr: a failing task prints its output immediately and writes its +/// report entry at the same time. Returns the number of failing tasks. pub(crate) async fn run_parallel_checks( task: &str, phase: &str, - tasks: Vec<(String, Vec<OsString>)>, + tasks: Vec<(String, String, Vec<OsString>)>, ) -> usize { reporter::set_task(task); @@ -39,20 +47,20 @@ pub(crate) async fn run_parallel_checks( // Run each task in parallel. let mut set = tokio::task::JoinSet::new(); - for (name, args) in tasks { - set.spawn(async move { (name, run_cargo(args).await) }); + for (item, location, args) in tasks { + set.spawn(async move { (item, location, run_cargo(args).await) }); } let mut fail_count = 0; while let Some(joined) = set.join_next().await { - let Ok((name, result)) = joined else { + let Ok((item, location, result)) = joined else { continue; }; pb.inc(1); - pb.set_message(name.clone()); + pb.set_message(item.clone()); if result.ok { - reporter::export(&name, ReportResult::Ok); + reporter::export(&item, &location, ReportResult::Ok); } else { fail_count += 1; // Failures print to stderr immediately (bar suspended to avoid @@ -61,7 +69,7 @@ pub(crate) async fn run_parallel_checks( eprintln!( "{}: {} failed{}", phase.bold().bright_cyan(), - name, + item, result .exit_code .map_or_else(String::new, |c| format!(" (exit code {c})")) @@ -70,7 +78,7 @@ pub(crate) async fn run_parallel_checks( eprintln!(" {line}"); } }); - reporter::export(&name, ReportResult::Error(result.output)); + reporter::export(&item, &location, ReportResult::Error(result.output)); } } |
