From 76d5cc4a3a5f7decacf978a9bac9f5810c2f64ab Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 14 Mar 2024 11:30:44 +0200 Subject: [PATCH] fix: return failure for command run by CI failing If any command run by CI for a repository fails, set the run to failed in the run info builder. Also, we were hiding that failure with later errors, if, say, updating a log file or removing temporary files failed, so don't do that. --- src/engine.rs | 24 +++++++++++++----------- src/run.rs | 13 +++++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 7cb90da..b3c5a10 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -177,15 +177,20 @@ impl Engine { // Actually run. Examine the run log to decide if the run // succeeded or failed. - let run_log = run.run()?; - let result = if run_log.all_commands_succeeded() { - RunResult::Success + let result = run.run(); + if let Ok(run_log) = result { + let result = if run_log.all_commands_succeeded() { + RunResult::Success + } else { + RunResult::Failure + }; + self.run_info_builder.result(result); + let all = run_log.all_commands_succeeded(); + Ok(all) } else { - RunResult::Failure - }; - self.run_info_builder.result(result); - - Ok(run_log.all_commands_succeeded()) + self.run_info_builder.result(RunResult::Failure); + Ok(false) + } } /// Report results to caller (via stdout) and to users (via report @@ -222,9 +227,6 @@ pub enum EngineError { #[error("failed to load Radicle profile")] LoadProfile(#[source] radicle::profile::Error), - #[error("failed to remove {0}")] - RemoveDir(PathBuf, #[source] std::io::Error), - #[error("programming error: failed to set field {0}")] Unset(&'static str), diff --git a/src/run.rs b/src/run.rs index 423d143..6ff9c1e 100644 --- a/src/run.rs +++ b/src/run.rs @@ -91,11 +91,18 @@ impl Run { // that can be a problem for all future runs, e.g., due to a // full file system, whereas, e.g., a syntax error in the code // under test, is more fleeting. - self.run_log.write()?; + let write_result = self.run_log.write(); + if result.is_ok() { + write_result?; + } // Likewise, if we can't clean up disk space, the node admin // needs to know about that. - std::fs::remove_dir_all(&self.src).map_err(|e| RunError::RemoveDir(self.src.clone(), e))?; + let rmdir_result = std::fs::remove_dir_all(&self.src) + .map_err(|e| RunError::RemoveDir(self.src.clone(), e)); + if result.is_ok() { + rmdir_result?; + } // Return result from the actual CI run. result.map(|_| self.run_log) @@ -190,8 +197,6 @@ impl Run { &output.stdout, &output.stderr, ); - eprintln!("RUNCMD: argv={:?}", argv); - eprintln!("RUNCMD: exit={}", exit); Ok(exit) } }