Skip to content

Commit

Permalink
fix: panic if a step in a job is nil (#1145)
Browse files Browse the repository at this point in the history
* fix: panic if a step is a job is nil

* simplify

* [no ci] Add testdata

* [no ci] Add Test
  • Loading branch information
ChristopherHX authored May 12, 2022
1 parent 1e72c59 commit 91fd412
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/runner/job_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/job_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/runner/testdata/job-nil-step/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
-
- run: exit 0

0 comments on commit 91fd412

Please sign in to comment.