Add per-repo config.
This commit is contained in:
parent
28e430c8cf
commit
11b08785ed
@ -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" } }
|
||||
|
||||
44
src/main.rs
44
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<TaskStatus, SyncError> {
|
||||
info!("{:?}", cmd);
|
||||
info!(
|
||||
"{}$ {} {}",
|
||||
cmd.get_current_dir()
|
||||
.unwrap_or(Path::new("<NO CWD>"))
|
||||
.display(),
|
||||
cmd.get_program().to_string_lossy(),
|
||||
cmd.get_args()
|
||||
.map(|a| a.to_string_lossy())
|
||||
.collect::<Vec<_>>()
|
||||
.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<Config>, repo: &str) -> Result<String, SyncError> {
|
||||
info!("Need to reload '{}': {:?}", repo, config);
|
||||
fn reload(config: &State<Config>, name: &str) -> Result<String, SyncError> {
|
||||
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<Config>, repo: &str) -> Result<String, SyncError> {
|
||||
.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<Config>, repo: &str) -> Result<String, SyncError> {
|
||||
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<Config>, repo: &str) -> Result<String, SyncError> {
|
||||
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<String, Repo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Repo {
|
||||
name: String,
|
||||
branch: String,
|
||||
first_commit: Option<String>,
|
||||
}
|
||||
|
||||
#[launch]
|
||||
@ -252,7 +272,7 @@ fn rocket() -> _ {
|
||||
let config = rocket::Config::figment()
|
||||
.extract::<Config>()
|
||||
.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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user