Skip to content

Commit 7c7b383

Browse files
ChristopherHXgithub-actions[bot]mergify[bot]
authored
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>
1 parent 515dd66 commit 7c7b383

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
@@ -376,13 +376,24 @@ func (factory *captureJobLoggerFactory) WithJobLogger() *logrus.Logger {
376376
return logger
377377
}
378378

379-
func TestPullFailureIsJobFailure(t *testing.T) {
379+
func TestPullAndPostStepFailureIsJobFailure(t *testing.T) {
380380
if testing.Short() {
381381
t.Skip("skipping integration test")
382382
}
383383

384-
tables := []TestJobFileInfo{
385-
{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets},
384+
defCache := &GoGitActionCache{
385+
path.Clean(path.Join(workdir, "cache")),
386+
}
387+
388+
mockCache := &mockCache{}
389+
390+
tables := []struct {
391+
TestJobFileInfo
392+
ActionCache ActionCache
393+
SetupResult string
394+
}{
395+
{TestJobFileInfo{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets}, defCache, "failure"},
396+
{TestJobFileInfo{workdir, "post-step-failure-is-job-failure", "push", "post failure", map[string]string{"ubuntu-latest": "-self-hosted"}, secrets}, mockCache, "success"},
386397
}
387398

388399
for _, table := range tables {
@@ -397,9 +408,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
397408
if _, err := os.Stat(eventFile); err == nil {
398409
config.EventPath = eventFile
399410
}
400-
config.ActionCache = &GoGitActionCache{
401-
path.Clean(path.Join(workdir, "cache")),
402-
}
411+
config.ActionCache = table.ActionCache
403412

404413
logger := logrus.New()
405414
logger.SetOutput(&factory.buffer)
@@ -418,7 +427,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
418427
hasJobResult = true
419428
}
420429
if val, ok := entry["stepResult"]; ok && !hasStepResult {
421-
assert.Equal(t, "failure", val)
430+
assert.Equal(t, table.SetupResult, val)
422431
hasStepResult = true
423432
}
424433
}
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)