Compare commits

..

5 commits

Author SHA1 Message Date
askiiart
522d12929b
add some feedback when running 2025-02-01 13:19:40 -06:00
askiiart
5ea4aa430d
update readme 2025-01-31 21:29:08 -06:00
askiiart
362a57715b
add repo updating stuff 2025-01-31 21:24:52 -06:00
askiiart
e6dcedd79d
fix typo 2025-01-31 20:57:20 -06:00
askiiart
9ce1d87174
change behavior of dependency_map() 2025-01-31 19:36:39 -06:00
2 changed files with 95 additions and 12 deletions

View file

@ -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.

View file

@ -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,9 +98,51 @@ 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,
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.clone(),
)
.await;
println!(
" Logged metadata to postgres database; log file at {}",
job_exit_status.log_path
);
println!()
}
}
@ -191,7 +243,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())
@ -306,25 +358,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<String, Job>, conf: Config) -> HashMap<String, Vec<String>> {
let mut dep_map: HashMap<String, Vec<String>> = 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 +392,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());
}
}