mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-11-21 10:30:49 +08:00
feat: add .radicle/native.yaml to run log
Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
+4
-1
@@ -2,7 +2,7 @@ use std::path::Path;
|
||||
|
||||
use radicle_ci_broker::msg::{Oid, RepoId};
|
||||
|
||||
use radicle_native_ci::runlog::RunLog;
|
||||
use radicle_native_ci::{runlog::RunLog, runspec::RunSpec};
|
||||
|
||||
/// The main program.
|
||||
fn main() {
|
||||
@@ -10,6 +10,9 @@ fn main() {
|
||||
run_log.title("Some Title");
|
||||
run_log.rid(RepoId::from_urn("rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE").expect("rid"));
|
||||
run_log.commit(Oid::try_from("b788f7ffd38572614457adb1656c0b4575b941dd").expect("commit"));
|
||||
run_log.runspec(RunSpec {
|
||||
shell: "echo hello, world".into(),
|
||||
});
|
||||
run_log.runcmd(
|
||||
&["git", "pull"],
|
||||
Path::new("/tmp"),
|
||||
|
||||
+6
-3
@@ -19,7 +19,7 @@ const EXIT_TIMEOUT: i32 = 124;
|
||||
|
||||
// Path to the repository's CI run specification. This is relative to
|
||||
// the root of the repository.
|
||||
const RUNSPEC_PATH: &str = ".radicle/native.yaml";
|
||||
pub const RUNSPEC_PATH: &str = ".radicle/native.yaml";
|
||||
|
||||
/// Execute the project-specific parts of a CI run. This needs to be
|
||||
/// set up with `set_*` methods, and then the [`run`](Run::run) method
|
||||
@@ -131,13 +131,16 @@ impl Run {
|
||||
|
||||
let runspec_path = self.src.join(RUNSPEC_PATH);
|
||||
let runspec = match RunSpec::from_file(&runspec_path) {
|
||||
Ok(runspec) => runspec,
|
||||
Ok(runspec) => {
|
||||
self.run_log.runspec(runspec.clone());
|
||||
runspec
|
||||
}
|
||||
Err(e) => {
|
||||
// Log error in run log, then return. We can't do
|
||||
// anything more if we don't have the run spec.
|
||||
// However, return `Ok`, so that the CI engine doesn't
|
||||
// report that the engine failed.
|
||||
self.run_log.runspec(&e);
|
||||
self.run_log.runspec_error(&e);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
+26
-2
@@ -4,7 +4,10 @@ use html_page::{Document, Element, Tag};
|
||||
|
||||
use radicle_ci_broker::msg::{Oid, RepoId};
|
||||
|
||||
use crate::runspec::{RunSpec, RunSpecError};
|
||||
use crate::{
|
||||
run::RUNSPEC_PATH,
|
||||
runspec::{RunSpec, RunSpecError},
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct RunLog {
|
||||
@@ -42,7 +45,11 @@ impl RunLog {
|
||||
self.commands.iter().all(|c| c.exit == 0) && !self.timeout && self.runspec_error.is_none()
|
||||
}
|
||||
|
||||
pub fn runspec(&mut self, e: &RunSpecError) {
|
||||
pub fn runspec(&mut self, runspec: RunSpec) {
|
||||
self.runspec = Some(runspec);
|
||||
}
|
||||
|
||||
pub fn runspec_error(&mut self, e: &RunSpecError) {
|
||||
self.runspec_error = Some(format!("{}", e));
|
||||
}
|
||||
|
||||
@@ -100,6 +107,20 @@ impl RunLog {
|
||||
doc.push_to_body(&timeout);
|
||||
}
|
||||
|
||||
if let Some(runspec) = &self.runspec {
|
||||
let text = serde_yaml::to_string(&runspec).map_err(RunLogError::RunSpec)?;
|
||||
let native_yaml = Element::new(Tag::Div)
|
||||
.with_child(
|
||||
Element::new(Tag::H2)
|
||||
.with_child(Element::new(Tag::Code).with_text(RUNSPEC_PATH)),
|
||||
)
|
||||
.with_child(
|
||||
Element::new(Tag::Blockquote)
|
||||
.with_child(Element::new(Tag::Code).with_text(&text)),
|
||||
);
|
||||
doc.push_to_body(&native_yaml);
|
||||
}
|
||||
|
||||
let mut toc = ToC::default();
|
||||
let mut body = Element::new(Tag::Div);
|
||||
for cmd in self.commands.iter() {
|
||||
@@ -221,4 +242,7 @@ pub enum RunLogError {
|
||||
|
||||
#[error("failed to write HTML run log to {0}")]
|
||||
Write(PathBuf, #[source] std::io::Error),
|
||||
|
||||
#[error("failed to serialize run spec to YAML")]
|
||||
RunSpec(#[source] serde_yaml::Error),
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::logfile::LogError;
|
||||
|
||||
/// How to run CI for this repository.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[allow(dead_code)]
|
||||
pub struct RunSpec {
|
||||
|
||||
Reference in New Issue
Block a user