github_workflows_update/
cmd.rs1use color_eyre::Result;
8use futures::future::join_all;
9use tokio_stream::StreamExt;
10use tokio_stream::wrappers::ReadDirStream;
11use tracing::Level;
12use tracing::event;
13
14use crate::cli::Cli;
15use crate::cli::OutputFormat;
16use crate::proxy;
17use clap::Parser;
18
19#[tokio::main]
20pub async fn main() -> Result<()> {
21 let args = Cli::parse();
22 env_logger::init();
23 let proxy_server = proxy::Server::new();
24 let futures = ReadDirStream::new(tokio::fs::read_dir(".github/workflows").await?)
25 .filter_map(|filename| match filename {
26 Ok(filename) => Some(filename.path()),
27 Err(ref e) => {
28 event!(
29 Level::ERROR,
30 error = ?e,
31 filename = ?filename,
32 "error getting filename from .github/workflows"
33 );
34 None
35 }
36 })
37 .map(|f| {
38 crate::processor::process_file(
39 args.dryrun,
40 args.output_format.unwrap_or_default(),
41 &proxy_server,
42 f,
43 )
44 })
45 .collect::<Vec<_>>()
46 .await;
47 let mut any_outdated = false;
48 for result in join_all(futures).await {
49 match result {
50 Ok(true) => {
51 any_outdated = true;
52 }
53 Err(_) => {
54 std::process::exit(1);
57 }
58 _ => {}
59 }
60 }
61 if any_outdated && args.error_on_outdated {
62 match args.output_format.unwrap_or_default() {
63 OutputFormat::Standard => {
64 eprintln!("Found oudated entities");
65 }
66 OutputFormat::GithubWarning => {
67 println!("::error ::outdated entities found");
68 }
69 }
70 std::process::exit(2);
71 }
72 Ok(())
73}