Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat(cibtool): add command to produce HTML report from database
Lars Wirzenius committed 1 year ago
commit 968d0e091b0b3c9943aef24f9dd08504296a6673
parent 6cd968d48078c86f866d8868d8f7fcea65c504d0
2 files changed +66 -1
modified ci-broker.md
@@ -417,6 +417,30 @@ then command is successful
~~~


+
## Produces a report page upon request
+

+
_Requirement:_ The node operator can run a command to produce a report
+
of all CI runs a CI broker instance has performed.
+

+
_Justification:_ This is useful for diagnosis, if nothing else.
+

+
_Stakeholder:_ Lars.
+

+
~~~scenario
+
given an installed cibtool
+
when I run cibtool --db x.db run add --id x --repo rad:zwTxygwuz5LDGBq255RA2CbNGrz8 --alias x --url https://x/1 --branch main --commit f1815dde6ae406d8fe3cec0b96c4486766342716 --who x --finished --failure --timestamp 2024-07-09T02:00:00
+

+
given a directory reports
+
when I run cibtool --db x.db report --output-dir reports
+

+
then file reports/index.html exists
+
then file reports/index.html contains "zwTxygwuz5LDGBq255RA2CbNGrz8"
+

+
then file reports/zwTxygwuz5LDGBq255RA2CbNGrz8.html exists
+
then file reports/zwTxygwuz5LDGBq255RA2CbNGrz8.html contains "success"
+
~~~
+

+

# Acceptance criteria for test tooling

The event synthesizer is a helper to feed the CI broker node events in
modified src/bin/cibtool.rs
@@ -20,7 +20,8 @@ use radicle_ci_broker::{
    broker::BrokerError,
    db::{Db, DbError, QueueId},
    event::BrokerEvent,
-
    msg::RunId,
+
    msg::{RunId, RunResult},
+
    pages::{PageBuilder, PageError},
    run::{Run, Whence},
};

@@ -62,6 +63,7 @@ impl Args {
            Cmd::Counter(x) => x.run(self)?,
            Cmd::Event(x) => x.run(self)?,
            Cmd::Run(x) => x.run(self)?,
+
            Cmd::Report(x) => x.run(self)?,
        }
        Ok(())
    }
@@ -77,6 +79,7 @@ enum Cmd {
    Counter(CounterCmd),
    Event(EventCmd),
    Run(RunCmd),
+
    Report(ReportCmd),
}

#[derive(Parser)]
@@ -528,6 +531,12 @@ impl AddRun {
            run.set_adapter_info_url(url);
        }

+
        run.set_result(if self.success {
+
            RunResult::Success
+
        } else {
+
            RunResult::Failure
+
        });
+

        db.push_run(run).unwrap();

        Ok(())
@@ -551,6 +560,35 @@ impl ListRuns {
    }
}

+
#[derive(Parser)]
+
struct ReportCmd {
+
    #[clap(long)]
+
    output_dir: PathBuf,
+
}
+

+
impl ReportCmd {
+
    #[allow(clippy::result_large_err)]
+
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
+
        let db = args.open_db()?;
+

+
        let mut runs = vec![];
+
        for id in db.list_runs()? {
+
            if let Some(run) = db.get_run(&id)? {
+
                runs.push(run);
+
            }
+
        }
+

+
        let mut page = PageBuilder::default()
+
            .node_alias("FIXME")
+
            .runs(runs)
+
            .build()?;
+

+
        page.write(&self.output_dir)?;
+

+
        Ok(())
+
    }
+
}
+

#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
enum CibToolError {
@@ -589,4 +627,7 @@ enum CibToolError {

    #[error("failed to write file: {0}")]
    Write(PathBuf, #[source] std::io::Error),
+

+
    #[error(transparent)]
+
    Page(#[from] PageError),
}