From 9ce1d87174ba26a0b8b568ab0818846c6e960c04 Mon Sep 17 00:00:00 2001 From: askiiart Date: Fri, 31 Jan 2025 19:36:39 -0600 Subject: [PATCH 1/5] change behavior of dependency_map() --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2b79ee7..733d4ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -306,25 +306,30 @@ impl State { /// /// ```json /// { - /// "packages.some-librewolf-dependency.packaging.fedora": [ - /// "packages.librewolf.compilation", - /// "packages.librewolf.packaging.fedora", - /// ], /// "packages.some-librewolf-dependency.compilation": [ /// "packages.librewolf.compilation", /// "packages.librewolf.packaging.fedora", /// "packages.some-librewolf-dependency.packaging.fedora", /// ], + /// "packages.librewolf.packaging.fedora": [], /// "packages.librewolf.compilation": [ /// "packages.librewolf.packaging.fedora", /// ], + /// "packages.some-librewolf-dependency.packaging.fedora": [ + /// "packages.librewolf.compilation", + /// "packages.librewolf.packaging.fedora", + /// ], /// } /// ``` fn dependency_map(jobs: HashMap, conf: Config) -> HashMap> { let mut dep_map: HashMap> = HashMap::new(); // holds job ids and every job they depend on (recursively) - not just specified dependencies, also packaging depending on compilation for (job_id, _) in jobs.clone() { - let (_, package_name, _) = jod_id_to_metadata(job_id.clone()); + dep_map.insert(job_id, Vec::new()); + } + + for (job_id, _) in jobs.clone() { + let (_, package_name, _) = job_id_to_metadata(job_id.clone()); for dep_name in conf .packages @@ -335,9 +340,6 @@ impl State { { let all_deps = recursive_deps_for_package(dep_name.clone(), conf.clone()); for dep in all_deps { - if !dep_map.contains_key(&dep) { - dep_map.insert(dep.clone(), Vec::new()); - } dep_map.get_mut(&dep).unwrap().push(job_id.clone()); } } From e6dcedd79d072627cad9b911a278dbd1a14d5b2f Mon Sep 17 00:00:00 2001 From: askiiart Date: Fri, 31 Jan 2025 20:57:20 -0600 Subject: [PATCH 2/5] fix typo --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 733d4ec..c08443e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,7 +191,7 @@ fn run_job(conf: &Config, job_id: String, job: Job) -> JobExitStatus { } /// Turns a job name into the relevant data - (category (i.e. "packaging"), package name (i.e. "librewolf"), name (i.e. "compilation")) -fn jod_id_to_metadata(job_id: String) -> (String, String, String) { +fn job_id_to_metadata(job_id: String) -> (String, String, String) { let data = job_id .split(".") .map(|item| item.to_string()) From 362a57715b475d222f7eaf94af69e7a22da80b0c Mon Sep 17 00:00:00 2001 From: askiiart Date: Fri, 31 Jan 2025 21:24:52 -0600 Subject: [PATCH 3/5] add repo updating stuff --- src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.rs b/src/main.rs index c08443e..652752d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,24 @@ async fn run(config_path: String) { ) .await; } + + // run repo updates + for (job_id, job) in update_repo_jobs { + let start_time = SystemTime::now(); + let job_exit_status = run_job(&state.conf, job_id.clone(), job.clone()); + + sql::log_job( + &mut pg_connection, + start_time, + start_time + job_exit_status.duration, + job_exit_status.exit_code, + job_id, + job.revision, + job_exit_status.job_uuid, + job_exit_status.log_path, + ) + .await; + } } fn run_job(conf: &Config, job_id: String, job: Job) -> JobExitStatus { From 5ea4aa430d695919ab13466c75f8fb1b93681cae Mon Sep 17 00:00:00 2001 From: askiiart Date: Fri, 31 Jan 2025 21:29:08 -0600 Subject: [PATCH 4/5] update readme --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ea4976..daf7a92 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,36 @@ This is Gregory. Gregory controls repos. Gregory keeps track of updating repos, ## Documentation -Go look at [`docs/`](/docs/), and check out the [example config](/gregory.example.toml) +Install gregory with `cargo install`: + +```sh +cargo install --git https://github.com/askiiart/gregory +``` + +Gregory's config looks something like this: + +```toml +max-jobs = 4 +max-threads = 10 + +[packages] + + [packages.librewolf] + + dependencies = ["some-librewolf-dependency"] + version_check = ["check-version --whenever-you-feel-like-it-please"] + + [packages.librewolf.compilation] + revision = "2" + threads = 6 + image = "docker.io/library/debian" + commands = ["echo hi", "sleep 2.432", "echo helloooooooooo"] + volumes = ["librewolf"] +``` + +For more details, look at the `./docs/`, and check out the rest of the [example config](./gregory.example.toml). + +Once you've created your config, just run gregory with `gregory run` - that's it! ## TODO @@ -15,6 +44,6 @@ Go look at [`docs/`](/docs/), and check out the [example config](/gregory.exampl - The formatting for the config file (`gregory.toml`) was heavily inspired by Drone's config. - Why the name? - - I was thinking to go with something dark and foreboding, since this is a program to control *everything* about a repo - it's the high command. But I couldn't think of anything and thought just naming it some lame random name instead would be way funnier. Hence, Gregory. + - I was thinking to go with something dark and foreboding, since this is a program to control *everything* about many repos - it's the high command. But I couldn't think of anything and thought just naming it some lame random name instead would be way funnier. Hence, Gregory. - Gregory is a program, so it uses it/its pronouns. It also doesn't mind whether you capitalize its name or not, "gregory" or "Gregory" are fine, you can even shorten it if you want. - It's built for updating package repositories, but can be used to run pretty much anything. This isn't to say support won't be offered unless you're using it for a repo, but development will be focused on updating repos. From 522d12929b0a27488eff22ecf1be0013643625bd Mon Sep 17 00:00:00 2001 From: askiiart Date: Sat, 1 Feb 2025 13:19:40 -0600 Subject: [PATCH 5/5] add some feedback when running --- src/main.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 652752d..2fc0eeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,8 +77,18 @@ async fn run(config_path: String) { // runs the jobs (will need to be updated after sorting is added) for (job_id, job) in state.jobs { + println!("Running {job_id}"); let start_time = SystemTime::now(); let job_exit_status = run_job(&state.conf, job_id.clone(), job.clone()); + match job_exit_status.exit_code.clone() { + Some(e) => { + println!(" Job completed, exit code {e}"); + } + None => { + println!(" Job completed, !!! no exit code !!!"); + println!(" This means the process was terminated by a signal, like SIGKILL, which you should probably look into. See also: https://doc.rust-lang.org/std/process/struct.ExitStatus.html#method.code") + } + } sql::log_job( &mut pg_connection, @@ -88,15 +98,32 @@ async fn run(config_path: String) { job_id, job.revision, job_exit_status.job_uuid, - job_exit_status.log_path, + job_exit_status.log_path.clone(), ) .await; + + println!( + " Logged metadata to postgres database; log file at {}", + job_exit_status.log_path + ); + + println!() } // run repo updates for (job_id, job) in update_repo_jobs { + println!("Running {job_id}"); let start_time = SystemTime::now(); let job_exit_status = run_job(&state.conf, job_id.clone(), job.clone()); + match job_exit_status.exit_code.clone() { + Some(e) => { + println!(" Job completed, exit code {e}"); + } + None => { + println!(" Job completed, !!! no exit code !!!"); + println!(" This means the process was terminated by a signal, like SIGKILL, which you should probably look into. See also: https://doc.rust-lang.org/std/process/struct.ExitStatus.html#method.code") + } + } sql::log_job( &mut pg_connection, @@ -106,9 +133,16 @@ async fn run(config_path: String) { job_id, job.revision, job_exit_status.job_uuid, - job_exit_status.log_path, + job_exit_status.log_path.clone(), ) .await; + + println!( + " Logged metadata to postgres database; log file at {}", + job_exit_status.log_path + ); + + println!() } }