1use anyhow::Result;
2use clap::Parser;
3
4use gh_workflow::*;
5
6#[derive(Parser)]
7pub struct GenerateWorkflowArgs {}
8
9pub fn run_generate_workflow(_args: GenerateWorkflowArgs) -> Result<()> {
10 // Create the "Run tests" composite action workflow
11 let workflow = Workflow::default().name("Run tests").add_job(
12 "run_tests",
13 Job::default()
14 .add_step(Step::new("Install Rust").run("cargo install cargo-nextest --locked"))
15 .add_step(
16 Step::new("Install Node")
17 .uses(
18 "actions",
19 "setup-node",
20 "49933ea5288caeca8642d1e84afbd3f7d6820020",
21 )
22 .add_with(("node-version", "18")),
23 )
24 .add_step(
25 Step::new("Limit target directory size")
26 .run("script/clear-target-dir-if-larger-than ${{ env.MAX_SIZE }}")
27 .env(("MAX_SIZE", "${{ runner.os == 'macOS' && 300 || 100 }}")),
28 )
29 .add_step(Step::new("Run tests").run(
30 "cargo nextest run --workspace --no-fail-fast --failure-output immediate-final",
31 )),
32 );
33
34 // Generate and print the workflow YAML
35 let yaml = workflow
36 .to_string()
37 .map_err(|e| anyhow::anyhow!("{:?}", e))?;
38 println!("{}", yaml);
39
40 Ok(())
41}