From 11b08785edebfb2860096517d5db84c960271d47 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 5 Dec 2022 20:47:08 -0800 Subject: [PATCH] Add per-repo config. --- Rocket.toml | 2 ++ src/main.rs | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Rocket.toml b/Rocket.toml index d5a7f04..2f8f6a5 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -11,3 +11,5 @@ port = 9346 source_root = "/net/nasx/mnt/storage/aoc/github/" build_root = "/tmp/aocsync/" www_root = "/tmp/aocsync-serve/" + +repos = { akramer = { name = "aoc2022", branch = "main" }, ggriffiniii = { name = "aoc2022", branch = "main" }, wathiede = { name = "advent/2022", branch = "master", first_commit = "bc3feabb4669b7ad8167398a4d37eefe68ea0565" } } diff --git a/src/main.rs b/src/main.rs index 24f068e..d981bd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate rocket; use std::{ + collections::HashMap, fs, fs::File, io, @@ -60,7 +61,17 @@ struct TaskStatus { } fn logging_run(cmd: &mut Command) -> Result { - info!("{:?}", cmd); + info!( + "{}$ {} {}", + cmd.get_current_dir() + .unwrap_or(Path::new("")) + .display(), + cmd.get_program().to_string_lossy(), + cmd.get_args() + .map(|a| a.to_string_lossy()) + .collect::>() + .join(" "), + ); let start = Instant::now(); let o = cmd.output()?; let ts = TaskStatus { @@ -102,17 +113,18 @@ fn bench_at_commit( Ok(output) } -fn reload(config: &State, repo: &str) -> Result { - info!("Need to reload '{}': {:?}", repo, config); +fn reload(config: &State, name: &str) -> Result { + let repo = &config.repos[name]; + info!("Need to reload '{}': {:?}\n{:#?}", name, config, repo); let commits_root = config.build_root.join("commits"); - let git_root = config.build_root.join("git"); - let www_root = config.www_root.join(repo); + let git_root = config.build_root.join("git").join(name); + let www_root = config.www_root.join(name); let target_root = config.build_root.join("target"); - let source_path = config.source_root.join(repo); - let build_path = git_root.join(repo); - let target_path = target_root.join(repo); + let source_path = config.source_root.join(name).join(&repo.name); + let build_path = git_root.join(&repo.name); + let target_path = target_root.join(name); dbg!( &source_path, @@ -154,7 +166,7 @@ fn reload(config: &State, repo: &str) -> Result { .current_dir(&build_path) .arg("checkout") .arg("-f") - .arg("origin"), + .arg(&repo.branch), )?); dbg!(&build_path); // Make sure buildable clone is up to date @@ -164,7 +176,7 @@ fn reload(config: &State, repo: &str) -> Result { let commits = logging_run(Command::new("git").current_dir(&build_path).args([ "log", "--format=%H", - "origin", + &repo.branch, ]))?; let binding = String::from_utf8_lossy(&commits.output.stdout).into_owned(); let mut unknown_commits: Vec<_> = binding @@ -180,7 +192,7 @@ fn reload(config: &State, repo: &str) -> Result { output.extend(outputs); File::create(commits_root.join(commit))?; } - Err(err) => error!("Failed to bench {}@{}: {}", repo, commit, err), + Err(err) => error!("Failed to bench {}@{}: {}", name, commit, err), } } // Copy files from `target/` to serving directory @@ -236,6 +248,14 @@ struct Config { source_root: PathBuf, build_root: PathBuf, www_root: PathBuf, + repos: HashMap, +} + +#[derive(Debug, Deserialize)] +struct Repo { + name: String, + branch: String, + first_commit: Option, } #[launch] @@ -252,7 +272,7 @@ fn rocket() -> _ { let config = rocket::Config::figment() .extract::() .expect("Couldn't parse config"); - + info!("Config:\n{:#?}", config); rocket::build() .mount("/", routes![index, get_reload, post_reload]) .mount("/results/", FileServer::from(config.www_root))