feat: utility function to run job and write results

This commit is contained in:
Aravinth Manivannan 2023-09-29 19:35:07 +05:30
parent 79dcf895b6
commit 0d332062db
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
1 changed files with 46 additions and 0 deletions

View File

@ -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();
}