mirror of
https://git.alemi.dev/tci.git
synced 2024-11-23 16:44:48 +01:00
feat: scripts in dir run in order
This commit is contained in:
parent
2f19906f0c
commit
97dc8a0aee
1 changed files with 26 additions and 18 deletions
32
src/main.rs
32
src/main.rs
|
@ -118,33 +118,41 @@ fn tci_hook(repo_path: &std::path::PathBuf, tci_script: &str) -> Result<(), TciE
|
|||
|
||||
let tci_path = tmp.path().join(tci_script);
|
||||
|
||||
// if .tci is one script file, just run it
|
||||
if tci_path.is_file() {
|
||||
|
||||
println!("[=] running tci script for repo '{name}'");
|
||||
std::env::set_current_dir(tmp.path())?;
|
||||
let res = shell_out(tmp.path().join(tci_script));
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
res
|
||||
|
||||
// if .tci is a directory of scripts, run all of them sequentially
|
||||
} else if tci_path.is_dir() {
|
||||
|
||||
let mut scripts : Vec<String> = std::fs::read_dir(&tci_path)?
|
||||
.filter_map(|x| Some(x.ok()?.file_name().to_string_lossy().to_string()))
|
||||
.collect();
|
||||
scripts.sort(); // so that we get reliable execution order
|
||||
|
||||
std::env::set_current_dir(tmp.path())?;
|
||||
for script in std::fs::read_dir(&tci_path)? {
|
||||
match script {
|
||||
Err(e) => eprintln!("[?] error while listing .tci dir: {e}"),
|
||||
Ok(s) => {
|
||||
println!("[=] running tci script '{:?}' for repo '{name}'", s.file_name());
|
||||
let p = tci_path.clone();
|
||||
let res = shell_out(p.join(s.path()));
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
for script in scripts {
|
||||
println!("[=] running tci script '{script}' for repo '{name}'");
|
||||
let res = shell_out(tci_path.clone().join(&script));
|
||||
if let Err(e) = res {
|
||||
eprintln!("[!] error executing script '{:?}': {e}", s.file_name());
|
||||
eprintln!("[!] error executing script '{script}': {e}");
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
// return error in any other case
|
||||
} else {
|
||||
|
||||
return Err(TciError::MissingScript);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue