Skip to content

Commit

Permalink
Merge pull request #28 from jamf/enable-multiple-upgrade-scripts-betw…
Browse files Browse the repository at this point in the history
…een-versions

Enable multiple upgrade scripts between versions
  • Loading branch information
thecodesmith authored Jun 2, 2021
2 parents 51f9e36 + 87fddb8 commit 5f2d4ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rendr"
version = "1.0.0"
version = "1.1.0"
authors = ["Brian Stewart <brian.stewart@jamf.com>", "Tomasz Kurcz <tomasz.kurcz@jamf.com>"]
description = "A project scaffolding tool"
categories = ["command-line-utilities", "development-tools"]
Expand Down
20 changes: 10 additions & 10 deletions src/blueprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl Blueprint {
values: &Values,
output_dir: &Path,
source: &str,
source_version: &u32,
dry_run: bool,
) -> Result<(), DynError> {
info!("Upgrading to blueprint version {}", &self.metadata.version);
Expand Down Expand Up @@ -256,7 +257,8 @@ impl Blueprint {

self.generate_rendr_file(&source, &output_dir, &values, dry_run)?;

let scripts = self.get_upgrade_scripts();
let target_version = self.metadata.version;
let scripts = self.get_upgrade_scripts(&source_version, &target_version);
self.run_upgrade_scripts(scripts, output_dir, values, dry_run)?;

Ok(())
Expand Down Expand Up @@ -307,11 +309,11 @@ impl Blueprint {
Ok(())
}

pub fn get_upgrade_scripts(&self) -> Vec<&UpgradeSpec> {
pub fn get_upgrade_scripts(&self, source_version: &u32, target_version: &u32) -> Vec<&UpgradeSpec> {
self.metadata
.upgrades
.iter()
.filter(|it| it.version == self.metadata.version)
.filter(|it| it.version > *source_version && it.version <= *target_version)
.collect()
}

Expand All @@ -330,13 +332,11 @@ impl Blueprint {
);

for script in scripts {
if script.version == target_version {
if let Some(mut s) = self.find_script(&script.script).unwrap() {
s.executable = Some(String::from(&script.executable));
println!("Running upgrade script: {}", s.name);
if !dry_run {
s.run(output_dir, values)?;
}
if let Some(mut s) = self.find_script(&script.script).unwrap() {
s.executable = Some(String::from(&script.executable));
println!("Running upgrade script: {}", s.name);
if !dry_run {
s.run(output_dir, values)?;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<'p> Project<'p> {
values.extend(prompt_values);

// Update the target version, inserting if it does not exist for some reason
let source_version = config.version;
let target_version = blueprint.metadata.version.to_string();
let v = values.entry("version").or_insert(target_version.as_str());
*v = target_version.as_str();
Expand All @@ -231,6 +232,7 @@ impl<'p> Project<'p> {
&values.into(),
&self.path,
&config.source,
&source_version,
dry_run,
)
.map_err(|e| UpgradeError::RenderError(anyhow!("error rendering upgrade: {}", e)))?;
Expand Down

0 comments on commit 5f2d4ce

Please sign in to comment.