commit e09d5261c2356d8b4bb6fa889e89a8313e6738d1
parent 3b5b873bcddcbfe1286db150817d94c1bf12a29b
Author: Stefan Koch <programming@stefan-koch.name>
Date: Fri, 11 Oct 2019 22:27:40 +0200
allow to use custom paths for the CI configuration file
Diffstat:
3 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
@@ -26,6 +26,15 @@ git repository and optionally the name of the branch you want to build:
cinderella https://github.com/aufziehvogel/Cinderella.git --branch master
```
+You can use a different path than `.cinderella.toml` for your CI configuration
+file with the argument `-f` or `--file`. This argument is evaluated relatively
+to the git work directory. If you want to use a CI configuration file local
+to your shell directory use absolute paths.
+
+```bash
+cinderella https://github.com/aufziehvogel/Cinderella.git --file /home/user/cinderella-test.toml
+```
+
CI Configuration Format
-----------------------
diff --git a/src/lib.rs b/src/lib.rs
@@ -17,16 +17,30 @@ use crate::execution::ExecutionResult;
use crate::vcs::CodeSource;
use crate::vcs::WorkingCopy;
-pub struct RepoPointer {
+pub struct ExecutionConfig {
pub repo_url: String,
pub branch: Option<String>,
+ pub cinderella_filepath: Option<String>,
}
-impl RepoPointer {
+impl ExecutionConfig {
// TODO: This approach only works for URLs, not for local paths.
fn name(&self) -> String {
self.repo_url.split('/').last().unwrap().to_string()
}
+
+ fn cinderella_file(&self, folder: &PathBuf) -> PathBuf {
+ let filepath = match &self.cinderella_filepath {
+ Some(filepath) => PathBuf::from(filepath),
+ None => {
+ let mut cinderella_file = folder.clone();
+ cinderella_file.push(".cinderella.toml");
+ cinderella_file
+ },
+ };
+
+ filepath
+ }
}
fn random_dir(base_path: &str) -> PathBuf {
@@ -41,13 +55,6 @@ fn random_dir(base_path: &str) -> PathBuf {
tempdir
}
-fn cinderella_file(folder: &PathBuf) -> PathBuf {
- let mut cinderella_file = folder.clone();
- cinderella_file.push(".cinderella.toml");
-
- cinderella_file
-}
-
fn appconfig_file() -> PathBuf {
let mut application_path = env::current_exe().unwrap();
application_path.pop();
@@ -56,11 +63,11 @@ fn appconfig_file() -> PathBuf {
application_path
}
-pub fn run(repo_ptr: &RepoPointer) {
+pub fn run(exec_config: &ExecutionConfig) {
let config = config::read_config(appconfig_file());
let repo = vcs::GitSource {
- src: repo_ptr.repo_url.clone(),
+ src: exec_config.repo_url.clone(),
};
// generate a temp unique work dir
@@ -73,7 +80,7 @@ pub fn run(repo_ptr: &RepoPointer) {
let mut variables = HashMap::new();
// checkout the branch if a branch was provided
- if let Some(branch) = &repo_ptr.branch {
+ if let Some(branch) = &exec_config.branch {
println!("Switching to branch {}", branch);
workdir.checkout_branch(&branch);
@@ -84,7 +91,7 @@ pub fn run(repo_ptr: &RepoPointer) {
// are executed there
assert!(env::set_current_dir(&workdir.path).is_ok());
- let cinderella_file = cinderella_file(&workdir.path);
+ let cinderella_file = exec_config.cinderella_file(&workdir.path);
if let Some(pipelines) = pipeline::load_pipeline(&cinderella_file) {
// TODO: Check if execution was successful. If not and if email is
// configured, send a mail
@@ -98,13 +105,13 @@ pub fn run(repo_ptr: &RepoPointer) {
};
let mailer = mail::build_mailer(&config.email);
mailer.send_mail(
- &repo_ptr.name(),
+ &exec_config.name(),
&format!("Build failed: {}\n{}\n\n{}", msg, code_msg, output));
},
ExecutionResult::ExecutionError(msg, output) => {
let mailer = mail::build_mailer(&config.email);
mailer.send_mail(
- &repo_ptr.name(),
+ &exec_config.name(),
&format!("Build failed: {}\n\n{}", msg, output));
},
_ => (),
diff --git a/src/main.rs b/src/main.rs
@@ -1,7 +1,7 @@
use std::env;
use getopts::Options;
-use cinderella::RepoPointer;
+use cinderella::ExecutionConfig;
fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} REPO_URL [options]", program);
@@ -14,6 +14,7 @@ fn main() {
let mut opts = Options::new();
opts.optopt("b", "branch", "set the branch to checkout", "BRANCH");
+ opts.optopt("f", "file", "set a file to the cinderella CI configuration", "FILEPATH");
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m },
@@ -27,9 +28,10 @@ fn main() {
return;
};
- let repo = RepoPointer {
+ let repo = ExecutionConfig {
repo_url: repository_url,
branch: matches.opt_str("b"),
+ cinderella_filepath: matches.opt_str("f"),
};
cinderella::run(&repo)