diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:59:46 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-18 10:59:46 +0800 |
| commit | 78776ff4a91c470f075aa5148e48c02ca6e4d050 (patch) | |
| tree | b072f4ca72679be50c1fe155b1651ded82cad4e7 /mingling_ci | |
| parent | b47a1fb1dd5b82ba14bcf8589c5b2a604569bf19 (diff) | |
refactor(ci-new): extract shared task progress bar helper
Diffstat (limited to 'mingling_ci')
| -rw-r--r-- | mingling_ci/src/cmd/cmd_test_examples.rs | 13 | ||||
| -rw-r--r-- | mingling_ci/src/lib.rs | 1 | ||||
| -rw-r--r-- | mingling_ci/src/markdown/test.rs | 14 | ||||
| -rw-r--r-- | mingling_ci/src/progress.rs | 24 | ||||
| -rw-r--r-- | mingling_ci/src/task/run.rs | 15 |
5 files changed, 33 insertions, 34 deletions
diff --git a/mingling_ci/src/cmd/cmd_test_examples.rs b/mingling_ci/src/cmd/cmd_test_examples.rs index 2b5526f..602ada3 100644 --- a/mingling_ci/src/cmd/cmd_test_examples.rs +++ b/mingling_ci/src/cmd/cmd_test_examples.rs @@ -1,5 +1,4 @@ use colored::Colorize; -use indicatif::{ProgressBar, ProgressStyle}; use mingling::{ Grouped, Routable, macros::{buffer, command, renderer}, @@ -8,6 +7,7 @@ use mingling::{ use crate::Next; use crate::examples::{check_example, load_test_configs}; +use crate::progress::task_progress_bar; use crate::reporter::{self, ReportResult}; #[command(node = "test-examples")] @@ -16,16 +16,7 @@ pub async fn test_examples() -> Next { let configs = load_test_configs(); let total = configs.len(); - let pb = ProgressBar::new(total as u64); - pb.set_style( - ProgressStyle::default_bar() - .template(&format!( - "{} [{{bar:28}}] {{pos}}/{{len}}: {{msg}}", - " Testing".bold().bright_cyan() - )) - .unwrap() - .progress_chars("=> "), - ); + let pb = task_progress_bar(total, "Testing"); pb.set_message("examples"); // One blocking task per example: build + run its test cases. diff --git a/mingling_ci/src/lib.rs b/mingling_ci/src/lib.rs index 3a3ffff..fad8d72 100644 --- a/mingling_ci/src/lib.rs +++ b/mingling_ci/src/lib.rs @@ -16,6 +16,7 @@ pub mod reporter; pub(crate) mod examples; pub(crate) mod markdown; +pub(crate) mod progress; #[help] pub fn render_fallback(_: EntryFallback) -> String { diff --git a/mingling_ci/src/markdown/test.rs b/mingling_ci/src/markdown/test.rs index f8bd1f7..8ecf18d 100644 --- a/mingling_ci/src/markdown/test.rs +++ b/mingling_ci/src/markdown/test.rs @@ -4,7 +4,8 @@ use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use colored::Colorize; -use indicatif::{ProgressBar, ProgressStyle}; + +use crate::progress::task_progress_bar; use super::project::{ MarkdownTestProject, generate_build_rs, generate_cargo_toml, generate_main_rs, @@ -37,16 +38,7 @@ pub(crate) async fn try_test_markdown_project( } let total: usize = groups.values().map(Vec::len).sum(); - let pb = ProgressBar::new(total as u64); - pb.set_style( - ProgressStyle::default_bar() - .template(&format!( - "{} [{{bar:28}}] {{pos}}/{{len}}: {{msg}}", - " Testing".bold().bright_cyan() - )) - .unwrap() - .progress_chars("=> "), - ); + let pb = task_progress_bar(total, "Testing"); pb.set_message("blocks"); // One blocking task per group; blocks within a group are serial because diff --git a/mingling_ci/src/progress.rs b/mingling_ci/src/progress.rs new file mode 100644 index 0000000..bd62ae1 --- /dev/null +++ b/mingling_ci/src/progress.rs @@ -0,0 +1,24 @@ +//! Shared task progress bar. + +use colored::Colorize; +use indicatif::{ProgressBar, ProgressStyle}; + +/// Creates a task progress bar with the CI's standard style. +/// +/// `prefix` is the phase label shown before the bar, right-aligned to 12 +/// columns (e.g. `Building`, `Clippy`, `Testing`). The caller sets the +/// initial message and drives the position. +pub(crate) fn task_progress_bar(len: usize, prefix: &str) -> ProgressBar { + let padding = " ".repeat(12usize.saturating_sub(prefix.len())); + let styled_prefix = format!("{padding}{}", prefix.bold().bright_cyan()); + let pb = ProgressBar::new(len as u64); + pb.set_style( + ProgressStyle::default_bar() + .template(&format!( + "{styled_prefix} [{{bar:28}}] {{pos}}/{{len}}: {{msg}}" + )) + .unwrap() + .progress_chars("=> "), + ); + pb +} diff --git a/mingling_ci/src/task/run.rs b/mingling_ci/src/task/run.rs index bf83d3b..ba752dd 100644 --- a/mingling_ci/src/task/run.rs +++ b/mingling_ci/src/task/run.rs @@ -2,8 +2,8 @@ use std::ffi::OsString; use std::path::Path; use colored::Colorize; -use indicatif::{ProgressBar, ProgressStyle}; +use crate::progress::task_progress_bar; use crate::reporter::{self, ReportResult}; /// The manifest's parent directory, e.g. `./mingling` — the report location @@ -33,17 +33,8 @@ pub(crate) async fn run_parallel_checks( reporter::set_task(task); let n = tasks.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("=> "), - ); + let pb = task_progress_bar(n, phase); + pb.set_message("tasks"); // Run each task in parallel. let mut set = tokio::task::JoinSet::new(); |
