Compare commits
5 commits
00703db338
...
522d12929b
Author | SHA1 | Date | |
---|---|---|---|
|
522d12929b | ||
|
5ea4aa430d | ||
|
362a57715b | ||
|
e6dcedd79d | ||
|
9ce1d87174 |
2 changed files with 95 additions and 12 deletions
33
README.md
33
README.md
|
@ -4,7 +4,36 @@ This is Gregory. Gregory controls repos. Gregory keeps track of updating repos,
|
||||||
|
|
||||||
## Documentation
|
## 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
|
## 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.
|
- The formatting for the config file (`gregory.toml`) was heavily inspired by Drone's config.
|
||||||
- Why the name?
|
- 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.
|
- 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.
|
- 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.
|
||||||
|
|
74
src/main.rs
74
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)
|
// runs the jobs (will need to be updated after sorting is added)
|
||||||
for (job_id, job) in state.jobs {
|
for (job_id, job) in state.jobs {
|
||||||
|
println!("Running {job_id}");
|
||||||
let start_time = SystemTime::now();
|
let start_time = SystemTime::now();
|
||||||
let job_exit_status = run_job(&state.conf, job_id.clone(), job.clone());
|
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(
|
sql::log_job(
|
||||||
&mut pg_connection,
|
&mut pg_connection,
|
||||||
|
@ -88,9 +98,51 @@ async fn run(config_path: String) {
|
||||||
job_id,
|
job_id,
|
||||||
job.revision,
|
job.revision,
|
||||||
job_exit_status.job_uuid,
|
job_exit_status.job_uuid,
|
||||||
job_exit_status.log_path,
|
job_exit_status.log_path.clone(),
|
||||||
)
|
)
|
||||||
.await;
|
.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"))
|
/// 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
|
let data = job_id
|
||||||
.split(".")
|
.split(".")
|
||||||
.map(|item| item.to_string())
|
.map(|item| item.to_string())
|
||||||
|
@ -306,25 +358,30 @@ impl State {
|
||||||
///
|
///
|
||||||
/// ```json
|
/// ```json
|
||||||
/// {
|
/// {
|
||||||
/// "packages.some-librewolf-dependency.packaging.fedora": [
|
|
||||||
/// "packages.librewolf.compilation",
|
|
||||||
/// "packages.librewolf.packaging.fedora",
|
|
||||||
/// ],
|
|
||||||
/// "packages.some-librewolf-dependency.compilation": [
|
/// "packages.some-librewolf-dependency.compilation": [
|
||||||
/// "packages.librewolf.compilation",
|
/// "packages.librewolf.compilation",
|
||||||
/// "packages.librewolf.packaging.fedora",
|
/// "packages.librewolf.packaging.fedora",
|
||||||
/// "packages.some-librewolf-dependency.packaging.fedora",
|
/// "packages.some-librewolf-dependency.packaging.fedora",
|
||||||
/// ],
|
/// ],
|
||||||
|
/// "packages.librewolf.packaging.fedora": [],
|
||||||
/// "packages.librewolf.compilation": [
|
/// "packages.librewolf.compilation": [
|
||||||
/// "packages.librewolf.packaging.fedora",
|
/// "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>> {
|
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
|
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() {
|
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
|
for dep_name in conf
|
||||||
.packages
|
.packages
|
||||||
|
@ -335,9 +392,6 @@ impl State {
|
||||||
{
|
{
|
||||||
let all_deps = recursive_deps_for_package(dep_name.clone(), conf.clone());
|
let all_deps = recursive_deps_for_package(dep_name.clone(), conf.clone());
|
||||||
for dep in all_deps {
|
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());
|
dep_map.get_mut(&dep).unwrap().push(job_id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue