From 5d5f78d9cbc97d656e404a6070b6cd896b4215a4 Mon Sep 17 00:00:00 2001 From: Takehiro Iyatomi Date: Fri, 26 Aug 2022 10:27:25 +0900 Subject: [PATCH] github action: fix event payload type of repository dispatch, because toml value cannot and won't accept null value. see https://github.com/toml-lang/toml/issues/30#issuecomment-14003959 --- .vscode/launch.json | 4 ++-- core/src/ci/ghaction.rs | 17 ++++++----------- core/src/config/value.rs | 8 +++++++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9d5f751..a3c4ef3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -39,12 +39,12 @@ ] }, { - "name": "Start", + "name": "Boot", "type": "lldb", "request": "launch", "program": "${workspaceFolder}/target/debug/cli", "args": [ - "-v=3", "start", "-r=nightly", "-w=integrate" + "-v=3", "boot", "-p=payload.json" ] }, { diff --git a/core/src/ci/ghaction.rs b/core/src/ci/ghaction.rs index 401d303..fbfe98f 100644 --- a/core/src/ci/ghaction.rs +++ b/core/src/ci/ghaction.rs @@ -10,6 +10,7 @@ use chrono::{Utc, Duration}; use log; use maplit::hashmap; use serde::{Deserialize, Serialize}; +use serde_json::{Value as JsonValue}; use crate::config; use crate::ci; @@ -34,7 +35,7 @@ enum EventPayload { // to avoid wrongly being matched as 'Repository' variant. RepositoryDispatch { action: String, - client_payload: config::AnyValue + client_payload: JsonValue }, Repository { action: Option @@ -601,22 +602,16 @@ impl ci::CI for GhAction { _ => {} }, // repository_dispatch has a few possibility. - // config::DEPLO_REMOTE_JOB_EVENT_TYPE => should contain workflow_name in client_payload + // config::DEPLO_REMOTE_JOB_EVENT_TYPE => should contain workflow name in client_payload["name"] // config::DEPLO_MODULE_EVENT_TYPE => Module workflow invocation // others => Repository workflow invocation "repository_dispatch" => if let EventPayload::RepositoryDispatch{ action, client_payload } = &workflow_event.event { if action == config::DEPLO_REMOTE_JOB_EVENT_TYPE { - match client_payload.index("workflow_name") { - Some(n) => match n.as_str() { - Some(s) => matched_names.push(s.to_string()), - None => panic!( - "{}: event payload invalid {}", - config::DEPLO_REMOTE_JOB_EVENT_TYPE, client_payload - ) - }, - None => panic!( + match &client_payload["name"] { + JsonValue::String(s) => matched_names.push(s.to_string()), + _ => panic!( "{}: event payload invalid {}", config::DEPLO_REMOTE_JOB_EVENT_TYPE, client_payload ) diff --git a/core/src/config/value.rs b/core/src/config/value.rs index 7960c8e..0468974 100644 --- a/core/src/config/value.rs +++ b/core/src/config/value.rs @@ -169,7 +169,13 @@ pub struct Any { impl<'de> Deserialize<'de> for Any { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de> { - let any = AnyValue::deserialize(deserializer)?; + let any = match AnyValue::deserialize(deserializer) { + Ok(v) => v, + Err(e) => { + log::error!("deserialize error: {}", e); + return Err(e); + } + }; return match any { AnyValue::String(ref v) => { let (value, resolver) = detect_value_ref(v);