|
| 1 | +use anyhow::Context; |
| 2 | +use colored::Colorize; |
| 3 | +use log::info; |
| 4 | + |
| 5 | +use crate::{ |
| 6 | + cli, |
| 7 | + config::read_config, |
| 8 | + template::{ |
| 9 | + expand_executor_config_template, expand_launch_config_template, |
| 10 | + expand_runner_config_template, |
| 11 | + }, |
| 12 | +}; |
| 13 | + |
| 14 | +pub fn check(paths: &cli::Paths) -> anyhow::Result<()> { |
| 15 | + let config = read_config(&paths.config_file).context(format!( |
| 16 | + "Failed reading config file {:?}", |
| 17 | + paths.config_file |
| 18 | + ))?; |
| 19 | + let num_jobs = config.launch.as_ref().map_or(1, |v| v.group_size); |
| 20 | + for (instance_name, instance) in &config.runners { |
| 21 | + expand_runner_config_template(&config.runner, instance_name, instance).context(format!( |
| 22 | + "Failed expanding [runner] for instance {}", |
| 23 | + instance_name |
| 24 | + ))?; |
| 25 | + expand_executor_config_template(&config, instance_name, instance).context(format!( |
| 26 | + "Failed expanding [executor] for instance {}", |
| 27 | + instance_name |
| 28 | + ))?; |
| 29 | + expand_launch_config_template(paths, &config, instance_name, instance, num_jobs).context( |
| 30 | + format!("Failed expanding [launch] for instance {}", instance_name), |
| 31 | + )?; |
| 32 | + } |
| 33 | + info!("Config check successful, no errors found"); |
| 34 | + Ok(()) |
| 35 | +} |
| 36 | + |
| 37 | +pub fn show(paths: &cli::Paths) -> anyhow::Result<()> { |
| 38 | + let config = read_config(&paths.config_file).context(format!( |
| 39 | + "Failed reading config file {:?}", |
| 40 | + paths.config_file |
| 41 | + ))?; |
| 42 | + info!("{}", "Full configuration".green()); |
| 43 | + println!( |
| 44 | + "{}", |
| 45 | + toml::to_string_pretty(&config).context("Failed printing config")? |
| 46 | + ); |
| 47 | + let num_jobs = config.launch.as_ref().map_or(1, |v| v.group_size); |
| 48 | + for (instance_name, instance) in &config.runners { |
| 49 | + println!( |
| 50 | + "{}", |
| 51 | + format!("gitlab-runner configuration for runner {}", instance_name).green() |
| 52 | + ); |
| 53 | + println!( |
| 54 | + "{}", |
| 55 | + toml::to_string_pretty( |
| 56 | + &expand_runner_config_template(&config.runner, instance_name, instance).context( |
| 57 | + format!("Failed expanding [runner] for instance {}", instance_name) |
| 58 | + )? |
| 59 | + ) |
| 60 | + .context("Failed printing config")? |
| 61 | + ); |
| 62 | + println!( |
| 63 | + "{}", |
| 64 | + format!("executor configuration for runner {}", instance_name).green() |
| 65 | + ); |
| 66 | + println!( |
| 67 | + "{}", |
| 68 | + toml::to_string_pretty( |
| 69 | + &expand_executor_config_template(&config, instance_name, instance).context( |
| 70 | + format!("Failed expanding [executor] for instance {}", instance_name) |
| 71 | + )? |
| 72 | + ) |
| 73 | + .context("Failed printing config")? |
| 74 | + ); |
| 75 | + println!( |
| 76 | + "{}", |
| 77 | + format!("launch configuration for runner {}", instance_name).green() |
| 78 | + ); |
| 79 | + println!( |
| 80 | + "{}", |
| 81 | + toml::to_string_pretty( |
| 82 | + &expand_launch_config_template(paths, &config, instance_name, instance, num_jobs) |
| 83 | + .context(format!( |
| 84 | + "Failed expanding [launch] for instance {}", |
| 85 | + instance_name |
| 86 | + ),)? |
| 87 | + ) |
| 88 | + .context("Failed printing config")? |
| 89 | + ); |
| 90 | + } |
| 91 | + Ok(()) |
| 92 | +} |
0 commit comments