Skip to main content

write_to_disk/
write_to_disk.rs

1//! Generate a workflow and write it to `.github/workflows/ci.yml`.
2//!
3//! ```text
4//! cargo run --example write_to_disk
5//! ```
6//!
7//! Writes into a temporary directory by default so running the example
8//! doesn't overwrite the host repo's CI file. Set
9//! `DEV_CI_WRITE_TARGET=.github/workflows/ci.yml` to write into the
10//! current crate instead.
11
12use std::path::PathBuf;
13
14use dev_ci::Generator;
15
16fn main() {
17    let yaml = Generator::new()
18        .with_clippy()
19        .with_fmt()
20        .with_docs()
21        .with_msrv("1.85")
22        .generate();
23
24    let target = std::env::var("DEV_CI_WRITE_TARGET")
25        .map(PathBuf::from)
26        .unwrap_or_else(|_| std::env::temp_dir().join("dev-ci-example/ci.yml"));
27
28    if let Some(parent) = target.parent() {
29        std::fs::create_dir_all(parent).expect("create parent dir");
30    }
31    std::fs::write(&target, yaml).expect("write yaml");
32    println!("wrote {}", target.display());
33}