diff --git a/src/bin/radicle-native-ci.rs b/src/bin/radicle-native-ci.rs index 3f3ff62..da6b26f 100644 --- a/src/bin/radicle-native-ci.rs +++ b/src/bin/radicle-native-ci.rs @@ -213,7 +213,7 @@ impl<'a> Runner<'a> { fn run(&mut self) -> Result<(), NativeError> { self.log(format!("CI run on {}, {}\n", self.repo, self.commit))?; - self.run_log_str("# Log from Radicle native CI\n\n")?; + self.run_log.h1("Log from Radicle native CI")?; self.run_log(format!("* Repository id: `{}`\n", self.repo))?; self.run_log(format!("* Commit: `{}`\n\n", self.commit))?; diff --git a/src/logfile.rs b/src/logfile.rs index 352a332..83911ee 100644 --- a/src/logfile.rs +++ b/src/logfile.rs @@ -23,6 +23,44 @@ impl LogFile { }) } + pub fn h1(&mut self, text: &str) -> Result<(), LogError> { + self.write_str("# ")?; + self.write_str(text)?; + self.write_str("\n\n")?; + Ok(()) + } + + pub fn h2(&mut self, text: &str) -> Result<(), LogError> { + self.write_str("## ")?; + self.write_str(text)?; + self.write_str("\n\n")?; + Ok(()) + } + + pub fn h3(&mut self, text: &str) -> Result<(), LogError> { + self.write_str("### ")?; + self.write_str(text)?; + self.write_str("\n\n")?; + Ok(()) + } + + pub fn fenced(&mut self, msg: &str, data: &[u8]) -> Result<(), LogError> { + const FENCED_BLOCK: &str = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; + self.h3(msg)?; + self.write_str(FENCED_BLOCK)?; + if !data.is_empty() { + let text = String::from_utf8_lossy(data); + self.write_str(&text)?; + if !text.ends_with('\n') { + self.write_str("\n")?; + } + } + self.write_str(FENCED_BLOCK)?; + self.write_str("\n")?; + + Ok(()) + } + pub fn write(&mut self, msg: String) -> Result<(), LogError> { self.write_str(&msg) } diff --git a/src/runcmd.rs b/src/runcmd.rs index 7076c18..8c81805 100644 --- a/src/runcmd.rs +++ b/src/runcmd.rs @@ -11,7 +11,7 @@ pub fn runcmd(log: &mut LogFile, argv: &[&str], cwd: &Path) -> Result<(), RunCmd debug!("runcmd: argv={:?}", argv); debug!("runcmd: cwd={:?}", cwd); - log.write_str("## Run command\n\n")?; + log.h2("Run command")?; log.write(format!("~~~\n{:?}\n~~~\n\n", argv))?; log.write(format!("in directory: {}\n\n", cwd.display()))?; @@ -24,13 +24,13 @@ pub fn runcmd(log: &mut LogFile, argv: &[&str], cwd: &Path) -> Result<(), RunCmd .map_err(|e| RunCmdError::Command(argv.iter().map(|s| s.to_string()).collect(), e))?; debug!("{:#?}", output); - fenced(log, "Standard output:", &output.stdout)?; - fenced(log, "Standard error:", &output.stderr)?; - let exit = output.status; debug!("exit: {:?}", exit); log.write(format!("Exit: {}\n\n\n", exit.code().unwrap()))?; + log.fenced("Standard output", &output.stdout)?; + log.fenced("Standard error", &output.stderr)?; + if !exit.success() { let error = Response::error(&format!("command failed: {:?}", argv)); error @@ -44,23 +44,6 @@ pub fn runcmd(log: &mut LogFile, argv: &[&str], cwd: &Path) -> Result<(), RunCmd Ok(()) } -fn fenced(log: &mut LogFile, msg: &str, data: &[u8]) -> Result<(), RunCmdError> { - const FENCED_BLOCK: &str = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; - log.write_str(msg)?; - log.write_str("\n")?; - log.write_str(FENCED_BLOCK)?; - if !data.is_empty() { - let text = String::from_utf8_lossy(data); - log.write_str(&text)?; - if !text.ends_with('\n') { - log.write_str("\n")?; - } - } - log.write_str(FENCED_BLOCK)?; - log.write_str("\n")?; - Ok(()) -} - #[derive(Debug, thiserror::Error)] pub enum RunCmdError { #[error("failed to write response to stdout: {0:?}")]