Fully reworked config struct + began work on signing on repo gen

main
Michal 2 years ago
parent 1ad8b76e51
commit 68c2751b3d
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -4,9 +4,13 @@ smart_pull = true
[mode.repository] [mode.repository]
name = "test" name = "test"
sign = false
build_on_update = true build_on_update = true
[mode.repository.signing]
enabled = true
key = ""
on_gen = true
[mode.workspace] [mode.workspace]
[repositories] [repositories]

@ -3,12 +3,9 @@ use serde_derive::Deserialize;
//// Config structs //// Config structs
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
pub mode: String, pub base: ConfigBase,
pub name: String, pub mode: ConfigMode,
pub sign: bool, pub repositories: Vec<Repo>,
pub smart_pull: bool,
pub build_on_update: bool,
pub repo: Vec<Repo>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -33,8 +30,15 @@ pub struct ConfigMode {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct ConfigModeRepository { pub struct ConfigModeRepository {
pub name: String, pub name: String,
pub sign: bool,
pub build_on_update: bool, pub build_on_update: bool,
pub signing: ConfigModeRepositorySigning,
}
#[derive(Debug, Deserialize)]
pub struct ConfigModeRepositorySigning {
pub enabled: bool,
pub key: String,
pub on_gen: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -46,6 +50,11 @@ pub struct ConfigRepositories {
pub urls: Vec<String>, pub urls: Vec<String>,
} }
#[derive(Debug, Deserialize)]
pub struct ConfigRepositoriesExpanded {
pub repos: Vec<Repo>,
}
//// Repository structs //// Repository structs
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Repo { pub struct Repo {

@ -36,7 +36,7 @@ fn main() {
env::set_current_dir("../").unwrap(); env::set_current_dir("../").unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
if config.smart_pull { if config.base.smart_pull {
log!(verbose, "Smart pull"); log!(verbose, "Smart pull");
Command::new("git") Command::new("git")
.args(&["remote", "update"]) .args(&["remote", "update"])
@ -80,13 +80,13 @@ fn main() {
Operation::Pull { packages, .. } => operations::pull(packages, exclude.to_vec(), verbose), Operation::Pull { packages, .. } => operations::pull(packages, exclude.to_vec(), verbose),
Operation::RepoGen => { Operation::RepoGen => {
let config = read_cfg(verbose); let config = read_cfg(verbose);
if config.mode != "repository" { if config.base.mode != "repository" {
crash!( crash!(
AppExitCode::BuildInWorkspace, AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode" "Cannot build packages in workspace mode"
) )
} }
info!("Generating repository: {}", config.name); info!("Generating repository: {}", config.mode.repository.name);
repository::generate(verbose); repository::generate(verbose);
} }
Operation::Config => operations::config(verbose), Operation::Config => operations::config(verbose),

@ -8,10 +8,15 @@ pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbos
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
let all = packages.is_empty(); let all = packages.is_empty();
log!(verbose, "All: {:?}", all); log!(verbose, "All: {:?}", all);
log!(verbose, "Signing: {:?}", config.sign); let sign = if config.mode.repository.signing.enabled && config.mode.repository.signing.on_gen {
false
} else {
config.mode.repository.signing.enabled
};
log!(verbose, "Signing: {:?}", config.mode.repository.signing);
// Get list of repos and subtract exclude // Get list of repos and subtract exclude
let mut repos: Vec<Repo> = config.repo; let mut repos: Vec<Repo> = config.repositories;
log!(verbose, "{} Repos: {:?}", repos.len(), repos); log!(verbose, "{} Repos: {:?}", repos.len(), repos);
if !exclude.is_empty() { if !exclude.is_empty() {
log!(verbose, "Exclude not empty: {:?}", exclude); log!(verbose, "Exclude not empty: {:?}", exclude);
@ -42,7 +47,7 @@ pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbos
} else { } else {
// Otherwise, build // Otherwise, build
log!(verbose, "Building {}", pkg); log!(verbose, "Building {}", pkg);
let code = repository::build(pkg, config.sign, verbose); let code = repository::build(pkg, sign, verbose);
log!( log!(
verbose, verbose,
"Package {} finished with exit code: {:?}", "Package {} finished with exit code: {:?}",
@ -70,7 +75,7 @@ pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbos
log!(verbose, "Sorted: {:?}", repos); log!(verbose, "Sorted: {:?}", repos);
for pkg in repos { for pkg in repos {
log!(verbose, "Building {}", pkg.name); log!(verbose, "Building {}", pkg.name);
let code = repository::build(&pkg.name, config.sign, verbose); let code = repository::build(&pkg.name, sign, verbose);
log!( log!(
verbose, verbose,
"Package {} finished with exit code: {:?}", "Package {} finished with exit code: {:?}",

@ -6,7 +6,7 @@ pub fn clone(verbose: bool) {
// Read config struct from mlc.toml // Read config struct from mlc.toml
let config = workspace::read_cfg(verbose); let config = workspace::read_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
let repos = &config.repo; let repos = &config.repositories;
log!(verbose, "Repos: {:?}", repos); log!(verbose, "Repos: {:?}", repos);
// Get a vector of all files/dirs in the current directory, excluding config file // Get a vector of all files/dirs in the current directory, excluding config file
@ -44,7 +44,7 @@ pub fn clone(verbose: bool) {
// Clone all diff repos // Clone all diff repos
for r in repo_diff { for r in repo_diff {
log!(verbose, "Cloning {}", r.name); log!(verbose, "Cloning {}", r.name);
info!("Cloning ({} mode): {}", config.mode, r.name); info!("Cloning ({} mode): {}", config.base.mode, r.name);
Command::new("git") Command::new("git")
.args(&["clone", &r.url, &r.name]) .args(&["clone", &r.url, &r.name])
.spawn() .spawn()

@ -46,7 +46,7 @@ fn do_the_pulling(repos: Vec<String>, verbose: bool, smart_pull: bool, build_on_
// If build_on_update is set, rebuild package // If build_on_update is set, rebuild package
if build_on_update { if build_on_update {
unimplemented!() unimplemented!() // TODO: Implement build_on_update
} }
} else { } else {
// If there are no changes, alert the user // If there are no changes, alert the user
@ -80,15 +80,15 @@ pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool) {
let all = packages.is_empty(); let all = packages.is_empty();
log!(verbose, "All: {}", all); log!(verbose, "All: {}", all);
// Read smart_pull from config // Read smart_pull from config
let smart_pull = config.smart_pull; let smart_pull = config.base.smart_pull;
log!(verbose, "Smart pull: {}", smart_pull); log!(verbose, "Smart pull: {}", smart_pull);
// Read build_on_update from config // Read build_on_update from config
let build_on_update = config.build_on_update; let build_on_update = config.mode.repository.build_on_update;
log!(verbose, "Build on update: {}", build_on_update); log!(verbose, "Build on update: {}", build_on_update);
// Read repos from config // Read repos from config
let repos = config let repos = config
.repo .repositories
.iter() .iter()
.map(|x| x.name.clone()) .map(|x| x.name.clone())
.collect::<Vec<String>>(); .collect::<Vec<String>>();

@ -10,7 +10,7 @@ pub fn generate(verbose: bool) {
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// Get repository name from config // Get repository name from config
let name = config.name; let name = config.mode.repository.name;
log!(verbose, "Name: {}", name); log!(verbose, "Name: {}", name);
// If repository exists, delete it // If repository exists, delete it
@ -32,6 +32,34 @@ pub fn generate(verbose: bool) {
.unwrap(); .unwrap();
log!(verbose, "Copied out packages to {}", name); log!(verbose, "Copied out packages to {}", name);
// Sign all package files in repository if signing and on_gen are true
if config.mode.repository.signing.enabled && config.mode.repository.signing.on_gen {
// Directory stuff
let dir = env::current_dir().unwrap();
log!(verbose, "Current dir: {:?}", dir);
env::set_current_dir(&name).unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
// Get a list of all .tar.* files in repository
let files = fs::read_dir("./").unwrap();
for file in files {
let file = file.unwrap();
let path = file.path();
if path.extension().unwrap() == "zst" || path.extension().unwrap() == "xz" {
log!(verbose, "Signing {}", path.display());
Command::new("bash")
.args(&["-c", &format!("gpg --default-key {} --detach-sign {}", config.mode.repository.signing.key, file.file_name().to_str().unwrap())])
.spawn()
.unwrap()
.wait()
.unwrap();
}
}
// Return to root dir
env::set_current_dir(dir).unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
log!(verbose, "Signed repository");
}
// Enter repository directory // Enter repository directory
env::set_current_dir(&name).unwrap(); env::set_current_dir(&name).unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap()); log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());

@ -67,12 +67,9 @@ pub fn read_cfg(verbose: bool) -> Config {
// Returns parsed config file // Returns parsed config file
let conf = Config { let conf = Config {
mode: config.base.mode, base: config.base,
smart_pull: config.base.smart_pull, mode: config.mode,
sign: config.mode.repository.sign, repositories: expanded_repos,
name: config.mode.repository.name,
build_on_update: config.mode.repository.build_on_update,
repo: expanded_repos,
}; };
log!(verbose, "Config: {:?}", conf); log!(verbose, "Config: {:?}", conf);
conf conf

Loading…
Cancel
Save