1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

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 <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-25 11:30:48 +00:00 committed by earl-warren
parent 53e26e56b1
commit 6e4a3b5127
2 changed files with 22 additions and 3 deletions

View file

@ -263,11 +263,13 @@ func ParseRawOn(rawOn *yaml.Node) ([]*Event, error) {
if isInvalidOnType(k, act) { if isInvalidOnType(k, act) {
return nil, fmt.Errorf("unknown on type: %#v", v) return nil, fmt.Errorf("unknown on type: %#v", v)
} }
acts = nil
default: default:
return nil, fmt.Errorf("unknown on type: %#v", branches) return nil, fmt.Errorf("unknown on type: %#v", branches)
} }
} }
if k == "workflow_dispatch" || k == "workflow_call" {
acts = nil
}
res = append(res, &Event{ res = append(res, &Event{
Name: k, Name: k,
acts: acts, acts: acts,

View file

@ -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{ result: []*Event{
{ {
Name: "workflow_dispatch", 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{ result: []*Event{
{ {
Name: "workflow_call", Name: "workflow_call",