1use anyhow::{Context, Result};
2use clap::Parser;
3use std::fs;
4use std::path::Path;
5
6mod runners;
7mod steps;
8mod vars;
9mod workflows;
10
11use workflows::*;
12
13#[derive(Parser)]
14pub struct GenerateWorkflowArgs {}
15
16pub fn run_workflows(_: GenerateWorkflowArgs) -> Result<()> {
17 let dir = Path::new(".github/workflows");
18
19 let workflows = vec![("danger.yml", danger()), ("nix.yml", nix())];
20 fs::create_dir_all(dir)
21 .with_context(|| format!("Failed to create directory: {}", dir.display()))?;
22
23 for (filename, workflow) in workflows {
24 let content = workflow
25 .to_string()
26 .map_err(|e| anyhow::anyhow!("{}: {:?}", filename, e))?;
27 let content = format!("# generated `cargo xtask workflows`. Do not edit.\n{content}");
28 let file_path = dir.join(filename);
29 fs::write(&file_path, content)?;
30 }
31
32 Ok(())
33}