summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-03-04 18:12:52 +0200
committerLars Wirzenius <liw@liw.fi>2024-03-04 18:12:52 +0200
commitd9aafdc87cc7cc396c5a1faca697ea9bb267f397 (patch)
treef28523f937894f313782c7aa94ff486d49eb38d3
parent443bf0b184aa4cd4842d787dd4e8b0874784d5e6 (diff)
downloadradicle-ci-broker-d9aafdc87cc7cc396c5a1faca697ea9bb267f397.tar.gz
fix: link to run log from native CI
We used to have two IDs for each CI run: one assigned by the broker and one by the adapter. The native CI adapter writes logs to a directory named by the id it chose itself: it doesn't know the on chosen by the broker. The broker was generating a report page that links to a run log using the broker-chosen id. Oops. Drop the id chosen by the broker, it doesn't serve any useful purpose anymore. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/adapter.rs4
-rw-r--r--src/bin/pagegen.rs11
-rw-r--r--src/broker.rs10
-rw-r--r--src/pages.rs21
-rw-r--r--src/radicle-ci.css4
-rw-r--r--src/run.rs16
6 files changed, 26 insertions, 40 deletions
diff --git a/src/adapter.rs b/src/adapter.rs
index 328ead4..30ddae1 100644
--- a/src/adapter.rs
+++ b/src/adapter.rs
@@ -183,7 +183,7 @@ mod test {
use super::{Adapter, Run, StatusPage};
use crate::{
adapter::AdapterError,
- msg::{MessageError, Response, RunId, RunResult},
+ msg::{MessageError, Response, RunResult},
pages::PageBuilder,
run::Whence,
test::{mock_adapter, trigger_request, TestResult},
@@ -191,7 +191,6 @@ mod test {
fn run() -> Run {
Run::new(
- RunId::default(),
RepoId::from_urn("rad:zwTxygwuz5LDGBq255RA2CbNGrz8").unwrap(),
"test.repo",
Whence::branch(
@@ -201,7 +200,6 @@ mod test {
"2024-02-29T12:58:12+02:00".into(),
)
}
-
fn status_page() -> StatusPage {
PageBuilder::default()
.node_alias("test.alias")
diff --git a/src/bin/pagegen.rs b/src/bin/pagegen.rs
index 34b9742..2859407 100644
--- a/src/bin/pagegen.rs
+++ b/src/bin/pagegen.rs
@@ -16,11 +16,9 @@ fn main() -> Result<(), PageError> {
.node_alias("radicle.liw.fi")
.build()?;
- let runid1 = RunId::default();
let rid1 = RepoId::from_urn("rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5").unwrap();
let alias1 = "heartwood";
let mut run1 = Run::new(
- runid1.clone(),
rid1,
alias1,
Whence::branch(
@@ -28,9 +26,8 @@ fn main() -> Result<(), PageError> {
Oid::from_str("a48081f2717f069d456ec09f31d9e639b232dbed").unwrap(),
),
"2024-02-27T18:29:25+02:00".into(),
- // RunState::Running,
- // RunResult::Success,
);
+ run1.set_adapter_run_id(RunId::default());
run1.set_state(RunState::Running);
run1.set_result(RunResult::Success);
page.push_run(run1.clone());
@@ -40,7 +37,6 @@ fn main() -> Result<(), PageError> {
page.push_run(run2);
let mut run3 = Run::new(
- RunId::default(),
rid1,
alias1,
Whence::patch(
@@ -48,9 +44,8 @@ fn main() -> Result<(), PageError> {
Oid::from_str("091f7b7e986d05381718e2aeed2497c55dd0179a").unwrap(),
),
"2024-02-27T18:29:09+02:00".into(),
- // RunState::Finished,
- // RunResult::Failure,
);
+ run3.set_adapter_run_id(RunId::default());
run3.set_state(RunState::Finished);
run3.set_result(RunResult::Failure);
page.push_run(run3);
@@ -58,7 +53,6 @@ fn main() -> Result<(), PageError> {
let rid2 = RepoId::from_urn("rad:zwTxygwuz5LDGBq255RA2CbNGrz8").unwrap();
let alias2 = "radicle-ci-broker";
let mut run4 = Run::new(
- RunId::default(),
rid2,
alias2,
Whence::branch(
@@ -67,6 +61,7 @@ fn main() -> Result<(), PageError> {
),
"2024-02-27T18:29:25+02:00".into(),
);
+ run4.set_adapter_run_id(RunId::default());
run4.set_state(RunState::Finished);
run4.set_result(RunResult::Success);
page.push_run(run4);
diff --git a/src/broker.rs b/src/broker.rs
index 5194a93..297b305 100644
--- a/src/broker.rs
+++ b/src/broker.rs
@@ -12,7 +12,7 @@ use radicle::prelude::RepoId;
use crate::{
adapter::Adapter,
error::BrokerError,
- msg::{PatchEvent, PushEvent, Request, RunId},
+ msg::{PatchEvent, PushEvent, Request},
pages::StatusPage,
run::{Run, Whence},
};
@@ -73,13 +73,7 @@ impl Broker {
panic!("neither push not patch event");
};
- let mut run = Run::new(
- RunId::default(),
- *rid,
- &common.repository.name,
- whence,
- now(),
- );
+ let mut run = Run::new(*rid, &common.repository.name, whence, now());
adapter.run(trigger, &mut run, status)?;
run
} else {
diff --git a/src/pages.rs b/src/pages.rs
index bc61243..ed998d2 100644
--- a/src/pages.rs
+++ b/src/pages.rs
@@ -255,9 +255,15 @@ impl PageData {
}
};
- let link = Element::new(Tag::A)
- .with_attribute("href", &format!("{}/log.html", run.broker_run_id()))
- .with_text("log");
+ let link = if let Some(id) = run.adapter_run_id() {
+ Element::new(Tag::A)
+ .with_attribute("href", &format!("{}/log.html", id))
+ .with_text("log")
+ } else {
+ Element::new(Tag::Span)
+ .with_attribute("class", "missing_log")
+ .with_text("no log yet")
+ };
list.push_child(
&Element::new(Tag::Li)
@@ -359,9 +365,12 @@ impl StatusPage {
/// Add a new CI run to the status page.
pub fn push_run(&mut self, new: Run) {
- let mut data = self.lock();
- data.latest_ci_run = Some(new.clone());
- data.runs.insert(new.broker_run_id().clone(), new);
+ // We silently ignore a run until its id has been set.
+ if let Some(id) = new.adapter_run_id() {
+ let mut data = self.lock();
+ data.latest_ci_run = Some(new.clone());
+ data.runs.insert(id.clone(), new);
+ }
}
/// Write the status page (as index.html) and per-repository pages
diff --git a/src/radicle-ci.css b/src/radicle-ci.css
index ab8c5fe..09b5a94 100644
--- a/src/radicle-ci.css
+++ b/src/radicle-ci.css
@@ -18,6 +18,10 @@ span.unknown {
background-color: grey;
}
+span.missing_log {
+ color: red;
+}
+
span.alias {
font-weight: bold;
}
diff --git a/src/run.rs b/src/run.rs
index 94a93b4..efd509d 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -9,7 +9,6 @@ use crate::msg::{RunId, RunResult};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Run {
- broker_run_id: RunId,
adapter_run_id: Option<RunId>,
repo_id: RepoId,
repo_alias: String,
@@ -21,15 +20,8 @@ pub struct Run {
impl Run {
/// Create a new run.
- pub fn new(
- run_id: RunId,
- repo_id: RepoId,
- alias: &str,
- whence: Whence,
- timestamp: String,
- ) -> Self {
+ pub fn new(repo_id: RepoId, alias: &str, whence: Whence, timestamp: String) -> Self {
Self {
- broker_run_id: run_id,
adapter_run_id: None,
repo_id,
repo_alias: alias.into(),
@@ -60,12 +52,6 @@ impl Run {
&self.whence
}
- /// Return the run id assigned by the broker. This is set when the
- /// run is created and can't be changed.
- pub fn broker_run_id(&self) -> &RunId {
- &self.broker_run_id
- }
-
/// Set the run id assigned by the adapter.
pub fn set_adapter_run_id(&mut self, run_id: RunId) {
self.adapter_run_id = Some(run_id);