From 54fead51c695960029389c09a00a2b52c4be7d22 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Wed, 29 Jan 2025 08:38:30 +0000 Subject: [PATCH] fix(jobparser): support `workflow_call.inputs` and `workflow_call.outputs` (#70) - Closes #69 - #45 - https://codeberg.org/forgejo/forgejo/issues/6069 Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/70 Reviewed-by: earl-warren Co-authored-by: Michael Kriese Co-committed-by: Michael Kriese --- act/jobparser/model.go | 12 +++++++++++- act/jobparser/model_test.go | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/act/jobparser/model.go b/act/jobparser/model.go index f63a0455..476853fd 100644 --- a/act/jobparser/model.go +++ b/act/jobparser/model.go @@ -260,7 +260,7 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) { } } case map[string]interface{}: - if k != "workflow_dispatch" || act != "inputs" { + if isInvalidOnType(k, act) { return nil, fmt.Errorf("unknown on type: %#v", v) } acts = nil @@ -304,6 +304,16 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) { } } +func isInvalidOnType(onType, subKey string) bool { + if onType == "workflow_dispatch" && subKey == "inputs" { + return false + } + if onType == "workflow_call" && (subKey == "inputs" || subKey == "outputs") { + return false + } + return true +} + // parseMappingNode parse a mapping node and preserve order. func parseMappingNode[T any](node *yaml.Node) ([]string, []T, error) { if node.Kind != yaml.MappingNode { diff --git a/act/jobparser/model_test.go b/act/jobparser/model_test.go index a034306f..45f8e9b2 100644 --- a/act/jobparser/model_test.go +++ b/act/jobparser/model_test.go @@ -163,7 +163,7 @@ func TestParseRawOn(t *testing.T) { }, }, { - input: "on: [pull_request, workflow_dispatch]", + input: "on: [pull_request, workflow_dispatch, workflow_call]", result: []*Event{ { Name: "pull_request", @@ -171,6 +171,9 @@ func TestParseRawOn(t *testing.T) { { Name: "workflow_dispatch", }, + { + Name: "workflow_call", + }, }, }, { @@ -194,6 +197,14 @@ func TestParseRawOn(t *testing.T) { }, }, }, + { + input: "on:\n workflow_call:\n inputs:\n test:\n type: string\n outputs:\n output:\n value: something", + result: []*Event{ + { + Name: "workflow_call", + }, + }, + }, } for _, kase := range kases { t.Run(kase.input, func(t *testing.T) {