cinderella

[unmaintained] simple CI engine
Log | Files | Refs | README | LICENSE

commit 9d089f650a6d3ba4189e48d6b19bd7b3964ad10f
parent 1ce34ce0350aa1a3ecb9a9b408b532884cb9a773
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Sat, 14 Dec 2019 15:41:49 +0100

allow to build tags

Diffstat:
M.cinderella.toml | 10+++++++++-
MREADME.md | 11++++++++++-
Msrc/config.rs | 2++
Msrc/lib.rs | 3+++
Msrc/main.rs | 2++
Msrc/variables.rs | 5+++++
Msrc/vcs.rs | 6++++++
7 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/.cinderella.toml b/.cinderella.toml @@ -3,7 +3,8 @@ commands = [ "cargo test", ] -[build-release] +[build-master] +# Always build the latest master for usage on my server commands = [ "cargo build --release", "cp target/release/cinderella /opt/cinderella/.cinderella", @@ -12,3 +13,10 @@ commands = [ "mv /opt/cinderella/.cinderella /opt/cinderella/cinderella", ] when = "\"%BRANCH\" == \"master\"" + +[build-release] +commands = [ + "cargo build --release", + "cp target/release/cinderella \"/opt/cinderella/cinderella-%TAG\"", +] +when = "\"%REFTYPE\" == \"tag\"" diff --git a/README.md b/README.md @@ -26,6 +26,12 @@ git repository and optionally the name of the branch you want to build: cinderella run https://github.com/aufziehvogel/Cinderella.git --branch master ``` +You can also build a specific tag with: + +```bash +cinderella run https://github.com/aufziehvogel/Cinderella.git --tag 0.1.0 +``` + 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 @@ -73,7 +79,10 @@ with a percentage symbol (`%`) and will be replaced before the commands are being sent to the shell. Currently supported variables are: -- `%BRANCH`: The name of the branch that is built +- `%REFTYPE`: The type of reference that is built, `branch` or `tag` +- `%BRANCH`: The name of the branch that is built, if it is a branch +- `%TAG`: The name of the tag that is built, if it is a tag + ### Conditions diff --git a/src/config.rs b/src/config.rs @@ -46,6 +46,7 @@ impl CinderellaConfig { pub struct ExecutionConfig { pub repo_url: String, pub branch: Option<String>, + pub tag: Option<String>, pub cinderella_filepath: Option<String>, } @@ -125,6 +126,7 @@ mod tests { let exec_config = ExecutionConfig { repo_url: String::from("https://example.com/my-repo.git"), branch: Some(String::from("master")), + tag: None, cinderella_filepath: None, }; diff --git a/src/lib.rs b/src/lib.rs @@ -62,6 +62,9 @@ pub fn run(exec_config: &ExecutionConfig) { if let Some(branch) = &exec_config.branch { println!("Switching to branch {}", branch); workdir.checkout_branch(&branch); + } else if let Some(tag) = &exec_config.tag { + println!("Switching to tag {}", tag); + workdir.checkout_tag(&tag); } // Switch to the exported work dir so that all commands diff --git a/src/main.rs b/src/main.rs @@ -61,6 +61,7 @@ fn run(args: Vec<String>) { let mut opts = Options::new(); opts.optopt("b", "branch", "set the branch to checkout", "BRANCH"); + opts.optopt("t", "tag", "set the tag to checkout", "TAG"); opts.optopt("f", "file", "set a file to the cinderella CI configuration", "FILEPATH"); let matches = match opts.parse(&args[2..]) { @@ -78,6 +79,7 @@ fn run(args: Vec<String>) { let repo = ExecutionConfig { repo_url: repository_url, branch: matches.opt_str("b"), + tag: matches.opt_str("t"), cinderella_filepath: matches.opt_str("f"), }; diff --git a/src/variables.rs b/src/variables.rs @@ -19,8 +19,13 @@ fn load_internal(configs: &Configs) -> HashMap<String, String> { let mut variables = HashMap::new(); if let Some(branch) = &configs.execution_config.branch { + variables.insert("reftype".to_string(), "branch".to_string()); variables.insert("branch".to_string(), branch.to_string()); } + if let Some(tag) = &configs.execution_config.tag { + variables.insert("reftype".to_string(), "tag".to_string()); + variables.insert("tag".to_string(), tag.to_string()); + } variables } diff --git a/src/vcs.rs b/src/vcs.rs @@ -11,6 +11,7 @@ pub trait CodeSource { pub trait WorkingCopy { fn checkout_branch(&self, branch: &str); + fn checkout_tag(&self, tag: &str); } pub struct GitSource { @@ -41,6 +42,11 @@ impl WorkingCopy for GitWorkingCopy { let revname = format!("refs/remotes/origin/{}", branch_name); self.checkout_rev(&revname); } + + fn checkout_tag(&self, tag_name: &str) { + let revname = format!("refs/tags/{}", tag_name); + self.checkout_rev(&revname); + } } impl GitWorkingCopy {