feat(wfe-yaml): auto-convert ##wfe[output] values to typed JSON (bool, number)
This commit is contained in:
@@ -92,8 +92,21 @@ impl StepBody for ShellStep {
|
|||||||
&& let Some(eq_pos) = rest.find('=')
|
&& let Some(eq_pos) = rest.find('=')
|
||||||
{
|
{
|
||||||
let name = rest[..eq_pos].trim().to_string();
|
let name = rest[..eq_pos].trim().to_string();
|
||||||
let value = rest[eq_pos + 1..].to_string();
|
let raw_value = rest[eq_pos + 1..].to_string();
|
||||||
outputs.insert(name, serde_json::Value::String(value));
|
// Auto-convert typed values from string annotations
|
||||||
|
let value = match raw_value.as_str() {
|
||||||
|
"true" => serde_json::Value::Bool(true),
|
||||||
|
"false" => serde_json::Value::Bool(false),
|
||||||
|
"null" => serde_json::Value::Null,
|
||||||
|
s if s.parse::<i64>().is_ok() => {
|
||||||
|
serde_json::Value::Number(s.parse::<i64>().unwrap().into())
|
||||||
|
}
|
||||||
|
s if s.parse::<f64>().is_ok() => {
|
||||||
|
serde_json::json!(s.parse::<f64>().unwrap())
|
||||||
|
}
|
||||||
|
_ => serde_json::Value::String(raw_value),
|
||||||
|
};
|
||||||
|
outputs.insert(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ workflow:
|
|||||||
assert_eq!(greeting.as_str(), Some("hello"));
|
assert_eq!(greeting.as_str(), Some("hello"));
|
||||||
}
|
}
|
||||||
if let Some(count) = data.get("count") {
|
if let Some(count) = data.get("count") {
|
||||||
assert_eq!(count.as_str(), Some("42"));
|
assert_eq!(count.as_i64(), Some(42)); // auto-converted from string "42"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ workflow:
|
|||||||
assert_eq!(greeting.as_str(), Some("hello"));
|
assert_eq!(greeting.as_str(), Some("hello"));
|
||||||
}
|
}
|
||||||
if let Some(count) = data.get("count") {
|
if let Some(count) = data.get("count") {
|
||||||
assert_eq!(count.as_str(), Some("42"));
|
assert_eq!(count.as_i64(), Some(42)); // auto-converted from string "42"
|
||||||
}
|
}
|
||||||
if let Some(path) = data.get("path") {
|
if let Some(path) = data.get("path") {
|
||||||
assert_eq!(path.as_str(), Some("/usr/local/bin"));
|
assert_eq!(path.as_str(), Some("/usr/local/bin"));
|
||||||
|
|||||||
Reference in New Issue
Block a user