Skip to content

Commit

Permalink
Fix ci_in when there is nothing to prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Jan 12, 2022
1 parent c48c965 commit c64cf1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion ci/release_notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Empty - please add release notes here
## Improvement

- reproduce last state when there is nothing to prepare in ci_in
17 changes: 12 additions & 5 deletions src/concourse/ci_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,20 @@ pub fn exec(destination: &str) -> Result<()> {
std::process::exit(1);
}
None => {
eprintln!("Nothing new to deploy... providing an empty dir");
return empty_repo(version);
eprintln!("Nothing new to deploy... reproducing last state");
let reproduced = ws.reproduce(env, true)?;
if &reproduced != wanted_trigger {
eprintln!("Reproduced state is out of sync - providing empty dir");
return empty_repo(version);
}
(reproduced, Vec::new())
}
Some(ret) => {
eprintln!("Preparing the workspace");
ws.prepare(env, gate, true)?;
ret
}
Some(ret) => ret,
};
eprintln!("Preparing the workspace");
ws.prepare(env, gate, true)?;

std::fs::write(".git/cepler_environment", &environment)
.context("Couldn't create file '.git/cepler_environment'")?;
Expand Down
5 changes: 3 additions & 2 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Workspace {
Ok(Some((new_env_state.head_commit.inner(), diffs)))
}

pub fn reproduce(&self, env: &EnvironmentConfig, force_clean: bool) -> Result<()> {
pub fn reproduce(&self, env: &EnvironmentConfig, force_clean: bool) -> Result<String> {
let repo = Repo::open(None)?;
if let Some(last_state) = self.db.get_current_state(&env.name) {
if force_clean {
Expand All @@ -81,11 +81,12 @@ impl Workspace {
for (ident, state) in last_state.files.iter() {
repo.checkout_file_from(&ident.name(), &state.from_commit)?;
}
Ok(())
Ok(last_state.head_commit.clone().inner())
} else {
Err(anyhow!("No state recorded for {}", env.name))
}
}

pub fn prepare(
&self,
env: &EnvironmentConfig,
Expand Down

0 comments on commit c64cf1e

Please sign in to comment.