Radish alpha
r
rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE
Radicle CI adapter for native CI
Radicle
Git
log run info even when run fail
Lars Wirzenius committed 2 years ago
commit 142675e9f1db6f65132298661304b4fba9befc09
parent ee63219
2 files changed +21 -32
modified src/main.rs
@@ -77,17 +77,15 @@ fn fallible_main_inner(config: &Config, logfile: &mut LogFile) -> Result<(), Nat
    let req = read_request()?;
    logfile.write(format!("request: {:#?}\n", req))?;

-
    let run_info = if let Request::Trigger { repo, commit } = req {
+
    let mut builder = RunInfo::builder()
+
        .id(run_id.clone())
+
        .log(&config.state, run_log.clone());
+

+
    if let Request::Trigger { repo, commit } = req {
        info!("Request to trigger CI on {}, {}", repo, commit);
+
        builder = builder.repo(repo).commit(commit);
        let result = run(
-
            run_id,
-
            storage,
-
            repo,
-
            commit,
-
            &src,
-
            logfile,
-
            &run_log,
-
            &config.state,
+
            run_id, storage, repo, commit, &src, logfile, &run_log, builder,
        );
        logfile.write(format!("CI result: {:?}\n", result))?;
        if let Err(e) = result {
@@ -95,18 +93,18 @@ fn fallible_main_inner(config: &Config, logfile: &mut LogFile) -> Result<(), Nat
            return Err(e);
        }
        logfile.write_str("CI run exited zero")?;
-
        result.unwrap()
+
        let run_info = result.unwrap();
+
        run_info.write(&run_info_file)?;
    } else {
        write_response(&Response::error("first request was not Trigger\n"))?;
-
        RunInfo::builder()
+
        let run_info = RunInfo::builder()
            .id(run_id)
            .log(&config.state, run_log)
            .result(RunResult::Error("first request was not Trigger".into()))
-
            .build()?
+
            .build()?;
+
        run_info.write(&run_info_file)?;
    };

-
    run_info.write(&run_info_file)?;
-

    logfile.write_str("radicle-native-ci ends successfully")?;
    info!("radicle-native-ci ends");
    Ok(())
@@ -151,7 +149,7 @@ fn run(
    src: &Path,
    log: &mut LogFile,
    run_log: &Path,
-
    state: &Path,
+
    builder: RunInfoBuilder,
) -> Result<RunInfo, NativeError> {
    let mut run_log = LogFile::open(run_log)?;

@@ -198,13 +196,7 @@ fn run(

    std::fs::remove_dir_all(src).map_err(|e| NativeError::RemoveDir(src.into(), e))?;

-
    let info = RunInfo::builder()
-
        .repo(repo)
-
        .commit(commit)
-
        .id(run_id)
-
        .result(result)
-
        .log(state, run_log.filename().into())
-
        .build()?;
+
    let info = builder.result(result).build()?;

    Ok(info)
}
@@ -306,10 +298,6 @@ struct LogFile {
}

impl LogFile {
-
    fn filename(&self) -> &Path {
-
        self.filename.as_path()
-
    }
-

    fn open(filename: &Path) -> Result<Self, NativeError> {
        let file = OpenOptions::new()
            .append(true)
modified test.sh
@@ -25,7 +25,7 @@ expect_failure() {
cargo build --all-targets --quiet

tmp="$(mktemp -d)"
-
#trap 'rm -rf "$tmp"' EXIT
+
trap 'rm -rf "$tmp"' EXIT
export TMPDIR="$tmp"

cat <<EOF >"$tmp/config.yaml"
@@ -38,11 +38,12 @@ export RADICLE_NATIVE_CI_LOG=debug

python3 test.py --commit b3a9a809420c89d08460046683f33d8a5bdfdc0a >"$tmp/test-request.yaml"
expect_failure
-
echo "test.log"
-
cat "$tmp/test.log"

-
echo
-
echo "log.txt"
-
cat "$tmp/test.state"/*/log.txt
+
# echo "test.log"
+
# cat "$tmp/test.log"
+

+
# echo
+
# echo "log.txt"
+
# cat "$tmp/test.state"/*/log.txt

echo All good.