From 6e4a3b5127a9dc21d87477227789a46b8f884d94 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 25 Jul 2025 11:30:48 +0000 Subject: [PATCH] fix: jobparser: do not crash on invalid workflow_{dispatch,call} (#193) An invalid workflow_{dispatch,call} key with a type that is not a map may attempt to use a nil map. It happens randomly as the order of the key maps is not guaranteed. Without this fix, the tests will fail 100% of the time with: `go test -count=500 -run=TestParseRawOn/on:___workflow_ -v ./pkg/jobparser/` Regression from https://code.forgejo.org/forgejo/act/pulls/45 Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/193 Reviewed-by: Michael Kriese Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/jobparser/model.go | 4 +++- act/jobparser/model_test.go | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/act/jobparser/model.go b/act/jobparser/model.go index 476853fd..d2482b74 100644 --- a/act/jobparser/model.go +++ b/act/jobparser/model.go @@ -263,11 +263,13 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) { if isInvalidOnType(k, act) { return nil, fmt.Errorf("unknown on type: %#v", v) } - acts = nil default: return nil, fmt.Errorf("unknown on type: %#v", branches) } } + if k == "workflow_dispatch" || k == "workflow_call" { + acts = nil + } res = append(res, &Event{ Name: k, acts: acts, diff --git a/act/jobparser/model_test.go b/act/jobparser/model_test.go index 7c73172b..96f999db 100644 --- a/act/jobparser/model_test.go +++ b/act/jobparser/model_test.go @@ -190,7 +190,14 @@ func TestParseRawOn(t *testing.T) { }, }, { - input: "on:\n workflow_dispatch:\n inputs:\n test:\n type: string", + input: ` +on: + workflow_dispatch: + inputs: + test: + type: string + silently: ignore +`, result: []*Event{ { Name: "workflow_dispatch", @@ -198,7 +205,17 @@ func TestParseRawOn(t *testing.T) { }, }, { - input: "on:\n workflow_call:\n inputs:\n test:\n type: string\n outputs:\n output:\n value: something", + input: ` +on: + workflow_call: + inputs: + test: + type: string + outputs: + output: + value: something + silently: ignore +`, result: []*Event{ { Name: "workflow_call",