From 0d332062db00884ec1fcc2962120e3640c0373a7 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 29 Sep 2023 19:35:07 +0530 Subject: [PATCH] feat: utility function to run job and write results --- src/runner/mod.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/runner/mod.rs b/src/runner/mod.rs index a710d1b..4cdd1d8 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -2,6 +2,52 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later +use std::fs; +use std::path::Path; +use std::path::PathBuf; + +use crate::git::Git; +use crate::runner::results::*; +use crate::AppCtx; + pub mod init_scripts; pub mod results; +pub mod scheduler; pub mod suite; +pub mod target; + +pub async fn run(ctx: AppCtx, commit: &str) { + let base_dir = Path::new(&ctx.settings.repository.base_dir); + let control = base_dir.join("control"); + + Git::checkout_commit(commit, &control); + + for entry in crate::runner::target::get_targets(&control).iter() { + let (suite_results, init_containers) = + crate::runner::target::run_target(&ctx, entry.into()).await; + let content = ArchivableResult { + commit: commit.to_string(), + suites: suite_results, + init_containers, + }; + + let results_repo = base_dir.join("results"); + write_res(&content, results_repo, entry.into(), commit); + } + Git::checkout_commit("master", &control); +} + +fn write_res(res: &ArchivableResult, results_repo: PathBuf, entry: PathBuf, commit: &str) { + let results_dir = results_repo.join(entry.file_name().unwrap()); + if !results_dir.exists() { + fs::create_dir_all(&results_dir).unwrap(); + } + let latest_file = results_dir.join("latest.json"); + let results_file = results_dir.join(format!("{commit}.json")); + fs::write(results_file, serde_json::to_string(&res).unwrap()).unwrap(); + + let latest = LatestFile { + latest: commit.to_string(), + }; + fs::write(latest_file, serde_json::to_string(&latest).unwrap()).unwrap(); +}