mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-09 20:41:46 +02:00
Backport #37570 by @Exgene ## The issue Closes #37568. Basically due to empty fields being present in the actions file, the jobs would be produced as `nil` inside `jobparser.go` . Because of this when we call `Parse` on the `jobparser` module. ```go Needs: job.Needs(), ``` would propagate the `nil` job down the chain. ## The fix For now i decide to fix it by guarding with an `if job == nil` check. Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Kausthubh J Rao <105716675+Exgene@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
58a66cae3c
commit
b586d80f97
@ -31,6 +31,9 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
|
|||||||
}
|
}
|
||||||
results := map[string]*JobResult{}
|
results := map[string]*JobResult{}
|
||||||
for id, job := range origin.Jobs {
|
for id, job := range origin.Jobs {
|
||||||
|
if job == nil {
|
||||||
|
return nil, fmt.Errorf("needed job not found: %q", id)
|
||||||
|
}
|
||||||
results[id] = &JobResult{
|
results[id] = &JobResult{
|
||||||
Needs: job.Needs(),
|
Needs: job.Needs(),
|
||||||
Result: pc.jobResults[id],
|
Result: pc.jobResults[id],
|
||||||
|
|||||||
@ -59,6 +59,13 @@ func TestParse(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
invalidFileTests := []struct {
|
||||||
|
name string
|
||||||
|
}{
|
||||||
|
{name: "null_job_implicit"},
|
||||||
|
{name: "null_job_explicit"},
|
||||||
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
content := ReadTestdata(t, tt.name+".in.yaml")
|
content := ReadTestdata(t, tt.name+".in.yaml")
|
||||||
@ -84,4 +91,14 @@ func TestParse(t *testing.T) {
|
|||||||
assert.Equal(t, string(want), builder.String())
|
assert.Equal(t, string(want), builder.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tt := range invalidFileTests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
content := ReadTestdata(t, tt.name+".in.yaml")
|
||||||
|
require.NotPanics(t, func() {
|
||||||
|
_, err := Parse(content)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
modules/actions/jobparser/testdata/null_job_explicit.in.yaml
vendored
Normal file
9
modules/actions/jobparser/testdata/null_job_explicit.in.yaml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# null_job_explicit.in.yaml
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
empty: null
|
||||||
|
notempty:
|
||||||
|
needs: empty
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo ok
|
||||||
9
modules/actions/jobparser/testdata/null_job_implicit.in.yaml
vendored
Normal file
9
modules/actions/jobparser/testdata/null_job_implicit.in.yaml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# null_job_implicit.in.yaml
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
empty:
|
||||||
|
notempty:
|
||||||
|
needs: empty
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo ok
|
||||||
Loading…
x
Reference in New Issue
Block a user