From 7c7b383c10fcaff8a04eafea924c9b02a129bb29 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 13 Jun 2025 18:53:18 +0200 Subject: [PATCH] fix: post step failure is job failure (#5297) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/runner/job_executor.go | 2 +- pkg/runner/runner_test.go | 23 +++++++++++++------ .../post-step-failure/action.yml | 4 ++++ .../post-step-failure/main.js | 0 .../post-step-failure/post.js | 2 ++ .../post-step-failure-is-job-failure/push.yml | 9 ++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml create mode 100644 pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js create mode 100644 pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js create mode 100644 pkg/runner/testdata/post-step-failure-is-job-failure/push.yml diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index ed6e43f..4ab7f23 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -92,7 +92,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo return nil })) - postExec := useStepLogger(rc, stepModel, stepStagePost, step.post()) + postExec := useStepLogger(rc, stepModel, stepStagePost, step.post().ThenError(setJobError)) if postExecutor != nil { // run the post executor in reverse order postExecutor = postExec.Finally(postExecutor) diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index b41048b..bf8b901 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -376,13 +376,24 @@ func (factory *captureJobLoggerFactory) WithJobLogger() *logrus.Logger { return logger } -func TestPullFailureIsJobFailure(t *testing.T) { +func TestPullAndPostStepFailureIsJobFailure(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } - tables := []TestJobFileInfo{ - {workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets}, + defCache := &GoGitActionCache{ + path.Clean(path.Join(workdir, "cache")), + } + + mockCache := &mockCache{} + + tables := []struct { + TestJobFileInfo + ActionCache ActionCache + SetupResult string + }{ + {TestJobFileInfo{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets}, defCache, "failure"}, + {TestJobFileInfo{workdir, "post-step-failure-is-job-failure", "push", "post failure", map[string]string{"ubuntu-latest": "-self-hosted"}, secrets}, mockCache, "success"}, } for _, table := range tables { @@ -397,9 +408,7 @@ func TestPullFailureIsJobFailure(t *testing.T) { if _, err := os.Stat(eventFile); err == nil { config.EventPath = eventFile } - config.ActionCache = &GoGitActionCache{ - path.Clean(path.Join(workdir, "cache")), - } + config.ActionCache = table.ActionCache logger := logrus.New() logger.SetOutput(&factory.buffer) @@ -418,7 +427,7 @@ func TestPullFailureIsJobFailure(t *testing.T) { hasJobResult = true } if val, ok := entry["stepResult"]; ok && !hasStepResult { - assert.Equal(t, "failure", val) + assert.Equal(t, table.SetupResult, val) hasStepResult = true } } diff --git a/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml b/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml new file mode 100644 index 0000000..8b4b322 --- /dev/null +++ b/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml @@ -0,0 +1,4 @@ +runs: + using: node20 + main: main.js + post: post.js \ No newline at end of file diff --git a/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js b/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js new file mode 100644 index 0000000..e69de29 diff --git a/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js b/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js new file mode 100644 index 0000000..e2e1887 --- /dev/null +++ b/pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js @@ -0,0 +1,2 @@ +console.log('This is a post step failure test'); +process.exit(1); \ No newline at end of file diff --git a/pkg/runner/testdata/post-step-failure-is-job-failure/push.yml b/pkg/runner/testdata/post-step-failure-is-job-failure/push.yml new file mode 100644 index 0000000..da79176 --- /dev/null +++ b/pkg/runner/testdata/post-step-failure-is-job-failure/push.yml @@ -0,0 +1,9 @@ +name: basic +on: push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./post-step-failure-is-job-failure/post-step-failure \ No newline at end of file