diff --git a/crates/client/src/release.rs b/crates/client/src/release.rs index 1dd4a7f..13a2fb4 100644 --- a/crates/client/src/release.rs +++ b/crates/client/src/release.rs @@ -97,10 +97,11 @@ impl Cx { } } -#[derive(Clone, Copy)] -struct Vm { - present: bool, - started: bool, +enum Vm { + Missing, + Running, + Started, + Broken(String), } fn run(source: &Path, cx: &Cx) { @@ -119,7 +120,7 @@ fn run(source: &Path, cx: &Cx) { let result = if cx.cancelled() { Err("cancelled".to_string()) } else { - run_job(job, source, &key, cx, vm) + run_job(job, source, &key, cx, &vm) }; if let Err(e) = result { let e = if cx.cancelled() { @@ -131,7 +132,7 @@ fn run(source: &Path, cx: &Cx) { break; } } - if vm.started { + if let Vm::Started = vm { podman_ok(&["stop", VM]); } cx.send(Event::Done); @@ -148,24 +149,23 @@ fn preflight(source: &Path) -> Result { return Err("uncommitted changes".into()); } fs::create_dir_all(source.join("dist")).map_err(|e| e.to_string())?; - let present = podman_ok(&["container", "exists", VM]); - let mut started = false; - if present { - let state = Command::new("podman") - .args(["inspect", "-f", "{{.State.Running}}", VM]) - .output() - .map_err(|e| e.to_string())?; - if String::from_utf8_lossy(&state.stdout).trim() == "false" { - if !podman_ok(&["start", VM]) { - return Err("podman start failed".into()); - } - started = true; - } + if !podman_ok(&["container", "exists", VM]) { + return Ok(Vm::Missing); } - Ok(Vm { present, started }) + let state = Command::new("podman") + .args(["inspect", "-f", "{{.State.Running}}", VM]) + .output() + .map_err(|e| e.to_string())?; + if String::from_utf8_lossy(&state.stdout).trim() != "false" { + return Ok(Vm::Running); + } + Ok(match check(Command::new("podman").args(["start", VM])) { + Ok(()) => Vm::Started, + Err(error) => Vm::Broken(error), + }) } -fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx, vm: Vm) -> Result<(), String> { +fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx, vm: &Vm) -> Result<(), String> { match job { Job::Linux(level) => { if !cfg!(target_os = "linux") { @@ -175,14 +175,17 @@ fn run_job(job: Job, source: &Path, key: &Path, cx: &Cx, vm: Vm) -> Result<(), S build_linux(job, level, source, cx) } Job::WindowsStart => { - if !vm.present { + if let Vm::Missing = vm { return skip(cx, job, "no yumush-win"); } cx.send(Event::Started(job)); + if let Vm::Broken(error) = vm { + return Err(error.clone()); + } start_windows(job, source, key, cx) } Job::Windows(level) => { - if !vm.present { + if let Vm::Missing = vm { return skip(cx, job, "no yumush-win"); } cx.send(Event::Started(job));