ambient-execute-plan.rs
1 use std::path::Path; 2 3 use ambient_ci::{ 4 action::Context, 5 plan::RunnablePlan, 6 runlog::{RunLog, RunLogSource}, 7 }; 8 9 const PLAN_FILENAME: &str = "plan.yaml"; 10 11 fn main() { 12 let mut runlog = RunLog::default(); 13 runlog.stdout(); 14 let mut context = Context::new(&mut runlog); 15 if let Err(err) = fallible_main(&mut context) { 16 eprintln!("ERROR: {err}"); 17 let mut source = err.source(); 18 while let Some(src) = source { 19 eprintln!("caused by: {src}"); 20 source = src.source(); 21 } 22 context 23 .runlog() 24 .executor_ends_in_failure(RunLogSource::Plan, 1); 25 std::process::exit(1); 26 } 27 } 28 29 fn fallible_main(context: &mut Context) -> Result<(), Box<dyn std::error::Error>> { 30 let name = "ambient-execute-plan"; 31 let version = env!("VERSION"); 32 33 context.set_env("HOME", "/root"); 34 context 35 .runlog() 36 .executor_starts(RunLogSource::Plan, name, version); 37 38 let plan = RunnablePlan::from_file(Path::new(PLAN_FILENAME))?; 39 context.runlog().runnable_plan(RunLogSource::Plan, &plan); 40 plan.execute(RunLogSource::Plan, context)?; 41 42 context 43 .runlog() 44 .executor_ends_successfully(RunLogSource::Plan); 45 46 Ok(()) 47 }