Skip to content

Commit 0aca9b8

Browse files
fix: post step failure is job failure (#85)
1 parent 8131645 commit 0aca9b8

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

pkg/runner/job_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
9292
return nil
9393
}))
9494

95-
postExec := useStepLogger(rc, stepModel, stepStagePost, step.post())
95+
postExec := useStepLogger(rc, stepModel, stepStagePost, step.post().ThenError(setJobError))
9696
if postExecutor != nil {
9797
// run the post executor in reverse order
9898
postExecutor = postExec.Finally(postExecutor)

pkg/runner/runner_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,24 @@ func (factory *captureJobLoggerFactory) WithJobLogger() *log.Logger {
371371
return logger
372372
}
373373

374-
func TestPullFailureIsJobFailure(t *testing.T) {
374+
func TestPullAndPostStepFailureIsJobFailure(t *testing.T) {
375375
if testing.Short() {
376376
t.Skip("skipping integration test")
377377
}
378378

379-
tables := []TestJobFileInfo{
380-
{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets},
379+
defCache := &GoGitActionCache{
380+
path.Clean(path.Join(workdir, "cache")),
381+
}
382+
383+
mockCache := &mockCache{}
384+
385+
tables := []struct {
386+
TestJobFileInfo
387+
ActionCache ActionCache
388+
SetupResult string
389+
}{
390+
{TestJobFileInfo{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets}, defCache, "failure"},
391+
{TestJobFileInfo{workdir, "post-step-failure-is-job-failure", "push", "post failure", map[string]string{"ubuntu-latest": "-self-hosted"}, secrets}, mockCache, "success"},
381392
}
382393

383394
for _, table := range tables {
@@ -392,9 +403,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
392403
if _, err := os.Stat(eventFile); err == nil {
393404
config.EventPath = eventFile
394405
}
395-
config.ActionCache = &GoGitActionCache{
396-
path.Clean(path.Join(workdir, "cache")),
397-
}
406+
config.ActionCache = table.ActionCache
398407

399408
logger := log.New()
400409
logger.SetOutput(&factory.buffer)
@@ -413,7 +422,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
413422
hasJobResult = true
414423
}
415424
if val, ok := entry["stepResult"]; ok && !hasStepResult {
416-
assert.Equal(t, "failure", val)
425+
assert.Equal(t, table.SetupResult, val)
417426
hasStepResult = true
418427
}
419428
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runs:
2+
using: node20
3+
main: main.js
4+
post: post.js

pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log('This is a post step failure test');
2+
process.exit(1);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: basic
2+
on: push
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: ./post-step-failure-is-job-failure/post-step-failure

0 commit comments

Comments
 (0)