Skip to content

Commit

Permalink
gen-job-list: add verbose option
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
  • Loading branch information
Kent Overstreet committed Jul 10, 2024
1 parent c7551e9 commit 1c7a058
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 20 additions & 5 deletions src/bin/gen-job-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use file_lock::{FileLock, FileOptions};
use memoize::memoize;
use anyhow;
use chrono::Utc;
use clap::Parser;

#[memoize]
fn get_subtests(test_path: PathBuf) -> Vec<String> {
Expand Down Expand Up @@ -174,7 +175,9 @@ fn rc_test_jobs(rc: &CiConfig, repo: &git2::Repository,
ret
}

fn write_test_jobs(rc: &CiConfig, jobs_in: Vec<TestJob>) -> anyhow::Result<()> {
fn write_test_jobs(rc: &CiConfig, jobs_in: Vec<TestJob>, verbose: bool) -> anyhow::Result<()> {
eprintln!("Writing new test jobs");

let jobs_fname = rc.ktest.output_dir.join("jobs");
let jobs_fname_new = rc.ktest.output_dir.join("jobs.new");
let mut jobs_out = std::io::BufWriter::new(File::create(&jobs_fname_new)?);
Expand Down Expand Up @@ -259,23 +262,33 @@ fn fetch_remotes(rc: &CiConfig, repo: &git2::Repository) -> anyhow::Result<bool>
Ok(true)
}

fn update_jobs(rc: &CiConfig, repo: &git2::Repository) -> anyhow::Result<()> {
fn update_jobs(rc: &CiConfig, repo: &git2::Repository, verbose: bool) -> anyhow::Result<()> {
if !fetch_remotes(rc, repo)? {
eprintln!("remotes unchanged, skipping updating joblist");
return Ok(());
}

let lockfile = rc.ktest.output_dir.join("jobs.lock");
let filelock = FileLock::lock(lockfile, true, FileOptions::new().create(true).write(true))?;

let jobs_in = rc_test_jobs(rc, repo, false);
write_test_jobs(rc, jobs_in)?;
let jobs_in = rc_test_jobs(rc, repo, verbose);
write_test_jobs(rc, jobs_in, verbose)?;

drop(filelock);

Ok(())
}

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long)]
verbose: bool,
}

fn main() {
let args = Args::parse();

let rc = ciconfig_read();
if let Err(e) = rc {
eprintln!("could not read config; {}", e);
Expand All @@ -291,5 +304,7 @@ fn main() {
}
let repo = repo.unwrap();

update_jobs(&rc, &repo).ok();
if let Err(e) = update_jobs(&rc, &repo, args.verbose) {
eprintln!("update_jobs() error: {}", e);
}
}
6 changes: 1 addition & 5 deletions src/bin/get-test-job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::process;
use ci_cgi::{Ktestrc, ciconfig_read, lockfile_exists};
use ci_cgi::{Worker, workers_update};
use file_lock::{FileLock, FileOptions};
use clap::Parser;
use chrono::Utc;
use clap::Parser;

#[derive(Debug)]
struct TestJob {
Expand Down Expand Up @@ -131,10 +131,6 @@ fn get_and_lock_job(rc: &Ktestrc) -> Option<TestJob> {
}

fn main() {
std::process::Command::new("gen-job-list")
.output()
.expect("failed to execute gen-job-list");

let args = Args::parse();

let rc = ciconfig_read();
Expand Down

0 comments on commit 1c7a058

Please sign in to comment.