From b1102be2682feb2d2182ead0fcc7ce12f8d0c865 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 18 Aug 2026 11:09:23 +0800 Subject: refactor(mingling_ci): rename build, clippy, and docs commands to -check suffix --- mingling_ci/help.txt | 8 ++-- mingling_ci/src/cmd.rs | 2 - mingling_ci/src/cmd/cmd_docs_build.rs | 44 -------------------- mingling_ci/src/cmd/cmd_test_examples.rs | 69 ------------------------------- mingling_ci/src/task.rs | 7 +++- mingling_ci/src/task/cmd_build.rs | 47 --------------------- mingling_ci/src/task/cmd_build_check.rs | 47 +++++++++++++++++++++ mingling_ci/src/task/cmd_clippy.rs | 50 ---------------------- mingling_ci/src/task/cmd_clippy_check.rs | 50 ++++++++++++++++++++++ mingling_ci/src/task/cmd_docs_check.rs | 44 ++++++++++++++++++++ mingling_ci/src/task/cmd_example_check.rs | 69 +++++++++++++++++++++++++++++++ 11 files changed, 219 insertions(+), 218 deletions(-) delete mode 100644 mingling_ci/src/cmd/cmd_docs_build.rs delete mode 100644 mingling_ci/src/cmd/cmd_test_examples.rs delete mode 100644 mingling_ci/src/task/cmd_build.rs create mode 100644 mingling_ci/src/task/cmd_build_check.rs delete mode 100644 mingling_ci/src/task/cmd_clippy.rs create mode 100644 mingling_ci/src/task/cmd_clippy_check.rs create mode 100644 mingling_ci/src/task/cmd_docs_check.rs create mode 100644 mingling_ci/src/task/cmd_example_check.rs diff --git a/mingling_ci/help.txt b/mingling_ci/help.txt index de85c89..9d80d2f 100644 --- a/mingling_ci/help.txt +++ b/mingling_ci/help.txt @@ -19,8 +19,8 @@ COMMANDS: markdown-check-all Verify rust code blocks in all configured markdown files markdown-compare Compare the structure of two markdown files/dirs markdown-compare-all Compare all translated docs against the reference - build-all Build all crates - clippy-all Run clippy with -D warnings on all crates + build-check Build all crates + clippy-check Run clippy with -D warnings on all crates test-all Test all crates - test-examples Build examples and run their test.toml cases - docs-build Build mingling docs with -D warnings + example-check Build examples and run their test.toml cases + docs-check Build mingling docs with -D warnings diff --git a/mingling_ci/src/cmd.rs b/mingling_ci/src/cmd.rs index 3b057af..30d65a1 100644 --- a/mingling_ci/src/cmd.rs +++ b/mingling_ci/src/cmd.rs @@ -1,6 +1,4 @@ -pub(crate) mod cmd_docs_build; pub(crate) mod cmd_report_clean; pub(crate) mod cmd_report_collect; pub(crate) mod cmd_show_features; pub(crate) mod cmd_show_manifests; -pub(crate) mod cmd_test_examples; diff --git a/mingling_ci/src/cmd/cmd_docs_build.rs b/mingling_ci/src/cmd/cmd_docs_build.rs deleted file mode 100644 index fe74419..0000000 --- a/mingling_ci/src/cmd/cmd_docs_build.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::ffi::OsString; - -use mingling::{ - Grouped, Routable, - macros::{buffer, command, renderer}, - res::ResExitCode, -}; - -use crate::Next; -use crate::res::ResFeatureList; -use crate::task::run::run_parallel_checks; - -#[command(node = "docs-build")] -pub async fn docs_build(features: &ResFeatureList) -> Next { - let args = vec![ - OsString::from("cargo"), - OsString::from("rustdoc"), - OsString::from("--features"), - OsString::from(features.list.join(",")), - OsString::from("-p"), - OsString::from("mingling"), - OsString::from("--"), - OsString::from("-D"), - OsString::from("warnings"), - ]; - let tasks = vec![("mingling".to_string(), "./mingling".to_string(), args)]; - let fail_count = run_parallel_checks("Docs-Build", "Docs", tasks).await; - - ResultDocsBuild { fail_count }.to_chain() -} - -/// Number of failed doc builds (0 or 1). -#[derive(Grouped)] -pub struct ResultDocsBuild { - pub fail_count: usize, -} - -/// Silently sets a non-zero exit code when the doc build failed. -#[renderer(buffer)] -pub fn render_docs_build(r: ResultDocsBuild, exit_code: &mut ResExitCode) { - if r.fail_count > 0 { - exit_code.exit_code = 1; - } -} diff --git a/mingling_ci/src/cmd/cmd_test_examples.rs b/mingling_ci/src/cmd/cmd_test_examples.rs deleted file mode 100644 index 602ada3..0000000 --- a/mingling_ci/src/cmd/cmd_test_examples.rs +++ /dev/null @@ -1,69 +0,0 @@ -use colored::Colorize; -use mingling::{ - Grouped, Routable, - macros::{buffer, command, renderer}, - res::ResExitCode, -}; - -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")] -pub async fn test_examples() -> Next { - reporter::set_task("Test-Examples"); - - let configs = load_test_configs(); - let total = configs.len(); - let pb = task_progress_bar(total, "Testing"); - pb.set_message("examples"); - - // One blocking task per example: build + run its test cases. - let mut handles = Vec::new(); - for example in configs { - handles.push(tokio::task::spawn_blocking(move || check_example(example))); - } - - let mut fail_count = 0; - for handle in handles { - let Ok(outcome) = handle.await else { - continue; - }; - pb.set_message(outcome.name.clone()); - pb.inc(1); - - if outcome.ok { - reporter::export(&outcome.name, &outcome.location, ReportResult::Ok); - } else { - fail_count += 1; - // Plain stderr: `pb.println` is swallowed on non-TTY (CI). - eprintln!(" {} {}", "failed".bright_red(), outcome.name); - eprintln!(" {}", outcome.output); - reporter::export( - &outcome.name, - &outcome.location, - ReportResult::Error(outcome.output), - ); - } - } - - pb.finish_and_clear(); - reporter::flush(); - - ResultTestExamples { fail_count }.to_chain() -} - -/// Number of examples that failed to build or pass their tests. -#[derive(Grouped)] -pub struct ResultTestExamples { - pub fail_count: usize, -} - -/// Silently sets a non-zero exit code when any example failed. -#[renderer(buffer)] -pub fn render_test_examples(r: ResultTestExamples, exit_code: &mut ResExitCode) { - if r.fail_count > 0 { - exit_code.exit_code = 1; - } -} diff --git a/mingling_ci/src/task.rs b/mingling_ci/src/task.rs index 92660bb..a42e458 100644 --- a/mingling_ci/src/task.rs +++ b/mingling_ci/src/task.rs @@ -1,6 +1,9 @@ -pub(crate) mod cmd_build; -pub(crate) mod cmd_clippy; +pub(crate) mod cmd_build_check; +pub(crate) mod cmd_clippy_check; +pub(crate) mod cmd_docs_check; +pub(crate) mod cmd_example_check; pub(crate) mod cmd_markdown_check; pub(crate) mod cmd_markdown_compare; pub(crate) mod cmd_test; pub(crate) mod run; + diff --git a/mingling_ci/src/task/cmd_build.rs b/mingling_ci/src/task/cmd_build.rs deleted file mode 100644 index f37699c..0000000 --- a/mingling_ci/src/task/cmd_build.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::ffi::OsString; -use std::path::Path; - -use mingling::{ - Grouped, Routable, - macros::{buffer, command, renderer}, - res::ResExitCode, -}; - -use crate::Next; -use crate::res::Manifests; -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(), location(path), build_args(path))) - .collect(); - let fail_count = run_parallel_checks("Build-All", "Building", tasks).await; - ResultBuildAll { fail_count }.to_chain() -} - -/// `cargo build --manifest-path ` -fn build_args(path: &Path) -> Vec { - vec![ - "cargo".into(), - "build".into(), - "--manifest-path".into(), - path.as_os_str().to_os_string(), - ] -} - -/// Number of packages that failed to build. -#[derive(Grouped)] -pub struct ResultBuildAll { - pub fail_count: usize, -} - -/// Silently sets a non-zero exit code when any build failed. -#[renderer(buffer)] -pub fn render_build_all(r: ResultBuildAll, exit_code: &mut ResExitCode) { - if r.fail_count > 0 { - exit_code.exit_code = 1; - } -} diff --git a/mingling_ci/src/task/cmd_build_check.rs b/mingling_ci/src/task/cmd_build_check.rs new file mode 100644 index 0000000..f67fe2e --- /dev/null +++ b/mingling_ci/src/task/cmd_build_check.rs @@ -0,0 +1,47 @@ +use std::ffi::OsString; +use std::path::Path; + +use mingling::{ + Grouped, Routable, + macros::{buffer, command, renderer}, + res::ResExitCode, +}; + +use crate::Next; +use crate::res::Manifests; +use crate::task::run::{location, run_parallel_checks}; + +#[command(node = "build-check")] +pub async fn build_check(manifests: &Manifests) -> Next { + let tasks = manifests + .package_dirs + .iter() + .map(|(name, path)| (name.clone(), location(path), build_args(path))) + .collect(); + let fail_count = run_parallel_checks("Build-Check", "Building", tasks).await; + ResultBuildCheck { fail_count }.to_chain() +} + +/// `cargo build --manifest-path ` +fn build_args(path: &Path) -> Vec { + vec![ + "cargo".into(), + "build".into(), + "--manifest-path".into(), + path.as_os_str().to_os_string(), + ] +} + +/// Number of packages that failed to build. +#[derive(Grouped)] +pub struct ResultBuildCheck { + pub fail_count: usize, +} + +/// Silently sets a non-zero exit code when any build failed. +#[renderer(buffer)] +pub fn render_build_check(r: ResultBuildCheck, exit_code: &mut ResExitCode) { + if r.fail_count > 0 { + exit_code.exit_code = 1; + } +} diff --git a/mingling_ci/src/task/cmd_clippy.rs b/mingling_ci/src/task/cmd_clippy.rs deleted file mode 100644 index 7256bef..0000000 --- a/mingling_ci/src/task/cmd_clippy.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::ffi::OsString; -use std::path::Path; - -use mingling::{ - Grouped, Routable, - macros::{buffer, command, renderer}, - res::ResExitCode, -}; - -use crate::Next; -use crate::res::Manifests; -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(), location(path), clippy_args(path))) - .collect(); - let fail_count = run_parallel_checks("Clippy-All", "Clippy", tasks).await; - ResultClippyAll { fail_count }.to_chain() -} - -/// `cargo clippy --manifest-path -- -D warnings` -fn clippy_args(path: &Path) -> Vec { - vec![ - "cargo".into(), - "clippy".into(), - "--manifest-path".into(), - path.as_os_str().to_os_string(), - "--".into(), - "-D".into(), - "warnings".into(), - ] -} - -/// Number of packages that failed clippy. -#[derive(Grouped)] -pub struct ResultClippyAll { - pub fail_count: usize, -} - -/// Silently sets a non-zero exit code when any clippy check failed. -#[renderer(buffer)] -pub fn render_clippy_all(r: ResultClippyAll, exit_code: &mut ResExitCode) { - if r.fail_count > 0 { - exit_code.exit_code = 1; - } -} diff --git a/mingling_ci/src/task/cmd_clippy_check.rs b/mingling_ci/src/task/cmd_clippy_check.rs new file mode 100644 index 0000000..a0dd46e --- /dev/null +++ b/mingling_ci/src/task/cmd_clippy_check.rs @@ -0,0 +1,50 @@ +use std::ffi::OsString; +use std::path::Path; + +use mingling::{ + Grouped, Routable, + macros::{buffer, command, renderer}, + res::ResExitCode, +}; + +use crate::Next; +use crate::res::Manifests; +use crate::task::run::{location, run_parallel_checks}; + +#[command(node = "clippy-check")] +pub async fn clippy_check(manifests: &Manifests) -> Next { + let tasks = manifests + .package_dirs + .iter() + .map(|(name, path)| (name.clone(), location(path), clippy_args(path))) + .collect(); + let fail_count = run_parallel_checks("Clippy-Check", "Clippy", tasks).await; + ResultClippyCheck { fail_count }.to_chain() +} + +/// `cargo clippy --manifest-path -- -D warnings` +fn clippy_args(path: &Path) -> Vec { + vec![ + "cargo".into(), + "clippy".into(), + "--manifest-path".into(), + path.as_os_str().to_os_string(), + "--".into(), + "-D".into(), + "warnings".into(), + ] +} + +/// Number of packages that failed clippy. +#[derive(Grouped)] +pub struct ResultClippyCheck { + pub fail_count: usize, +} + +/// Silently sets a non-zero exit code when any clippy check failed. +#[renderer(buffer)] +pub fn render_clippy_check(r: ResultClippyCheck, exit_code: &mut ResExitCode) { + if r.fail_count > 0 { + exit_code.exit_code = 1; + } +} diff --git a/mingling_ci/src/task/cmd_docs_check.rs b/mingling_ci/src/task/cmd_docs_check.rs new file mode 100644 index 0000000..3a77d4d --- /dev/null +++ b/mingling_ci/src/task/cmd_docs_check.rs @@ -0,0 +1,44 @@ +use std::ffi::OsString; + +use mingling::{ + Grouped, Routable, + macros::{buffer, command, renderer}, + res::ResExitCode, +}; + +use crate::Next; +use crate::res::ResFeatureList; +use crate::task::run::run_parallel_checks; + +#[command(node = "docs-check")] +pub async fn docs_check(features: &ResFeatureList) -> Next { + let args = vec![ + OsString::from("cargo"), + OsString::from("rustdoc"), + OsString::from("--features"), + OsString::from(features.list.join(",")), + OsString::from("-p"), + OsString::from("mingling"), + OsString::from("--"), + OsString::from("-D"), + OsString::from("warnings"), + ]; + let tasks = vec![("mingling".to_string(), "./mingling".to_string(), args)]; + let fail_count = run_parallel_checks("Docs-Check", "Docs", tasks).await; + + ResultDocsCheck { fail_count }.to_chain() +} + +/// Number of failed doc builds (0 or 1). +#[derive(Grouped)] +pub struct ResultDocsCheck { + pub fail_count: usize, +} + +/// Silently sets a non-zero exit code when the doc build failed. +#[renderer(buffer)] +pub fn render_docs_check(r: ResultDocsCheck, exit_code: &mut ResExitCode) { + if r.fail_count > 0 { + exit_code.exit_code = 1; + } +} diff --git a/mingling_ci/src/task/cmd_example_check.rs b/mingling_ci/src/task/cmd_example_check.rs new file mode 100644 index 0000000..1b9f440 --- /dev/null +++ b/mingling_ci/src/task/cmd_example_check.rs @@ -0,0 +1,69 @@ +use colored::Colorize; +use mingling::{ + Grouped, Routable, + macros::{buffer, command, renderer}, + res::ResExitCode, +}; + +use crate::Next; +use crate::examples::{check_example, load_test_configs}; +use crate::progress::task_progress_bar; +use crate::reporter::{self, ReportResult}; + +#[command(node = "example-check")] +pub async fn example_check() -> Next { + reporter::set_task("Example-Check"); + + let configs = load_test_configs(); + let total = configs.len(); + let pb = task_progress_bar(total, "Testing"); + pb.set_message("examples"); + + // One blocking task per example: build + run its test cases. + let mut handles = Vec::new(); + for example in configs { + handles.push(tokio::task::spawn_blocking(move || check_example(example))); + } + + let mut fail_count = 0; + for handle in handles { + let Ok(outcome) = handle.await else { + continue; + }; + pb.set_message(outcome.name.clone()); + pb.inc(1); + + if outcome.ok { + reporter::export(&outcome.name, &outcome.location, ReportResult::Ok); + } else { + fail_count += 1; + // Plain stderr: `pb.println` is swallowed on non-TTY (CI). + eprintln!(" {} {}", "failed".bright_red(), outcome.name); + eprintln!(" {}", outcome.output); + reporter::export( + &outcome.name, + &outcome.location, + ReportResult::Error(outcome.output), + ); + } + } + + pb.finish_and_clear(); + reporter::flush(); + + ResultExampleCheck { fail_count }.to_chain() +} + +/// Number of examples that failed to build or pass their tests. +#[derive(Grouped)] +pub struct ResultExampleCheck { + pub fail_count: usize, +} + +/// Silently sets a non-zero exit code when any example failed. +#[renderer(buffer)] +pub fn render_example_check(r: ResultExampleCheck, exit_code: &mut ResExitCode) { + if r.fail_count > 0 { + exit_code.exit_code = 1; + } +} -- cgit