mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-11-21 02:20:49 +08:00
refactor: use engine in main
Also introduce exit codes: 0 for success, 1 for problem in the repository under test, 2 for engine problem. Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
+16
-15
@@ -14,7 +14,6 @@ use crate::{
|
||||
},
|
||||
report,
|
||||
run::{Run, RunError},
|
||||
runcmd::RunCmdError,
|
||||
runinfo::{RunInfo, RunInfoBuilder, RunInfoError},
|
||||
runlog::RunLogError,
|
||||
runspec::RunSpecError,
|
||||
@@ -54,7 +53,7 @@ impl Engine {
|
||||
/// from stdin, write responses to stdout. Update node admin log
|
||||
/// with any problems that aren't inherent in the git repository
|
||||
/// (those go into the run log).
|
||||
pub fn run(&mut self) -> Result<(), EngineError> {
|
||||
pub fn run(&mut self) -> Result<bool, EngineError> {
|
||||
let req = match self.setup() {
|
||||
Ok(req) => req,
|
||||
Err(e) => {
|
||||
@@ -64,15 +63,20 @@ impl Engine {
|
||||
};
|
||||
|
||||
// Check that we got the right kind of request.
|
||||
let mut success = false;
|
||||
match req {
|
||||
Request::Trigger { repo, commit } => {
|
||||
if let Err(e) = self.run_helper(repo, commit) {
|
||||
// If the run helper return an error, something
|
||||
// went wrong in that is not due to the repository
|
||||
// under test. So we don't put it in the run log,
|
||||
// but the admin log and return it to the caller.
|
||||
self.adminlog.writeln(&format!("Error running CI: {}", e))?;
|
||||
return Err(e);
|
||||
match self.run_helper(repo, commit) {
|
||||
Ok(true) => success = true,
|
||||
Ok(false) => (),
|
||||
Err(e) => {
|
||||
// If the run helper return an error, something
|
||||
// went wrong in that is not due to the repository
|
||||
// under test. So we don't put it in the run log,
|
||||
// but the admin log and return it to the caller.
|
||||
self.adminlog.writeln(&format!("Error running CI: {}", e))?;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
@@ -89,7 +93,7 @@ impl Engine {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(success)
|
||||
}
|
||||
|
||||
// Set up CI to run. If something goes wrong, return the error,
|
||||
@@ -134,7 +138,7 @@ impl Engine {
|
||||
|
||||
// Execute the CI run. Log any problems to a log for this run, and
|
||||
// persist that. Update the run info builder as needed.
|
||||
fn run_helper(&mut self, rid: Id, commit: Oid) -> Result<(), EngineError> {
|
||||
fn run_helper(&mut self, rid: Id, commit: Oid) -> Result<bool, EngineError> {
|
||||
// Pick a run id and create a directory for files related to
|
||||
// the run.
|
||||
let (run_id, run_dir) = mkdir_run(&self.config)?;
|
||||
@@ -166,7 +170,7 @@ impl Engine {
|
||||
};
|
||||
self.run_info_builder.result(result);
|
||||
|
||||
Ok(())
|
||||
Ok(run_log.all_commands_succeeded())
|
||||
}
|
||||
|
||||
/// Report results to caller (via stdout) and to users (via report
|
||||
@@ -218,9 +222,6 @@ pub enum EngineError {
|
||||
#[error(transparent)]
|
||||
Report(#[from] report::ReportError),
|
||||
|
||||
#[error(transparent)]
|
||||
RunCmd(#[from] RunCmdError),
|
||||
|
||||
#[error(transparent)]
|
||||
RunInfo(#[from] RunInfoError),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user