diff options
author | Lars Wirzenius <liw@liw.fi> | 2024-01-15 18:09:16 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2024-01-15 18:09:16 +0200 |
commit | e786def6cd7b40af8a395016fcba6bd1c2e2833f (patch) | |
tree | 1c0ad22f9ee5667022cde3e1895ff68c044b71d0 | |
parent | 3a56190257eb94ca7d95acf10cdac1f8f4d5435b (diff) | |
download | radicle-native-ci-e786def6cd7b40af8a395016fcba6bd1c2e2833f.tar.gz |
refactor: rename log or logfile to adminlog, for clarity
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r-- | src/bin/radicle-native-ci.rs | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/bin/radicle-native-ci.rs b/src/bin/radicle-native-ci.rs index fcaa051..729514c 100644 --- a/src/bin/radicle-native-ci.rs +++ b/src/bin/radicle-native-ci.rs @@ -55,11 +55,11 @@ fn main() { fn fallible_main() -> Result<(), NativeError> { let config = Config::load_via_env()?; - let mut logfile = config.open_log()?; + let mut adminlog = config.open_log()?; let mut builder = RunInfo::builder(); - let result = fallible_main_inner(&config, &mut logfile, &mut builder); + let result = fallible_main_inner(&config, &mut adminlog, &mut builder); let ri = builder.build()?; match &ri.result { @@ -71,22 +71,22 @@ fn fallible_main() -> Result<(), NativeError> { ri.write()?; - logfile.writeln(&format!("update report page in {}", config.state.display()))?; + adminlog.writeln(&format!("update report page in {}", config.state.display()))?; if let Err(e) = report::build_report(&config.state) { - logfile.writeln(&format!("report generation failed: {}", e))?; + adminlog.writeln(&format!("report generation failed: {}", e))?; } - logfile.writeln(&format!("radicle-native-ci ends: {:?}", result))?; + adminlog.writeln(&format!("radicle-native-ci ends: {:?}", result))?; result } fn fallible_main_inner( config: &Config, - logfile: &mut AdminLog, + adminlog: &mut AdminLog, builder: &mut RunInfoBuilder, ) -> Result<(), NativeError> { let (run_id, run_dir) = mkdir_run(config)?; let run_id = RunId::from(format!("{}", run_id).as_str()); - logfile.writeln(&format!("run directory {}", run_dir.display()))?; + adminlog.writeln(&format!("run directory {}", run_dir.display()))?; let src = run_dir.join("src"); let run_log = run_dir.join("log.html"); @@ -96,7 +96,7 @@ fn fallible_main_inner( let storage = profile.storage.path(); let req = read_request()?; - logfile.writeln(&format!("request: {:#?}", req))?; + adminlog.writeln(&format!("request: {:#?}", req))?; builder.run_id(run_id.clone()); builder.log(&config.state, run_log.clone()); @@ -113,24 +113,24 @@ fn fallible_main_inner( .repo(repo) .commit(commit) .src(&src) - .log(logfile) + .adminlog(adminlog) .run_log(run_log) .timeout(config.timeout) .builder(builder) .build()?; let result = runner.run(); if let Err(e) = result { - logfile.writeln(&format!("CI failed: {:?}", e))?; + adminlog.writeln(&format!("CI failed: {:?}", e))?; builder.result(RunResult::Error(format!("{}", e))); return Err(e); } - logfile.writeln("CI run exited zero")?; + adminlog.writeln("CI run exited zero")?; builder.result(RunResult::Success); } else { builder.result(RunResult::Error("first request was not Trigger".into())); }; - logfile.writeln("radicle-native-ci ends successfully")?; + adminlog.writeln("radicle-native-ci ends successfully")?; Ok(()) } @@ -154,7 +154,7 @@ struct Runner<'a> { repo: Id, commit: Oid, src: PathBuf, - log: &'a mut AdminLog, + adminlog: &'a mut AdminLog, run_log: RunLog, timeout: Option<usize>, builder: &'a mut RunInfoBuilder, @@ -162,7 +162,7 @@ struct Runner<'a> { impl<'a> Runner<'a> { fn git_clone(&mut self, repo_path: &Path) -> Result<(), NativeError> { - self.log.writeln("clone repository")?; + self.adminlog.writeln("clone repository")?; runcmd( &mut self.run_log, &[ @@ -177,7 +177,7 @@ impl<'a> Runner<'a> { } fn git_checkout(&mut self) -> Result<(), NativeError> { - self.log.writeln("check out commit")?; + self.adminlog.writeln("check out commit")?; runcmd( &mut self.run_log, &["git", "checkout", &self.commit.to_string()], @@ -188,7 +188,7 @@ impl<'a> Runner<'a> { /// Perform the CI run. fn run(&mut self) -> Result<(), NativeError> { - self.log + self.adminlog .writeln(&format!("CI run on {}, {}", self.repo, self.commit))?; self.run_log.title("Log from Radicle native CI"); @@ -203,9 +203,10 @@ impl<'a> Runner<'a> { self.git_checkout()?; let runspec = RunSpec::from_file(&self.src.join(RUNSPEC_PATH))?; - self.log.writeln(&format!("CI run spec: {:#?}", runspec))?; + self.adminlog + .writeln(&format!("CI run spec: {:#?}", runspec))?; - self.log.writeln("run shell snippet in repository")?; + self.adminlog.writeln("run shell snippet in repository")?; let snippet = format!("set -xeuo pipefail\n{}", &runspec.shell); let runcmd_result = if let Some(timeout) = self.timeout { let timeout = format!("{}", timeout); @@ -233,7 +234,7 @@ impl<'a> Runner<'a> { self.builder.result(result); if let Err(e) = self.run_log.write() { - self.log + self.adminlog .writeln(&format!("failed to write run log: {}", e))?; } @@ -252,7 +253,7 @@ struct RunnerBuilder<'a> { repo: Option<Id>, commit: Option<Oid>, src: Option<PathBuf>, - log: Option<&'a mut AdminLog>, + adminlog: Option<&'a mut AdminLog>, run_log: Option<RunLog>, timeout: Option<usize>, builder: Option<&'a mut RunInfoBuilder>, @@ -284,8 +285,8 @@ impl<'a> RunnerBuilder<'a> { self } - fn log(mut self, log: &'a mut AdminLog) -> Self { - self.log = Some(log); + fn adminlog(mut self, log: &'a mut AdminLog) -> Self { + self.adminlog = Some(log); self } @@ -311,7 +312,7 @@ impl<'a> RunnerBuilder<'a> { repo: self.repo.ok_or(NativeError::Unset("repo"))?, commit: self.commit.ok_or(NativeError::Unset("commit"))?, src: self.src.ok_or(NativeError::Unset("src"))?, - log: self.log.ok_or(NativeError::Unset("log"))?, + adminlog: self.adminlog.ok_or(NativeError::Unset("log"))?, run_log: self.run_log.ok_or(NativeError::Unset("run_log"))?, timeout: self.timeout, builder: self.builder.ok_or(NativeError::Unset("builder"))?, |