summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-05-30 02:39:44 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-05-30 02:43:03 -0400
commitc0a688a24d2582ade596edf8db0e4ded92b0caa6 (patch)
tree9086835ffb466d6eab310d7e79e958dcbe02087b
parentc59e34f27154783f99319c932dab91ce1ba32bdc (diff)
gc-resultscapnp
Add a tool for deleting results for unreferenced commits Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--ci-web/src/bin/gc-results.rs92
-rw-r--r--ci-web/src/bin/get-test-job.rs1
2 files changed, 92 insertions, 1 deletions
diff --git a/ci-web/src/bin/gc-results.rs b/ci-web/src/bin/gc-results.rs
new file mode 100644
index 0000000..a5c9c25
--- /dev/null
+++ b/ci-web/src/bin/gc-results.rs
@@ -0,0 +1,92 @@
+extern crate libc;
+use std::process;
+use std::collections::HashSet;
+use std::fs::DirEntry;
+use ci_cgi::{Ktestrc, ktestrc_read, git_get_commit};
+use clap::Parser;
+
+#[derive(Parser)]
+#[command(author, version, about, long_about = None)]
+struct Args {
+ #[arg(short, long)]
+ dry_run: bool,
+}
+
+fn branch_get_commits(repo: &git2::Repository,
+ branch: &str,
+ max_commits: usize) -> Vec<String> {
+ let mut walk = repo.revwalk().unwrap();
+ let reference = git_get_commit(&repo, branch.to_string());
+ if reference.is_err() {
+ eprintln!("branch {} not found", branch);
+ return Vec::new();
+ }
+ let reference = reference.unwrap();
+
+ if let Err(e) = walk.push(reference.id()) {
+ eprintln!("Error walking {}: {}", branch, e);
+ return Vec::new();
+ }
+
+ walk.filter_map(|i| i.ok())
+ .take(max_commits)
+ .filter_map(|i| repo.find_commit(i).ok())
+ .map(|i| i.id().to_string())
+ .collect()
+}
+
+fn get_live_commits(rc: &Ktestrc) -> HashSet<String>
+{
+ let repo = git2::Repository::open(&rc.linux_repo);
+ if let Err(e) = repo {
+ eprintln!("Error opening {:?}: {}", rc.linux_repo, e);
+ eprintln!("Please specify correct linux_repo");
+ process::exit(1);
+ }
+ let repo = repo.unwrap();
+
+ rc.branch.iter()
+ .flat_map(move |(branch, branchconfig)| branchconfig.tests.iter()
+ .filter_map(|i| rc.test_group.get(i)).map(move |test_group| (branch, test_group)))
+ .map(|(branch, test_group)| branch_get_commits(&repo, &branch, test_group.max_commits))
+ .flatten()
+ .collect()
+}
+
+fn result_is_live(commits: &HashSet<String>, d: &DirEntry) -> bool {
+ let d = d.file_name().into_string().ok();
+
+ if let Some(d) = d {
+ commits.contains(&d[..40].to_string())
+ } else {
+ false
+ }
+}
+
+fn main() {
+ let args = Args::parse();
+
+ let rc = ktestrc_read();
+ if let Err(e) = rc {
+ eprintln!("could not read config; {}", e);
+ process::exit(1);
+ }
+ let rc = rc.unwrap();
+
+ let commits = get_live_commits(&rc);
+
+ for d in rc.output_dir.read_dir().unwrap()
+ .filter_map(|d| d.ok())
+ .filter(|d| !result_is_live(&commits, &d))
+ .map(|d| d.path()) {
+ println!("Removing: {}", d.to_string_lossy());
+
+ if !args.dry_run {
+ if d.is_dir() {
+ std::fs::remove_dir_all(d).ok();
+ } else {
+ std::fs::remove_file(d).ok();
+ }
+ }
+ }
+}
diff --git a/ci-web/src/bin/get-test-job.rs b/ci-web/src/bin/get-test-job.rs
index 4196ef4..4327576 100644
--- a/ci-web/src/bin/get-test-job.rs
+++ b/ci-web/src/bin/get-test-job.rs
@@ -285,5 +285,4 @@ fn main() {
break;
}
}
-
}