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.
This commit is contained in:
Lars Wirzenius
2024-03-14 11:42:55 +02:00
parent 6e2d748267
commit 76d5cc4a3a
2 changed files with 22 additions and 15 deletions
+13 -11
View File
@@ -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),
+9 -4
View File
@@ -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)
}
}