Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
add rad-ci binary
Lars Wirzenius committed 1 year ago
commit 7dde548745416c046142f59419e297fcea081483
parent 6b0b32b
1 file changed +41 -0
added src/bin/rad-ci.rs
@@ -0,0 +1,41 @@
+
use std::{
+
    path::Path,
+
    process::{exit, Command},
+
};
+

+
use radicle_native_ci::{run::RUNSPEC_PATH, runspec::RunSpec};
+

+
// Exit codes for the program.
+
const EXIT_OK: i32 = 0;
+
const EXIT_FAILURE: i32 = 1;
+
const EXIT_ERROR: i32 = 2;
+

+
/// The main program.
+
fn main() {
+
    let code = match fallible_main() {
+
        Ok(success) => {
+
            if success {
+
                EXIT_OK
+
            } else {
+
                EXIT_FAILURE
+
            }
+
        }
+
        Err(e) => {
+
            eprintln!("ERROR: {}", e);
+
            let mut e = e.source();
+
            while let Some(source) = e {
+
                eprintln!("caused by: {}", source);
+
                e = source.source();
+
            }
+
            EXIT_ERROR
+
        }
+
    };
+
    exit(code);
+
}
+

+
fn fallible_main() -> Result<bool, Box<dyn std::error::Error>> {
+
    let runspec = RunSpec::from_file(Path::new(RUNSPEC_PATH))?;
+
    let shell = format!("set -xeuo pipefail\n{}", runspec.shell);
+
    let exit = Command::new("bash").args(["-c", &shell]).spawn()?.wait()?;
+
    Ok(exit.success())
+
}