update config, add config docs

This commit is contained in:
askiiart 2024-12-21 20:41:28 -06:00
parent 4ed06a7f53
commit f77783c66f
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30
8 changed files with 615 additions and 72 deletions

333
Cargo.lock generated
View file

@ -2,15 +2,348 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 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]] [[package]]
name = "alphanumeric-sort" name = "alphanumeric-sort"
version = "1.5.3" version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d67c60c5f10f11c6ee04de72b2dd98bb9d2548cbc314d22a609bfa8bd9e87e8f" 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]] [[package]]
name = "gregory" name = "gregory"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"alphanumeric-sort", "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",
] ]

View file

@ -5,3 +5,6 @@ edition = "2021"
[dependencies] [dependencies]
alphanumeric-sort = "1.5.3" alphanumeric-sort = "1.5.3"
clap = { version = "4.5.23", features = ["derive"] }
clap_complete = "4.5.40"
yaml-rust2 = "0.9.0"

111
docs/config-reference.md Normal file
View file

@ -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'
```

View file

@ -1,16 +1,35 @@
max-jobs: 4
max-threads: 10 max-threads: 10
scripts-dir: "scripts" log-level: 0
packages: packages:
librewolf: librewolf:
compilation: compilation:
- "cd ~/librewolf" threads: 8
- "./mach blahblahblah" image: 'docker.io/library/debian'
commands:
- 'cd ~/librewolf'
- './mach build'
volumes:
- 'librewolf'
packaging: packaging:
fedora: fedora:
- "git clone http://example.com/librewolf-fedora-packaging.git && cd librewolf-fedora-packaging/" threads: 8
- "do-rpm-stuff-idk" 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: update-repo:
fedora: fedora:
- "idkkkkk" threads: 4
image: 'docker.io/library/fedora'
commands:
- 'idkkkkk'
volumes:
- 'librewolf'
volumes:
librewolf: './data/librewolf:/librewolf'

View file

@ -1,9 +1,17 @@
# Gregory # 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.
<small>Okay that's enough of talking about Gregory as a person.</small> ## 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. ## 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.

23
src/cli.rs Normal file
View file

@ -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,
},
}

View file

@ -1,68 +1,48 @@
use crate::cli::Commands;
use crate::cli::*;
use alphanumeric_sort::sort_str_slice; 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] match cli.command {
/// This isn't to test the program, more to test the crate works how I want, especially if I switch crates Commands::GenerateBashCompletions => {
fn test_semver_sorting() { generate(
// copied from https://pkgs.org/download/xorg-x11-xauth Bash,
let mut versions = [ &mut Cli::command(),
"xorg-x11-xauth-1.1.3", "gregory",
"xorg-x11-xauth-1.1.2", &mut stdout(),
"xorg-x11-xauth-1.0.9", );
"xorg-x11-xauth-1.0.10", }
"xorg-x11-xauth-1.1", Commands::GenerateZshCompletions => {
]; generate(
sort_str_slice(&mut versions); Zsh,
assert_eq!( &mut Cli::command(),
versions, "gregory",
[ &mut stdout(),
"xorg-x11-xauth-1.0.9", );
"xorg-x11-xauth-1.0.10", }
"xorg-x11-xauth-1.1", Commands::GenerateFishCompletions => {
"xorg-x11-xauth-1.1.2", generate(
"xorg-x11-xauth-1.1.3" Fish,
] &mut Cli::command(),
); "gregory",
&mut stdout(),
);
}
Commands::Run => {}
}
} }
#[test] fn run(config_path: String) {
fn test_date_versioning() { let tmp = fs::read_to_string(config_path.as_str()).unwrap();
// copied from https://pkgs.org/download/vpnc-script let config = YamlLoader::load_from_str(tmp.as_str()).unwrap()[0].clone();
let mut versions = [ println!("{:?}", config)
"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"
]
);
} }

66
src/tests.rs Normal file
View file

@ -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"
]
);
}