From 7dbf3fcb96e2d70b3436b718c1f4a9fe4b169a4f Mon Sep 17 00:00:00 2001 From: ChristopherHX <christopher.homberger@web.de> Date: Thu, 27 Jan 2022 17:20:44 +0100 Subject: [PATCH] Fix: regression run after failure (#971) * Fix: Regressions of run step after failure * Add test, to enshure no panic * Print error of failed step --- pkg/common/executor.go | 9 ++++--- pkg/runner/run_context.go | 26 +++++++++++++++++-- pkg/runner/runner_test.go | 1 + .../testdata/non-existent-action/push.yml | 7 +++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 pkg/runner/testdata/non-existent-action/push.yml diff --git a/pkg/common/executor.go b/pkg/common/executor.go index a7eec9e..cd92a6c 100644 --- a/pkg/common/executor.go +++ b/pkg/common/executor.go @@ -136,12 +136,13 @@ func (e Executor) Then(then Executor) Executor { case Warning: log.Warning(err.Error()) default: - SetJobError(ctx, err) + log.Debugf("%+v", err) + return err } - } else if ctx.Err() != nil { - SetJobError(ctx, ctx.Err()) } - + if ctx.Err() != nil { + return ctx.Err() + } return then(ctx) } } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index b5b0d43..e072b04 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -261,7 +261,18 @@ func (rc *RunContext) Executor() common.Executor { if step.ID == "" { step.ID = fmt.Sprintf("%d", i) } - steps = append(steps, rc.newStepExecutor(step)) + stepExec := rc.newStepExecutor(step) + steps = append(steps, func(ctx context.Context) error { + err := stepExec(ctx) + if err != nil { + common.Logger(ctx).Errorf("%v", err) + common.SetJobError(ctx, err) + } else if ctx.Err() != nil { + common.Logger(ctx).Errorf("%v", ctx.Err()) + common.SetJobError(ctx, ctx.Err()) + } + return nil + }) } steps = append(steps, func(ctx context.Context) error { err := rc.stopJobContainer()(ctx) @@ -295,7 +306,18 @@ func (rc *RunContext) CompositeExecutor() common.Executor { step.ID = fmt.Sprintf("%d", i) } stepcopy := step - steps = append(steps, rc.newStepExecutor(&stepcopy)) + stepExec := rc.newStepExecutor(&stepcopy) + steps = append(steps, func(ctx context.Context) error { + err := stepExec(ctx) + if err != nil { + common.Logger(ctx).Errorf("%v", err) + common.SetJobError(ctx, err) + } else if ctx.Err() != nil { + common.Logger(ctx).Errorf("%v", ctx.Err()) + common.SetJobError(ctx, ctx.Err()) + } + return nil + }) } steps = append(steps, common.JobError) diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 26fdb16..ca0d19e 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -97,6 +97,7 @@ func TestRunEvent(t *testing.T) { {"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, ""}, {"testdata", "runs-on", "push", "", platforms, ""}, {"testdata", "checkout", "push", "", platforms, ""}, + {"testdata", "non-existent-action", "push", "Job 'nopanic' failed", platforms, ""}, {"testdata", "shells/defaults", "push", "", platforms, ""}, // TODO: figure out why it fails // {"testdata", "shells/custom", "push", "", map[string]string{"ubuntu-latest": "ghcr.io/justingrote/act-pwsh:latest"}, ""}, // custom image with pwsh diff --git a/pkg/runner/testdata/non-existent-action/push.yml b/pkg/runner/testdata/non-existent-action/push.yml new file mode 100644 index 0000000..f6b0c6e --- /dev/null +++ b/pkg/runner/testdata/non-existent-action/push.yml @@ -0,0 +1,7 @@ +on: push +name: non-existent-action +jobs: + nopanic: + runs-on: ubuntu-latest + steps: + - uses: ./path/to/non-existent-action \ No newline at end of file