From 91fd412c51667dd10c434e9eb16ba10685581fa6 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Thu, 12 May 2022 21:23:34 +0200 Subject: [PATCH] fix: panic if a step in a job is nil (#1145) * fix: panic if a step is a job is nil * simplify * [no ci] Add testdata * [no ci] Add Test --- pkg/runner/job_executor.go | 5 +++++ pkg/runner/job_executor_test.go | 1 + pkg/runner/testdata/job-nil-step/push.yml | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 pkg/runner/testdata/job-nil-step/push.yml diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index 7c9da4d9..e128aaa7 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -39,6 +39,11 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo preSteps = append(preSteps, info.startContainer()) for i, stepModel := range infoSteps { + if stepModel == nil { + return func(ctx context.Context) error { + return fmt.Errorf("invalid Step %v: missing run or uses key", i) + } + } if stepModel.ID == "" { stepModel.ID = fmt.Sprintf("%d", i) } diff --git a/pkg/runner/job_executor_test.go b/pkg/runner/job_executor_test.go index 2af79336..4d892feb 100644 --- a/pkg/runner/job_executor_test.go +++ b/pkg/runner/job_executor_test.go @@ -21,6 +21,7 @@ func TestJobExecutor(t *testing.T) { {workdir, "uses-docker-url", "push", "", platforms}, {workdir, "uses-github-full-sha", "push", "", platforms}, {workdir, "uses-github-short-sha", "push", "Unable to resolve action `actions/hello-world-docker-action@b136eb8`, the provided ref `b136eb8` is the shortened version of a commit SHA, which is not supported. Please use the full commit SHA `b136eb8894c5cb1dd5807da824be97ccdf9b5423` instead", platforms}, + {workdir, "job-nil-step", "push", "invalid Step 0: missing run or uses key", platforms}, } // These tests are sufficient to only check syntax. ctx := common.WithDryrun(context.Background(), true) diff --git a/pkg/runner/testdata/job-nil-step/push.yml b/pkg/runner/testdata/job-nil-step/push.yml new file mode 100644 index 00000000..b868b047 --- /dev/null +++ b/pkg/runner/testdata/job-nil-step/push.yml @@ -0,0 +1,7 @@ +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - + - run: exit 0