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

main
Michal 2 years ago
parent 2549b48a1e
commit e3341de0a0

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

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

@ -36,7 +36,7 @@ fn main() {
env::set_current_dir("../").unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());
if config.smart_pull {
if config.base.smart_pull {
log!(verbose, "Smart pull");
Command::new("git")
.args(&["remote", "update"])
@ -80,13 +80,13 @@ fn main() {
Operation::Pull { packages, .. } => operations::pull(packages, exclude.to_vec(), verbose),
Operation::RepoGen => {
let config = read_cfg(verbose);
if config.mode != "repository" {
if config.base.mode != "repository" {
crash!(
AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode"
)
}
info!("Generating repository: {}", config.name);
info!("Generating repository: {}", config.mode.repository.name);
repository::generate(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);
let all = packages.is_empty();
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
let mut repos: Vec<Repo> = config.repo;
let mut repos: Vec<Repo> = config.repositories;
log!(verbose, "{} Repos: {:?}", repos.len(), repos);
if !exclude.is_empty() {
log!(verbose, "Exclude not empty: {:?}", exclude);
@ -42,7 +47,7 @@ pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbos
} else {
// Otherwise, build
log!(verbose, "Building {}", pkg);
let code = repository::build(pkg, config.sign, verbose);
let code = repository::build(pkg, sign, verbose);
log!(
verbose,
"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);
for pkg in repos {
log!(verbose, "Building {}", pkg.name);
let code = repository::build(&pkg.name, config.sign, verbose);
let code = repository::build(&pkg.name, sign, verbose);
log!(
verbose,
"Package {} finished with exit code: {:?}",

@ -6,7 +6,7 @@ pub fn clone(verbose: bool) {
// Read config struct from mlc.toml
let config = workspace::read_cfg(verbose);
log!(verbose, "Config: {:?}", config);
let repos = &config.repo;
let repos = &config.repositories;
log!(verbose, "Repos: {:?}", repos);
// 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
for r in repo_diff {
log!(verbose, "Cloning {}", r.name);
info!("Cloning ({} mode): {}", config.mode, r.name);
info!("Cloning ({} mode): {}", config.base.mode, r.name);
Command::new("git")
.args(&["clone", &r.url, &r.name])
.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 {
unimplemented!()
unimplemented!() // TODO: Implement build_on_update
}
} else {
// 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();
log!(verbose, "All: {}", all);
// Read smart_pull from config
let smart_pull = config.smart_pull;
let smart_pull = config.base.smart_pull;
log!(verbose, "Smart pull: {}", smart_pull);
// 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);
// Read repos from config
let repos = config
.repo
.repositories
.iter()
.map(|x| x.name.clone())
.collect::<Vec<String>>();

@ -10,7 +10,7 @@ pub fn generate(verbose: bool) {
log!(verbose, "Config: {:?}", config);
// Get repository name from config
let name = config.name;
let name = config.mode.repository.name;
log!(verbose, "Name: {}", name);
// If repository exists, delete it
@ -32,6 +32,34 @@ pub fn generate(verbose: bool) {
.unwrap();
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
env::set_current_dir(&name).unwrap();
log!(verbose, "Current dir: {:?}", env::current_dir().unwrap());

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

Loading…
Cancel
Save