xtask_lib/tasks/ci/mod.rs
1//! `cargo xtask ci` — tasks that run exclusively in CI environments.
2//!
3//! These tasks handle CI-specific setup that would be awkward to express as
4//! GitHub Actions YAML steps, such as installing and caching external tools
5//! with version pinning.
6//!
7//! ## Subcommands
8//!
9//! | Subcommand | Description |
10//! |------------|-------------|
11//! | `install-doc-tools` | Install mdBook, mdbook-epub, mdbook-mermaid, and optionally Zola |
12//! | `matrix` | Emit a GitHub Actions dynamic feature matrix JSON |
13//! | `clippy-report` | Deduplicate clippy JSON artifacts and report via reviewdog |
14
15pub mod clippy_report;
16pub mod install_doc_tools;
17pub mod matrix;
18
19use anyhow::Result;
20use clap::{Args, Subcommand};
21
22use clippy_report::ClippyReportArgs;
23use install_doc_tools::InstallDocToolsArgs;
24
25/// Arguments for `cargo xtask ci`.
26#[derive(Debug, Args)]
27pub struct CiArgs {
28 #[command(subcommand)]
29 pub command: CiCommand,
30}
31
32/// Subcommands available under `cargo xtask ci`.
33#[derive(Debug, Subcommand)]
34pub enum CiCommand {
35 /// Install and cache mdBook, mdbook-epub, mdbook-mermaid, and optionally Zola.
36 ///
37 /// Reads from the GitHub Actions cache (populated by `actions/cache` before
38 /// this step) and installs any tools not already present. Appends the
39 /// install directory to `$GITHUB_PATH` so subsequent steps can invoke the
40 /// tools directly.
41 InstallDocTools(InstallDocToolsArgs),
42
43 /// Scan workspace Cargo.toml files and emit a GitHub Actions dynamic matrix JSON.
44 ///
45 /// Writes `matrix=<json>` to `$GITHUB_OUTPUT` (or stdout when run locally).
46 /// Consume the output with `fromJson(needs.<job>.outputs.matrix)`.
47 Matrix,
48
49 /// Deduplicate clippy JSON artifacts and post a single reviewdog report.
50 ///
51 /// Reads every `.json` file produced by `cargo xtask clippy --save-json`
52 /// from `--artifacts-dir`, deduplicates diagnostics across feature labels,
53 /// and pipes the unique set through `reviewdog` once using the
54 /// `github-pr-review` reporter.
55 ClippyReport(ClippyReportArgs),
56}
57
58/// Dispatches `cargo xtask ci <subcommand>`.
59///
60/// # Errors
61///
62/// Propagates any error returned by the selected subcommand.
63pub fn run(args: CiArgs) -> Result<()> {
64 match args.command {
65 CiCommand::InstallDocTools(args) => install_doc_tools::run(args),
66 CiCommand::Matrix => matrix::run(),
67 CiCommand::ClippyReport(args) => clippy_report::run(args),
68 }
69}