-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add workflow upload to cli (#493)
- Loading branch information
Showing
7 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use anyhow::{bail, Result}; | ||
use clap::Args; | ||
use serde::Serialize; | ||
use std::path::PathBuf; | ||
|
||
use crate::flags::GlobalFormatFlags; | ||
|
||
use crate::commands::apply_migration::{run_apply_migration, ApplyMigrationArgs}; | ||
use crate::workflows::fetch_remote_workflow; | ||
use marzano_messenger::emit::VisibilityLevels; | ||
|
||
#[derive(Args, Debug, Serialize)] | ||
pub struct WorkflowsUploadArgs { | ||
#[clap(index = 1)] | ||
workflow_path: String, | ||
} | ||
|
||
pub async fn run_upload_workflows( | ||
_arg: &WorkflowsUploadArgs, | ||
parent: &GlobalFormatFlags, | ||
) -> Result<()> { | ||
if parent.json || parent.jsonl { | ||
bail!("JSON output not supported for workflows"); | ||
} | ||
|
||
let workflow_path = PathBuf::from(&_arg.workflow_path); | ||
let workflow_info = fetch_remote_workflow( | ||
"https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/upload_workflow.js", | ||
None, | ||
) | ||
.await?; | ||
|
||
let apply_migration_args = ApplyMigrationArgs { | ||
input: Some(format!(r#"{{"workflow": "{}"}}"#, workflow_path.display())), | ||
..Default::default() | ||
}; | ||
|
||
let execution_id = | ||
std::env::var("GRIT_EXECUTION_ID").unwrap_or_else(|_| uuid::Uuid::new_v4().to_string()); | ||
|
||
let result = run_apply_migration( | ||
workflow_info, | ||
vec![], | ||
None, | ||
apply_migration_args, | ||
parent, | ||
VisibilityLevels::default(), | ||
execution_id, | ||
) | ||
.await?; | ||
|
||
if let Some(data) = result.data.and_then(|v| v.get("id").cloned()) { | ||
if let Some(data_str) = data.as_str() { | ||
println!("Uploaded Workflow ID: {}", data_str); | ||
return Ok(()); | ||
} | ||
} | ||
|
||
bail!("Failed to upload workflow: URL not returned") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters