diff --git a/Cargo.lock b/Cargo.lock index 90dcb94..768ff33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,348 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "alphanumeric-sort" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d67c60c5f10f11c6ee04de72b2dd98bb9d2548cbc314d22a609bfa8bd9e87e8f" +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_complete" +version = "4.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac2e663e3e3bed2d32d065a8404024dad306e699a04263ec59919529f803aee9" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "gregory" version = "0.1.0" dependencies = [ "alphanumeric-sort", + "clap", + "clap_complete", + "yaml-rust2", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "yaml-rust2" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" +dependencies = [ + "arraydeque", + "encoding_rs", + "hashlink", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 82fb25b..cbf43b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,6 @@ edition = "2021" [dependencies] alphanumeric-sort = "1.5.3" +clap = { version = "4.5.23", features = ["derive"] } +clap_complete = "4.5.40" +yaml-rust2 = "0.9.0" diff --git a/docs/config-reference.md b/docs/config-reference.md new file mode 100644 index 0000000..6745214 --- /dev/null +++ b/docs/config-reference.md @@ -0,0 +1,111 @@ +# Config Reference + +- Config location: `gregory.yml` +- Example: see [`gregory.example.yml`](/gregory.example.yml) + +Note: This primarily uses LibreWolf and Fedora as examples of packages and distros. Also note that rather than separating by what distro, you can instead use those field to define which repo. + +## Top-level config + +- `log-level`: Log level `0`-`3` (error, warning, info, or debug) +- `max-threads`: The maximum number of threads to be used + - **See also**: [`threads`](#job-config) +- `max-jobs`: The maximum number of jobs to be run at once + +**Multithreading notes (IMPORTANT)**: Gregory will first run compilation jobs, then packaging jobs for whatever programs are done, then run the `update-repo` for whichever distros are finished. For this reason, the distro names listed under `packaging` and `update-repo` *must* match. + +## Job config + +- `threads`: The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number + - Set this as less than or equal to the max number of threads the thing you're running will use + - See `--cpus` in the [`podman run` docs](https://docs.podman.io/en/latest/markdown/podman-run.1.html#cpus) + - *Root may be required for this argument* + - If not specified, it will fall back to `max-threads` +- `image`: The Docker image to run the job in +- `commands`: The commands to run + - TODO: Add command file/bash script instead +- `volumes`: Names of volumes as defined in [`volumes` (top level)](#volumes) + +## Packages (`packages`) + +Example: + +```yml +packages: + librewolf: + compilation: + image: 'debian' + commands: + - './mach build' + + packaging: + fedora: + image: 'lesbi-oops-i-mean/debian' + commands: + - './lesbiab package thingy' +``` + +### Compilation (optional) + +Defines the compilation of a program, if applicable. Stuff like Python scripts can skip this. + +It's defined in this format: + +```yml +packages: + pkgname: + compilation: + image: 'fedora' + commands: + - 'echo hi' + + other-package: + compilation: + job-details-go-here: +``` + +### Packaging + +Defines the packaging of a program into stuff like `.deb` or `.rpm` files. + +Example: + +```yml +packages: + pkgname: + packaging: + distro-name: + image: 'fedora' + commands: + - 'echo hi' + + other-package: + packaging: + distro-name: + job-details-go-here: +``` + +Replace `distro-name` with the name of a distro, like `fedora` or `debian` + +## Update repo (`update-repo`) + +Defines how to update a repo. + +Example: + +```yml +update-repo: + distro-name: + image: 'fedora' + command: + - 'echo hi' +``` + +## Volumes + +Lists a volume in Docker's volume format, to be used in [job configs](#job-config) + +```yml +volumes: + librewolf: './local/path:/path/in/container' +``` diff --git a/gregory.example.yml b/gregory.example.yml index 2f6f728..084b1b1 100644 --- a/gregory.example.yml +++ b/gregory.example.yml @@ -1,16 +1,35 @@ +max-jobs: 4 max-threads: 10 -scripts-dir: "scripts" +log-level: 0 packages: librewolf: compilation: - - "cd ~/librewolf" - - "./mach blahblahblah" + threads: 8 + image: 'docker.io/library/debian' + commands: + - 'cd ~/librewolf' + - './mach build' + volumes: + - 'librewolf' packaging: fedora: - - "git clone http://example.com/librewolf-fedora-packaging.git && cd librewolf-fedora-packaging/" - - "do-rpm-stuff-idk" + threads: 8 + image: 'docker.io/library/fedora' + commands: + - 'git clone http://example.com/librewolf-fedora-packaging.git && cd librewolf-fedora-packaging/' + - 'do-rpm-stuff-idk' + volumes: + - 'librewolf' update-repo: fedora: - - "idkkkkk" + threads: 4 + image: 'docker.io/library/fedora' + commands: + - 'idkkkkk' + volumes: + - 'librewolf' + +volumes: + librewolf: './data/librewolf:/librewolf' diff --git a/src/README.md b/src/README.md index 04570c3..63f5b3c 100644 --- a/src/README.md +++ b/src/README.md @@ -1,9 +1,17 @@ # Gregory -This is Gregory. Gregory controls repos. He keeps track of building packages for repos, and can also have steps added to update those repos, or whatever you want him to do. +This is Gregory. Gregory controls repos. Gregory keeps track of updating repos, trying to be simple and elegant, but enough. -Okay that's enough of talking about Gregory as a person. +## TODO -## Why the name? +- Add sources (similar to `sources` in a PKGBUILD)? +- Add support for loading scripts rather than listing commands +- Add multithreading +- Add better/custom grouping for when to run jobs (dependency system?) -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. \ No newline at end of file +## Other stuff + +- The formatting for the config file (`gregory.yml`) 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. diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..bf62a68 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,23 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Debug)] +pub enum Commands { + ///Generate bash completions + GenerateBashCompletions, + ///Generate zsh completions + GenerateZshCompletions, + ///Generate fish completions + GenerateFishCompletions, + ///Runs it + Run { + #[arg(short, long)] + config: String, + }, +} diff --git a/src/main.rs b/src/main.rs index 9ae01a5..7e1a4f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,68 +1,48 @@ +use crate::cli::Commands; +use crate::cli::*; use alphanumeric_sort::sort_str_slice; +use clap::{CommandFactory, Parser}; +use clap_complete::aot::{generate, Bash, Fish, Zsh}; +use std::fs; +use std::io::stdout; +use yaml_rust2::YamlLoader; +mod cli; +mod tests; -fn main() {} +fn main() { + let cli = Cli::parse(); -#[test] -/// This isn't to test the program, more to test the crate works how I want, especially if I switch crates -fn test_semver_sorting() { - // copied from https://pkgs.org/download/xorg-x11-xauth - let mut versions = [ - "xorg-x11-xauth-1.1.3", - "xorg-x11-xauth-1.1.2", - "xorg-x11-xauth-1.0.9", - "xorg-x11-xauth-1.0.10", - "xorg-x11-xauth-1.1", - ]; - sort_str_slice(&mut versions); - assert_eq!( - versions, - [ - "xorg-x11-xauth-1.0.9", - "xorg-x11-xauth-1.0.10", - "xorg-x11-xauth-1.1", - "xorg-x11-xauth-1.1.2", - "xorg-x11-xauth-1.1.3" - ] - ); + match cli.command { + Commands::GenerateBashCompletions => { + generate( + Bash, + &mut Cli::command(), + "gregory", + &mut stdout(), + ); + } + Commands::GenerateZshCompletions => { + generate( + Zsh, + &mut Cli::command(), + "gregory", + &mut stdout(), + ); + } + Commands::GenerateFishCompletions => { + generate( + Fish, + &mut Cli::command(), + "gregory", + &mut stdout(), + ); + } + Commands::Run => {} + } } -#[test] -fn test_date_versioning() { - // copied from https://pkgs.org/download/vpnc-script - let mut versions = [ - "vpnc-script-20230907", - "vpnc-script-20230103", - "vpnc-script-20220404", - ]; - sort_str_slice(&mut versions); - assert_eq!( - versions, - [ - "vpnc-script-20220404", - "vpnc-script-20230103", - "vpnc-script-20230907" - ] - ); -} -#[test] -fn test_git_versioning() { - // copied from aurpublish versions - https://gitlab.archlinux.org/archlinux/packaging/packages/avahi/-/commits/main - let mut versions = [ - "1:0.8+r194+g3f79789-3", - "1:0.8+r194+g3f79789-2", - "0.7+4+gd8d8c67-1", - "0.8+r189+g35bb1ba-1", - "0.8+r127+g55d783d-1", - ]; - sort_str_slice(&mut versions); - assert_eq!( - versions, - [ - "0.7+4+gd8d8c67-1", - "0.8+r127+g55d783d-1", - "0.8+r189+g35bb1ba-1", - "1:0.8+r194+g3f79789-2", - "1:0.8+r194+g3f79789-3" - ] - ); +fn run(config_path: String) { + let tmp = fs::read_to_string(config_path.as_str()).unwrap(); + let config = YamlLoader::load_from_str(tmp.as_str()).unwrap()[0].clone(); + println!("{:?}", config) } diff --git a/src/tests.rs b/src/tests.rs new file mode 100644 index 0000000..b99ceb1 --- /dev/null +++ b/src/tests.rs @@ -0,0 +1,66 @@ +use alphanumeric_sort::sort_str_slice; + +#[test] +/// This isn't to test the program, more to test the crate works how I want, especially if I switch crates +fn test_semver_sorting() { + // copied from https://pkgs.org/download/xorg-x11-xauth + let mut versions = [ + "xorg-x11-xauth-1.1.3", + "xorg-x11-xauth-1.1.2", + "xorg-x11-xauth-1.0.9", + "xorg-x11-xauth-1.0.10", + "xorg-x11-xauth-1.1", + ]; + sort_str_slice(&mut versions); + assert_eq!( + versions, + [ + "xorg-x11-xauth-1.0.9", + "xorg-x11-xauth-1.0.10", + "xorg-x11-xauth-1.1", + "xorg-x11-xauth-1.1.2", + "xorg-x11-xauth-1.1.3" + ] + ); +} + +#[test] +fn test_date_versioning() { + // copied from https://pkgs.org/download/vpnc-script + let mut versions = [ + "vpnc-script-20230907", + "vpnc-script-20230103", + "vpnc-script-20220404", + ]; + sort_str_slice(&mut versions); + assert_eq!( + versions, + [ + "vpnc-script-20220404", + "vpnc-script-20230103", + "vpnc-script-20230907" + ] + ); +} +#[test] +fn test_git_versioning() { + // copied from aurpublish versions - https://gitlab.archlinux.org/archlinux/packaging/packages/avahi/-/commits/main + let mut versions = [ + "1:0.8+r194+g3f79789-3", + "1:0.8+r194+g3f79789-2", + "0.7+4+gd8d8c67-1", + "0.8+r189+g35bb1ba-1", + "0.8+r127+g55d783d-1", + ]; + sort_str_slice(&mut versions); + assert_eq!( + versions, + [ + "0.7+4+gd8d8c67-1", + "0.8+r127+g55d783d-1", + "0.8+r189+g35bb1ba-1", + "1:0.8+r194+g3f79789-2", + "1:0.8+r194+g3f79789-3" + ] + ); +}