Skip to content

Commit

Permalink
fix: propagate workflow outcomes (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante authored Aug 3, 2024
1 parent d5f10ca commit f79bc30
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
24 changes: 7 additions & 17 deletions crates/cli/src/result_formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,13 @@ pub fn print_file_header(
fn get_pretty_workflow_message(
outcome: &marzano_messenger::workflows::PackagedWorkflowOutcome,
) -> String {
match outcome.success {
true => {
format!(
"✅ {}",
outcome
.message
.as_deref()
.unwrap_or("Workflow completed successfully")
)
}
false => {
format!(
"❌ {}",
outcome.message.as_deref().unwrap_or("Workflow failed")
)
}
}
let emoji = match outcome.get_outcome() {
marzano_messenger::workflows::OutcomeKind::Success => "✅",
marzano_messenger::workflows::OutcomeKind::Failure => "❌",
marzano_messenger::workflows::OutcomeKind::Skipped => "⚪️",
};
let message = outcome.message.as_deref().unwrap_or("Workflow finished");
format!("{} {}", emoji, message)
}

impl fmt::Display for FormattedResult {
Expand Down
6 changes: 4 additions & 2 deletions crates/cli/src/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ where
Ok((
emitter,
PackagedWorkflowOutcome {
message: Some("Workflow completed successfully".to_string()),
message: None,
outcome: None,
success: true,
data: None,
},
Expand All @@ -184,7 +185,8 @@ where
Ok((
emitter,
PackagedWorkflowOutcome {
message: Some("Workflow failed".to_string()),
message: None,
outcome: None,
success: false,
data: None,
},
Expand Down
25 changes: 25 additions & 0 deletions crates/marzano_messenger/src/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@ use serde::{Deserialize, Serialize};

use crate::emit::Messager;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum OutcomeKind {
#[serde(rename = "success")]
Success,
#[serde(rename = "failure")]
Failure,
#[serde(rename = "skipped")]
Skipped,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct PackagedWorkflowOutcome {
pub message: Option<String>,
pub outcome: Option<OutcomeKind>,
pub success: bool,
pub data: Option<serde_json::Value>,
}

impl PackagedWorkflowOutcome {
pub fn get_outcome(&self) -> OutcomeKind {
if let Some(outcome) = self.outcome.as_ref() {
return outcome.clone();
}

if self.success {
OutcomeKind::Success
} else {
OutcomeKind::Failure
}
}
}

/// Handle workflow-related messages
pub trait WorkflowMessenger: Messager {
fn save_metadata(&mut self, message: &SimpleWorkflowMessage) -> anyhow::Result<()>;
Expand Down

0 comments on commit f79bc30

Please sign in to comment.