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>
This commit is contained in:
ChristopherHX
2025-06-13 18:53:18 +02:00
committed by GitHub
parent 515dd6612c
commit 7c7b383c10
6 changed files with 32 additions and 8 deletions

View File

@@ -92,7 +92,7 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo
return nil return nil
})) }))
postExec := useStepLogger(rc, stepModel, stepStagePost, step.post()) postExec := useStepLogger(rc, stepModel, stepStagePost, step.post().ThenError(setJobError))
if postExecutor != nil { if postExecutor != nil {
// run the post executor in reverse order // run the post executor in reverse order
postExecutor = postExec.Finally(postExecutor) postExecutor = postExec.Finally(postExecutor)

View File

@@ -376,13 +376,24 @@ func (factory *captureJobLoggerFactory) WithJobLogger() *logrus.Logger {
return logger return logger
} }
func TestPullFailureIsJobFailure(t *testing.T) { func TestPullAndPostStepFailureIsJobFailure(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping integration test") t.Skip("skipping integration test")
} }
tables := []TestJobFileInfo{ defCache := &GoGitActionCache{
{workdir, "checkout", "push", "pull failure", map[string]string{"ubuntu-latest": "localhost:0000/missing:latest"}, secrets}, 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 { for _, table := range tables {
@@ -397,9 +408,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
if _, err := os.Stat(eventFile); err == nil { if _, err := os.Stat(eventFile); err == nil {
config.EventPath = eventFile config.EventPath = eventFile
} }
config.ActionCache = &GoGitActionCache{ config.ActionCache = table.ActionCache
path.Clean(path.Join(workdir, "cache")),
}
logger := logrus.New() logger := logrus.New()
logger.SetOutput(&factory.buffer) logger.SetOutput(&factory.buffer)
@@ -418,7 +427,7 @@ func TestPullFailureIsJobFailure(t *testing.T) {
hasJobResult = true hasJobResult = true
} }
if val, ok := entry["stepResult"]; ok && !hasStepResult { if val, ok := entry["stepResult"]; ok && !hasStepResult {
assert.Equal(t, "failure", val) assert.Equal(t, table.SetupResult, val)
hasStepResult = true hasStepResult = true
} }
} }

View File

@@ -0,0 +1,4 @@
runs:
using: node20
main: main.js
post: post.js

View File

@@ -0,0 +1,2 @@
console.log('This is a post step failure test');
process.exit(1);

View File

@@ -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