Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
fix: return failure for command run by CI failing
Lars Wirzenius committed 2 years ago
commit 76d5cc4a3a5f7decacf978a9bac9f5810c2f64ab
parent 6e2d748
2 files changed +22 -15
modified 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),

modified 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)
    }
}