Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
add rad-ci binary
Merged liw opened 1 year ago

Signed-off-by: Lars Wirzenius liw@liw.fi

2 files changed +55 -1 6b0b32bb 70535d85
modified README.md
@@ -18,8 +18,21 @@ shell: |
  cargo test --locked --workspace
```

-
 [Radicle CI broker]: https://app.radicle.xyz/nodes/radicle.liw.fi/rad:zwTxygwuz5LDGBq255RA2CbNGrz8
+
[Radicle CI broker]: https://app.radicle.xyz/nodes/radicle.liw.fi/rad:zwTxygwuz5LDGBq255RA2CbNGrz8

+
This crate also includes the program `rad-ci`, which runs the commands
+
the adapter runs when invoked by the CI broker. To use: install it on
+
your `$PATH` (using `cargo install`) and run:
+

+
```sh
+
rad ci
+
```
+

+
This will read `.radicle/native.yaml` and run the shell commands
+
specified there.
+

+
(No command line arguments or options needed, nor any environment
+
variables for this.)

## Architecture

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())
+
}