diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 4d860a2..94d9cfc 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -503,7 +503,10 @@ func runPreStep(step actionStep) common.Executor { step.getCompositeRunContext(ctx) } - return step.getCompositeSteps().pre(ctx) + if steps := step.getCompositeSteps(); steps != nil && steps.pre != nil { + return steps.pre(ctx) + } + return fmt.Errorf("missing steps in composite action") default: return nil @@ -592,7 +595,10 @@ func runPostStep(step actionStep) common.Executor { return err } - return step.getCompositeSteps().post(ctx) + if steps := step.getCompositeSteps(); steps != nil && steps.post != nil { + return steps.post(ctx) + } + return fmt.Errorf("missing steps in composite action") default: return nil diff --git a/pkg/runner/action_composite.go b/pkg/runner/action_composite.go index 0b6fbe5..b6ef58c 100644 --- a/pkg/runner/action_composite.go +++ b/pkg/runner/action_composite.go @@ -86,6 +86,10 @@ func execAsComposite(step actionStep) common.Executor { steps := step.getCompositeSteps() + if steps == nil || steps.main == nil { + return fmt.Errorf("missing steps in composite action") + } + ctx = WithCompositeLogger(ctx, &compositeRC.Masks) err := steps.main(ctx) diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index fb51be9..b0ce4f2 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -299,6 +299,7 @@ func TestRunEvent(t *testing.T) { {workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets}, {workdir, "set-env-step-env-override", "push", "", platforms, secrets}, {workdir, "set-env-new-env-file-per-step", "push", "", platforms, secrets}, + {workdir, "no-panic-on-invalid-composite-action", "push", "jobs failed due to invalid action", platforms, secrets}, } for _, table := range tables { @@ -401,6 +402,7 @@ func TestRunEventHostEnvironment(t *testing.T) { {workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets}, {workdir, "set-env-step-env-override", "push", "", platforms, secrets}, {workdir, "set-env-new-env-file-per-step", "push", "", platforms, secrets}, + {workdir, "no-panic-on-invalid-composite-action", "push", "jobs failed due to invalid action", platforms, secrets}, }...) } diff --git a/pkg/runner/testdata/no-panic-on-invalid-composite-action/push.yml b/pkg/runner/testdata/no-panic-on-invalid-composite-action/push.yml new file mode 100644 index 0000000..6b9e4ae --- /dev/null +++ b/pkg/runner/testdata/no-panic-on-invalid-composite-action/push.yml @@ -0,0 +1,29 @@ +on: push +jobs: + local-invalid-step: + runs-on: ubuntu-latest + steps: + - run: | + runs: + using: composite + steps: + - name: Foo + - uses: Foo/Bar + shell: cp {0} action.yml + - uses: ./ + local-missing-steps: + runs-on: ubuntu-latest + steps: + - run: | + runs: + using: composite + shell: cp {0} action.yml + - uses: ./ + remote-invalid-step: + runs-on: ubuntu-latest + steps: + - uses: nektos/act-test-actions/invalid-composite-action/invalid-step@main + remote-missing-steps: + runs-on: ubuntu-latest + steps: + - uses: nektos/act-test-actions/invalid-composite-action/missing-steps@main \ No newline at end of file