From 4c4161638cff5210d6cb1e8afd717a87b2859b49 Mon Sep 17 00:00:00 2001 From: Gostuski Date: Wed, 31 May 2023 15:39:13 +0200 Subject: [PATCH] Add check for execution_type fields while building and publishing actions --- commands/actions/publish.go | 21 +++++++++++++++++++-- model/actions/action.go | 8 ++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/commands/actions/publish.go b/commands/actions/publish.go index 6cc63cb..2c825e6 100644 --- a/commands/actions/publish.go +++ b/commands/actions/publish.go @@ -110,7 +110,7 @@ func buildFunc(cmd *cobra.Command, args []string) { ) os.Exit(1) } - mustParseAndValidateTriggers(actions) + mustParseAndValidateActions(actions) tsConfigExists := util.TsConfigExists(actions.Sources) tsFileExists, tsFile := anyFunctionTsFileExists(actions) @@ -175,8 +175,25 @@ func buildFunc(cmd *cobra.Command, args []string) { logrus.Info(commands.Colorizer.Green("\nBuild completed.")) } -func mustParseAndValidateTriggers(projectActions *actionsModel.ProjectActions) { +func mustParseAndValidateActions(projectActions *actionsModel.ProjectActions) { for name, spec := range projectActions.Specs { + if spec.ExecutionType != actionsModel.ParallelExecutionType && + spec.ExecutionType != actionsModel.SequentialExecutionType { + userError.LogErrorf( + "validation of action failed", + userError.NewUserError( + nil, + commands.Colorizer.Sprintf( + "Invalid execution type %s for action %s. Supported values: {%s, %s}", + commands.Colorizer.Bold(commands.Colorizer.Red(spec.ExecutionType)), + commands.Colorizer.Bold(commands.Colorizer.Blue(name)), + commands.Colorizer.Bold(commands.Colorizer.Green(actionsModel.SequentialExecutionType)), + commands.Colorizer.Bold(commands.Colorizer.Green(actionsModel.ParallelExecutionType)), + ), + ), + ) + os.Exit(1) + } err := spec.Parse() if err != nil { userError.LogErrorf( diff --git a/model/actions/action.go b/model/actions/action.go index 5896627..cc17be5 100644 --- a/model/actions/action.go +++ b/model/actions/action.go @@ -10,8 +10,8 @@ import ( ) const ( - sequentialExecutionType = "sequential" - parallelExecutionType = "parallel" + SequentialExecutionType = "sequential" + ParallelExecutionType = "parallel" ) type Action struct { @@ -115,9 +115,9 @@ func IsRuntimeSupported(runtime string) bool { func invocationTypeFromExecution(executionType string) string { switch executionType { - case sequentialExecutionType: + case SequentialExecutionType: return "SYNC" - case parallelExecutionType: + case ParallelExecutionType: return "ASYNC" default: return ""