M0.3: xtask ci, layers, assets, cleanroom, ui-licences, dev, fixtures
layers reads cargo metadata and rejects upward, sideways and tool-crate dependencies and any path to Tauri below L6. assets checks ASSETS.md rows and rejects committed fonts. cleanroom rejects JetBrains copyright notices, exported IDE configuration and .idea/.jar/.icls files. deny.toml mirrors the licence allow list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ec1c72d9ac
commit
3bd95343cc
8 changed files with 1130 additions and 2 deletions
152
xtask/src/tasks.rs
Normal file
152
xtask/src/tasks.rs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
//! The composite and launcher subcommands: `ci`, `dev` and `fixtures`.
|
||||
|
||||
use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::util::{TaskResult, program, repo_root, run};
|
||||
use crate::{assets, cleanroom, layers, licences, lints};
|
||||
|
||||
/// Runs the full quality gate of AGENTS.md, stopping at the first failure.
|
||||
///
|
||||
/// `skip_ui` leaves out the frontend steps, for machines without pnpm.
|
||||
///
|
||||
/// # Errors
|
||||
/// Fails with the name of the first step that failed.
|
||||
pub fn ci(skip_ui: bool) -> TaskResult {
|
||||
let root = repo_root()?;
|
||||
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());
|
||||
let ui = root.join("ui");
|
||||
type Step<'a> = (&'a str, Box<dyn Fn() -> TaskResult + 'a>);
|
||||
let mut steps: Vec<Step> = vec![
|
||||
(
|
||||
"fmt",
|
||||
Box::new(|| run(&root, &cargo, &["fmt", "--all", "--check"])),
|
||||
),
|
||||
(
|
||||
"clippy",
|
||||
Box::new(|| {
|
||||
run(
|
||||
&root,
|
||||
&cargo,
|
||||
&[
|
||||
"clippy",
|
||||
"--workspace",
|
||||
"--all-targets",
|
||||
"--",
|
||||
"-D",
|
||||
"warnings",
|
||||
],
|
||||
)
|
||||
}),
|
||||
),
|
||||
(
|
||||
"test",
|
||||
Box::new(|| run(&root, &cargo, &["test", "--workspace"])),
|
||||
),
|
||||
("lints-selftest", Box::new(lints::selftest)),
|
||||
("layers", Box::new(layers::check_workspace)),
|
||||
("assets", Box::new(assets::check_repo)),
|
||||
("cleanroom", Box::new(cleanroom::check_repo)),
|
||||
(
|
||||
"deny",
|
||||
Box::new(|| run(&root, &cargo, &["deny", "check", "licenses"])),
|
||||
),
|
||||
];
|
||||
if !skip_ui {
|
||||
steps.extend::<Vec<Step>>(vec![
|
||||
(
|
||||
"pnpm install",
|
||||
Box::new(|| run(&ui, "pnpm", &["install", "--frozen-lockfile"])),
|
||||
),
|
||||
("ui lint", Box::new(|| run(&ui, "pnpm", &["lint"]))),
|
||||
(
|
||||
"ui typecheck",
|
||||
Box::new(|| run(&ui, "pnpm", &["typecheck"])),
|
||||
),
|
||||
("ui test", Box::new(|| run(&ui, "pnpm", &["test"]))),
|
||||
("ui licences", Box::new(licences::check_ui)),
|
||||
]);
|
||||
}
|
||||
let start = Instant::now();
|
||||
for (name, step) in &steps {
|
||||
println!("==> {name}");
|
||||
step().map_err(|e| format!("ci step `{name}` failed: {e}"))?;
|
||||
}
|
||||
println!(
|
||||
"ci: {} steps passed in {:.0?}",
|
||||
steps.len(),
|
||||
start.elapsed()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Starts the desktop app in development mode (Vite dev server plus a debug
|
||||
/// build of the Tauri shell) through `cargo tauri dev`. Arguments after `--`
|
||||
/// are passed to the app, e.g. `cargo xtask dev -- --control 7979 .`.
|
||||
///
|
||||
/// # Errors
|
||||
/// Fails if the Tauri CLI is missing or the app exits with an error.
|
||||
pub fn dev(app_args: &[String]) -> TaskResult {
|
||||
let root = repo_root()?;
|
||||
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());
|
||||
if !root.join("ui").join("node_modules").is_dir() {
|
||||
run(&root.join("ui"), "pnpm", &["install"])?;
|
||||
}
|
||||
let mut args = vec!["tauri", "dev"];
|
||||
if !app_args.is_empty() {
|
||||
args.push("--");
|
||||
args.push("--");
|
||||
args.extend(app_args.iter().map(String::as_str));
|
||||
}
|
||||
run(&root.join("apps").join("lutra-desktop"), &cargo, &args).map_err(|e| {
|
||||
format!("{e}\n(install the Tauri CLI with `cargo install tauri-cli --locked`)")
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates the reference projects (a Symfony and a Laravel skeleton) in
|
||||
/// `target/fixtures/` with Composer. Existing fixtures are kept.
|
||||
///
|
||||
/// # Errors
|
||||
/// Fails if Composer is missing or a project cannot be created.
|
||||
pub fn fixtures() -> TaskResult {
|
||||
let root = repo_root()?;
|
||||
let dir = root.join("target").join("fixtures");
|
||||
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
|
||||
if std::process::Command::new(program("composer"))
|
||||
.arg("--version")
|
||||
.output()
|
||||
.is_err()
|
||||
{
|
||||
return Err("Composer is not on the PATH; install PHP and Composer first".into());
|
||||
}
|
||||
for (name, package) in [
|
||||
("symfony", "symfony/skeleton"),
|
||||
("laravel", "laravel/laravel"),
|
||||
] {
|
||||
if dir.join(name).join("composer.json").is_file() {
|
||||
println!("fixtures: {name} exists");
|
||||
continue;
|
||||
}
|
||||
create_project(&dir, package, name)?;
|
||||
}
|
||||
println!("fixtures: ready in {}", dir.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Runs `composer create-project` for one fixture.
|
||||
///
|
||||
/// # Errors
|
||||
/// Fails if Composer fails.
|
||||
fn create_project(dir: &Path, package: &str, name: &str) -> TaskResult {
|
||||
run(
|
||||
dir,
|
||||
"composer",
|
||||
&[
|
||||
"create-project",
|
||||
"--no-interaction",
|
||||
"--prefer-dist",
|
||||
package,
|
||||
name,
|
||||
],
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue