1use anyhow::{Context, Result};
2use clap::Parser;
3use std::fs;
4use std::path::Path;
5
6mod danger;
7mod nix_build;
8mod release_nightly;
9mod run_action_checks;
10mod run_bundling;
11mod run_docs_checks;
12mod run_license_checks;
13mod run_style_checks;
14
15mod run_tests;
16mod runners;
17mod steps;
18mod vars;
19
20#[derive(Parser)]
21pub struct GenerateWorkflowArgs {}
22
23pub fn run_workflows(_: GenerateWorkflowArgs) -> Result<()> {
24 let dir = Path::new(".github/workflows");
25
26 let workflows = vec![
27 ("danger.yml", danger::danger()),
28 ("nix_build.yml", nix_build::nix_build()),
29 ("run_bundling.yml", run_bundling::run_bundling()),
30 ("release_nightly.yml", release_nightly::release_nightly()),
31 ("run_tests.yml", run_tests::run_tests()),
32 ("run_docs_checks.yml", run_docs_checks::run_docs_checks()),
33 ("run_style_checks.yml", run_style_checks::run_style_checks()),
34 (
35 "run_action_checks.yml",
36 run_action_checks::run_action_checks(),
37 ),
38 (
39 "run_license_checks.yml",
40 run_license_checks::run_license_checks(),
41 ), // ("release.yml", release::release()),
42 ];
43 fs::create_dir_all(dir)
44 .with_context(|| format!("Failed to create directory: {}", dir.display()))?;
45
46 for (filename, workflow) in workflows {
47 let content = workflow
48 .to_string()
49 .map_err(|e| anyhow::anyhow!("{}: {:?}", filename, e))?;
50 let content = format!(
51 "# Generated from xtask::workflows::{}\n# Rebuild with `cargo xtask workflows`.\n{}",
52 workflow.name.unwrap(),
53 content
54 );
55 let file_path = dir.join(filename);
56 fs::write(&file_path, content)?;
57 }
58
59 Ok(())
60}