ftest/src/runner/mod.rs

55 lines
1.7 KiB
Rust

// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// 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::AppFullCtx;
pub mod init_scripts;
pub mod results;
pub mod scheduler;
pub mod suite;
pub mod target;
pub async fn run(ctx: AppFullCtx, 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, target_logs) =
crate::runner::target::run_target(ctx.as_ref(), entry.into()).await;
let content = ArchivableResult {
commit: commit.to_string(),
suites: suite_results,
init_containers,
specimen_logs : target_logs,
};
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();
}