Skip to content

Commit

Permalink
feat: auto-install workflow binary when required (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante authored Aug 18, 2024
1 parent 6349a02 commit 0fa2219
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crates/cli/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl Updater {

/// Retrieve auth info from the manifest, if available
pub fn get_auth(&self) -> Option<AuthInfo> {
let auth = get_env_auth(false);
let auth = get_env_auth(true);
if let Some(auth) = auth {
return Some(auth);
}
Expand Down Expand Up @@ -497,6 +497,7 @@ impl Updater {
Ok(bin_path.exists())
}

/// Get the path to the app's binary, installing it if necessary
pub async fn get_app_bin_and_install(&mut self, app: SupportedApp) -> Result<PathBuf> {
// If the path is overridden, skip checking install
if let Some(bin_path) = self.get_env_bin(&app)? {
Expand All @@ -506,11 +507,18 @@ impl Updater {
if bin_path.exists() {
return Ok(bin_path);
}
bail!(
"Please set the {} environment variable to the path of the {} binary",
app.get_env_name(),
app
);
let pg = ProgressBar::new_spinner();
pg.set_message(format!("Downloading {}...", app));
self.install_latest(app).await?;

pg.finish_and_clear();

// Get the path again, since it may have been moved
let bin_path = self.get_app_bin(&app)?;
if bin_path.exists() {
return Ok(bin_path);
}
bail!("Attempted to install {} but could not find it", app);
}

pub async fn sync_manifest_version(&mut self, app: SupportedApp) -> Result<Option<String>> {
Expand Down
2 changes: 2 additions & 0 deletions crates/cli_bin/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use marzano_gritmodule::config::GRIT_GLOBAL_DIR_ENV;
use tempfile::tempdir;

pub const BIN_NAME: &str = "marzano";

#[allow(dead_code)]
pub const INSTA_FILTERS: &[(&str, &str)] = &[(
r"\b[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}\b",
"[UUID]",
Expand Down
29 changes: 29 additions & 0 deletions crates/cli_bin/tests/workflows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::common::{get_fixture, get_test_cmd};
use anyhow::Result;

mod common;

#[test]
#[ignore = "No auth token is available in CI"]
fn run_test_workflow() -> Result<()> {
let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js")
.current_dir(temp_fixtures_root);

let output = cmd.output()?;
println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?);
println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?);

assert!(
output.status.success(),
"Command didn't finish successfully"
);

let stdout = String::from_utf8(output.stdout)?;
assert!(stdout.contains("Running hello workflow"),);

Ok(())
}

0 comments on commit 0fa2219

Please sign in to comment.