summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-01-10 16:54:45 +0200
committerLars Wirzenius <liw@liw.fi>2024-01-10 17:38:05 +0200
commitddfedf5985b4da1fa37178ad2162861c4fa711c3 (patch)
tree2ae52c642be2d3c59954e8b7911b137e5c192c2a
parent6083f087d7eeb278b73c82c002078c2fe3cd2999 (diff)
downloadradicle-native-ci-ddfedf5985b4da1fa37178ad2162861c4fa711c3.tar.gz
refactor: don't write run info file unless requested
Also, rename id to run_id for clarity. Found this out the hard way while debugging. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/bin/radicle-native-ci.rs2
-rw-r--r--src/report.rs2
-rw-r--r--src/runinfo.rs24
3 files changed, 15 insertions, 13 deletions
diff --git a/src/bin/radicle-native-ci.rs b/src/bin/radicle-native-ci.rs
index 13ea44c..0c3910c 100644
--- a/src/bin/radicle-native-ci.rs
+++ b/src/bin/radicle-native-ci.rs
@@ -95,7 +95,7 @@ fn fallible_main_inner(
let req = read_request()?;
logfile.writeln(&format!("request: {:#?}", req))?;
- builder.id(run_id.clone());
+ builder.run_id(run_id.clone());
builder.log(&config.state, run_log.clone());
builder.run_info(run_info_file.clone());
diff --git a/src/report.rs b/src/report.rs
index 5ab7d4c..b027133 100644
--- a/src/report.rs
+++ b/src/report.rs
@@ -76,7 +76,7 @@ fn list_runs(repos: &[&str], run_infos: &[RunInfo]) -> Document {
let run_id = Element::new(Tag::Code)
.with_class("run_id")
- .with_text(&ri.id);
+ .with_text(&ri.run_id);
let timestamp = Element::new(Tag::Span)
.with_class("timestamp")
diff --git a/src/runinfo.rs b/src/runinfo.rs
index 554218f..0e09dee 100644
--- a/src/runinfo.rs
+++ b/src/runinfo.rs
@@ -18,7 +18,7 @@ pub struct RunInfo {
pub commit: String,
/// Identifier for the CI run.
- pub id: String,
+ pub run_id: String,
/// Result of the CI run.
pub result: RunResult,
@@ -28,7 +28,7 @@ pub struct RunInfo {
/// Name of run info file.
#[serde(skip)]
- pub run_info: PathBuf,
+ pub run_info: Option<PathBuf>,
/// Timestamp of when the run ended (the value was created).
/// ISO8601 format.
@@ -41,10 +41,12 @@ impl RunInfo {
}
pub fn write(&self) -> Result<(), RunInfoError> {
- info!("Writing run info to {}", self.run_info.display());
- let yaml = serde_yaml::to_string(&self).map_err(RunInfoError::SerializeRunInfo)?;
- std::fs::write(&self.run_info, yaml.as_bytes())
- .map_err(|e| RunInfoError::WriteRunInfo(self.run_info.clone(), e))?;
+ if let Some(filename) = &self.run_info {
+ info!("Writing run info to {}", filename.display());
+ let yaml = serde_yaml::to_string(&self).map_err(RunInfoError::SerializeRunInfo)?;
+ std::fs::write(filename, yaml.as_bytes())
+ .map_err(|e| RunInfoError::WriteRunInfo(filename.into(), e))?;
+ }
Ok(())
}
}
@@ -54,7 +56,7 @@ impl RunInfo {
pub struct RunInfoBuilder {
repo: Option<Id>,
commit: Option<Oid>,
- id: Option<String>,
+ run_id: Option<String>,
result: Option<RunResult>,
log: Option<PathBuf>,
run_info: Option<PathBuf>,
@@ -69,8 +71,8 @@ impl RunInfoBuilder {
self.commit = Some(commit);
}
- pub fn id(&mut self, id: RunId) {
- self.id = Some(format!("{}", id));
+ pub fn run_id(&mut self, id: RunId) {
+ self.run_id = Some(format!("{}", id));
}
pub fn result(&mut self, result: RunResult) {
@@ -94,12 +96,12 @@ impl RunInfoBuilder {
Ok(RunInfo {
repo: self.repo.map(|x| x.to_string()).unwrap_or("".into()),
commit: self.commit.map(|x| x.to_string()).unwrap_or("".into()),
- id: self.id.unwrap_or("<unknown>".into()),
+ run_id: self.run_id.unwrap_or("<unknown>".into()),
result: self
.result
.ok_or(RunInfoError::MissingInfo("result".into()))?,
log: self.log.unwrap_or("<unknown>".into()),
- run_info: self.run_info.unwrap_or("<unknown>".into()),
+ run_info: self.run_info,
timestamp: now,
})
}