summaryrefslogtreecommitdiff
path: root/ci-web/src/lib.rs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-01-26 14:46:01 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-03 13:41:16 -0500
commitf212ca7ac70982d6a006783a99a4b356feaf550d (patch)
tree7f8fb1e3157503560d291a75a2303a6ddc4cc72d /ci-web/src/lib.rs
parent0f740d2cf11e1a4d9ec4ae800db6c8d1adab4ad1 (diff)
ci-web: Kill BRANCHES-TO-TEST
This moves the branches to test/test configuration into ktestrc Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'ci-web/src/lib.rs')
-rw-r--r--ci-web/src/lib.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/ci-web/src/lib.rs b/ci-web/src/lib.rs
index b4bd65c..412b756 100644
--- a/ci-web/src/lib.rs
+++ b/ci-web/src/lib.rs
@@ -1,18 +1,10 @@
use std::collections::BTreeMap;
-use std::fs::File;
use std::fs::read_to_string;
-use std::io::{self, BufRead};
use std::error::Error;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use serde_derive::{Serialize, Deserialize};
use toml;
-pub fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
-where P: AsRef<Path>, {
- let file = File::open(filename)?;
- Ok(io::BufReader::new(file).lines())
-}
-
pub fn git_get_commit(repo: &git2::Repository, reference: String) -> Result<git2::Commit, git2::Error> {
let r = repo.revparse_single(&reference);
if let Err(e) = r {
@@ -29,15 +21,37 @@ pub fn git_get_commit(repo: &git2::Repository, reference: String) -> Result<git2
}
#[derive(Deserialize)]
+pub struct KtestrcTestGroup {
+ pub max_commits: usize,
+ pub priority: usize,
+ pub tests: Vec<PathBuf>,
+}
+
+#[derive(Deserialize)]
+pub struct KtestrcBranch {
+ pub remote: String,
+ pub branch: Option<String>,
+ pub tests: Vec<String>,
+}
+
+#[derive(Deserialize)]
pub struct Ktestrc {
- pub ci_linux_repo: PathBuf,
- pub ci_output_dir: PathBuf,
- pub ci_branches_to_test: PathBuf,
+ pub linux_repo: PathBuf,
+ pub output_dir: PathBuf,
+ pub ktest_dir: PathBuf,
+ pub test_group: BTreeMap<String, KtestrcTestGroup>,
+ pub branch: BTreeMap<String, KtestrcBranch>,
}
pub fn ktestrc_read() -> Result<Ktestrc, Box<dyn Error>> {
let config = read_to_string("/etc/ktest-ci.toml")?;
- let ktestrc: Ktestrc = toml::from_str(&config)?;
+ let mut ktestrc: Ktestrc = toml::from_str(&config)?;
+
+ for (branch, branchconfig) in ktestrc.branch.iter_mut() {
+ if branchconfig.branch.is_none() {
+ branchconfig.branch = Some(branch.to_string());
+ }
+ }
Ok(ktestrc)
}
@@ -117,7 +131,7 @@ fn read_test_result(testdir: &std::fs::DirEntry) -> Option<TestResult> {
pub fn commitdir_get_results(ktestrc: &Ktestrc, commit_id: &String) -> TestResultsMap {
let mut results = BTreeMap::new();
- let results_dir = ktestrc.ci_output_dir.join(commit_id).read_dir();
+ let results_dir = ktestrc.output_dir.join(commit_id).read_dir();
if let Ok(results_dir) = results_dir {
for d in results_dir.filter_map(|i| i.ok()) {
@@ -131,7 +145,7 @@ pub fn commitdir_get_results(ktestrc: &Ktestrc, commit_id: &String) -> TestResul
}
pub fn commitdir_get_results_toml(ktestrc: &Ktestrc, commit_id: &String) -> Result<TestResultsMap, Box<dyn Error>> {
- let toml = read_to_string(ktestrc.ci_output_dir.join(commit_id.to_owned() + ".toml"))?;
+ let toml = read_to_string(ktestrc.output_dir.join(commit_id.to_owned() + ".toml"))?;
let r: TestResults = toml::from_str(&toml)?;
Ok(r.d)
}