diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 09:32:47 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 09:32:47 +0800 |
| commit | 3b56d50c16cf86429de9bf82b717ad4c13d7f968 (patch) | |
| tree | 233fd04ff127e42cd0315c634504a30d20506ced | |
| parent | fcdbc57ad135ad134f4f0cb9ea127a24098b7fdb (diff) | |
chore(ci-new): replace progress system with indicatif
| -rw-r--r-- | mingling_ci/Cargo.lock | 154 | ||||
| -rw-r--r-- | mingling_ci/Cargo.toml | 1 | ||||
| -rw-r--r-- | mingling_ci/src/bin/ci.rs | 27 | ||||
| -rw-r--r-- | mingling_ci/src/task/run.rs | 99 |
4 files changed, 224 insertions, 57 deletions
diff --git a/mingling_ci/Cargo.lock b/mingling_ci/Cargo.lock index 8187736..538b06c 100644 --- a/mingling_ci/Cargo.lock +++ b/mingling_ci/Cargo.lock @@ -24,6 +24,12 @@ dependencies = [ ] [[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] name = "bytes" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -45,6 +51,18 @@ dependencies = [ ] [[package]] +name = "console" +version = "0.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fe5f465a4f6fee88fad41b85d990f84c835335e85b5d9e6e63e0d06d28cba7c" +dependencies = [ + "encode_unicode", + "libc", + "unicode-width 0.2.2", + "windows-sys", +] + +[[package]] name = "csv" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -109,6 +127,30 @@ dependencies = [ ] [[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] name = "getrandom" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -142,6 +184,19 @@ dependencies = [ ] [[package]] +name = "indicatif" +version = "0.18.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9433806cd6b4ec1aba79c021c7e4c58fb4c3b9977c085062e611ac929998fb0c" +dependencies = [ + "console", + "portable-atomic", + "unicode-width 0.2.2", + "unit-prefix", + "web-time", +] + +[[package]] name = "is-terminal" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -159,6 +214,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] name = "just_fmt" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -255,6 +321,7 @@ name = "mingling-ci-system" version = "0.1.0" dependencies = [ "colored", + "indicatif", "just_progress", "just_template", "mingling", @@ -309,12 +376,24 @@ dependencies = [ ] [[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] name = "pin-project-lite" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] name = "prettytable-rs" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -325,7 +404,7 @@ dependencies = [ "is-terminal", "lazy_static", "term", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -418,6 +497,12 @@ dependencies = [ ] [[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] name = "syn" version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -550,12 +635,79 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unit-prefix" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3" + +[[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/mingling_ci/Cargo.toml b/mingling_ci/Cargo.toml index 5db7c97..5de752a 100644 --- a/mingling_ci/Cargo.toml +++ b/mingling_ci/Cargo.toml @@ -24,6 +24,7 @@ mingling = { version = "0.4.0", features = [ just_progress = "0.1.3" colored = "3.1.1" +indicatif = "0.18.4" tokio = { version = "1.53.1", features = [ "rt", "rt-multi-thread", diff --git a/mingling_ci/src/bin/ci.rs b/mingling_ci/src/bin/ci.rs index e823000..98e0fd5 100644 --- a/mingling_ci/src/bin/ci.rs +++ b/mingling_ci/src/bin/ci.rs @@ -1,34 +1,15 @@ -use just_progress::{ - progress::{self}, - renderer::ProgressSimpleRenderer, +use mingling::setup::{ + ConfirmSetup, DirectoryEnvironmentSetup, ExitCodeSetup, + picker::{ConfirmFlagSetup, HelpFlagSetup, QuietFlagSetup}, }; -use mingling::{ - hook::ProgramHook, - setup::{ - ConfirmSetup, DirectoryEnvironmentSetup, ExitCodeSetup, - picker::{ConfirmFlagSetup, HelpFlagSetup, QuietFlagSetup}, - }, -}; -use tokio::join; use mingling_ci_system::ThisProgram; use mingling_ci_system::res::*; #[tokio::main] async fn main() { - let center = progress::init(); - let renderer = ProgressSimpleRenderer::new().with_subprogress(true); - let bind = progress::bind(center, move |name, state| renderer.update(name, state)); - - let (_, exit_code) = join!(bind, mingling_ci_begin()); - std::process::exit(exit_code); -} - -async fn mingling_ci_begin() -> i32 { let mut program = ThisProgram::new(); - program.with_hook(ProgramHook::empty().on_finish(|_| progress::close())); - // Plugins program.with_setup(ExitCodeSetup::default()); program.with_setup(DirectoryEnvironmentSetup::default()); @@ -44,5 +25,5 @@ async fn mingling_ci_begin() -> i32 { program.with_setup(FeaturesSetup); program.with_setup(ReportSetup); - program.exec().await + program.exec_and_exit().await; } diff --git a/mingling_ci/src/task/run.rs b/mingling_ci/src/task/run.rs index 1017677..db34277 100644 --- a/mingling_ci/src/task/run.rs +++ b/mingling_ci/src/task/run.rs @@ -1,25 +1,44 @@ use std::ffi::OsString; use std::path::Path; -use just_progress::progress::{self, ProgressInfo}; +use colored::Colorize; +use indicatif::{ProgressBar, ProgressStyle}; use crate::reporter::{self, ReportResult}; use crate::res::Manifests; -/// Runs one `cargo` subcommand per manifest in parallel, reporting each -/// outcome via `reporter` after the whole round finishes. +/// Outcome of a `cargo` subcommand. +struct CargoResult { + ok: bool, + exit_code: Option<i32>, + output: String, +} + +/// Runs one `cargo` subcommand per manifest in parallel. /// -/// Only output is the progress bar; returns the number of failing packages. -#[allow(clippy::cast_precision_loss)] // counts are small +/// Progress and failures go to stderr: a failing package prints its output +/// immediately and writes its report entry at the same time. Returns the +/// number of failing packages. pub(crate) async fn run_parallel_checks( task: &str, - status: &'static str, + phase: &str, args_for: fn(&Path) -> Vec<OsString>, manifests: &Manifests, ) -> usize { reporter::set_task(task); - let total = manifests.package_dirs.len(); - progress::update(task, 0.0, ProgressInfo::Info(status)); + + let n = manifests.package_dirs.len(); + let pb = ProgressBar::new(n as u64); + let padding = " ".repeat(12usize.saturating_sub(phase.len())); + let styled_prefix = format!("{}{}", padding, phase.bold().bright_cyan()); + pb.set_style( + ProgressStyle::default_bar() + .template(&format!( + "{styled_prefix} [{{bar:28}}] {{pos}}/{{len}}: {{msg}}" + )) + .unwrap() + .progress_chars("=> "), + ); // Run one cargo invocation per manifest in parallel. let mut set = tokio::task::JoinSet::new(); @@ -29,37 +48,43 @@ pub(crate) async fn run_parallel_checks( set.spawn(async move { (name, run_cargo(args).await) }); } - // Collect all outcomes first, then dump the report files in one round. - let mut results: Vec<(String, ReportResult)> = Vec::new(); - let mut done = 0; + let mut fail_count = 0; while let Some(joined) = set.join_next().await { - done += 1; - let Ok((name, (ok, output))) = joined else { + let Ok((name, result)) = joined else { continue; }; - progress::update(task, done as f32 / total as f32, ProgressInfo::Info(status)); - results.push(( - name, - if ok { - ReportResult::Ok - } else { - ReportResult::Error(output) - }, - )); - } + pb.inc(1); + pb.set_message(name.clone()); - let fail_count = results - .iter() - .filter(|(_, r)| matches!(r, ReportResult::Error(_))) - .count(); - for (name, result) in results { - reporter::export(&name, result); + if result.ok { + reporter::export(&name, ReportResult::Ok); + } else { + fail_count += 1; + // Failures print to stderr immediately (bar suspended to avoid + // interleaving) and write their report entry at the same time. + pb.suspend(|| { + eprintln!( + "{}: {} failed{}", + phase.bold().bright_cyan(), + name, + result + .exit_code + .map_or_else(String::new, |c| format!(" (exit code {c})")) + ); + for line in result.output.lines() { + eprintln!(" {line}"); + } + }); + reporter::export(&name, ReportResult::Error(result.output)); + } } + + pb.finish_and_clear(); fail_count } -/// Runs a `cargo` subcommand, returning success and captured output. -async fn run_cargo(args: Vec<OsString>) -> (bool, String) { +/// Runs a `cargo` subcommand, capturing its output. +async fn run_cargo(args: Vec<OsString>) -> CargoResult { let output = tokio::process::Command::new("cargo") .args(args) .output() @@ -68,8 +93,16 @@ async fn run_cargo(args: Vec<OsString>) -> (bool, String) { Ok(output) => { let mut log = String::from_utf8_lossy(&output.stdout).into_owned(); log.push_str(&String::from_utf8_lossy(&output.stderr)); - (output.status.success(), log) + CargoResult { + ok: output.status.success(), + exit_code: output.status.code(), + output: log, + } } - Err(e) => (false, format!("failed to run cargo: {e}")), + Err(e) => CargoResult { + ok: false, + exit_code: None, + output: format!("failed to run cargo: {e}"), + }, } } |
