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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
4
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml
vendored
Normal file
4
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/action.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
runs:
|
||||
using: node20
|
||||
main: main.js
|
||||
post: post.js
|
||||
0
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js
vendored
Normal file
0
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/main.js
vendored
Normal file
2
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js
vendored
Normal file
2
pkg/runner/testdata/post-step-failure-is-job-failure/post-step-failure/post.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
console.log('This is a post step failure test');
|
||||
process.exit(1);
|
||||
9
pkg/runner/testdata/post-step-failure-is-job-failure/push.yml
vendored
Normal file
9
pkg/runner/testdata/post-step-failure-is-job-failure/push.yml
vendored
Normal 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
|
||||
Reference in New Issue
Block a user