Skip to content

Commit c51290b

Browse files
KnisterPeterZauberNerd
authored andcommitted
fix: handle composite action on error and continue
This change is a follow up of nektos#840 and integrates with nektos#793 There are two things included here: - The default value for a step.if in an action need to be 'success()' - We need to hand the error from a composite action back to the calling executor Co-authored-by: Björn Brauer <[email protected]>
1 parent 542293f commit c51290b

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

pkg/model/action.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,16 @@ type Output struct {
8383
func ReadAction(in io.Reader) (*Action, error) {
8484
a := new(Action)
8585
err := yaml.NewDecoder(in).Decode(a)
86-
return a, err
86+
if err != nil {
87+
return nil, err
88+
}
89+
90+
for i, _ := range a.Runs.Steps {
91+
step := &a.Runs.Steps[i]
92+
if (*step).If.Value == "" {
93+
(*step).If.Value = "success()"
94+
}
95+
}
96+
97+
return a, nil
8798
}

pkg/runner/run_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ func (rc *RunContext) CompositeExecutor() common.Executor {
340340
stepcopy := step
341341
steps = append(steps, rc.newStepExecutor(&stepcopy))
342342
}
343+
344+
steps = append(steps, func(ctx context.Context) error {
345+
return common.JobError(ctx)
346+
})
343347
return common.NewPipelineExecutor(steps...)
344348
}
345349

pkg/runner/runner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func TestRunEvent(t *testing.T) {
118118
{"testdata", "workdir", "push", "", platforms, ""},
119119
{"testdata", "defaults-run", "push", "", platforms, ""},
120120
{"testdata", "uses-composite", "push", "", platforms, ""},
121+
{"testdata", "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, ""},
121122
{"testdata", "uses-nested-composite", "push", "", platforms, ""},
122123
{"testdata", "issue-597", "push", "", platforms, ""},
123124
{"testdata", "issue-598", "push", "", platforms, ""},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: "Test Composite Action"
3+
description: "Test action uses composite"
4+
5+
runs:
6+
using: "composite"
7+
steps:
8+
- run: exit 1
9+
shell: bash
10+
- run: echo should not run in composite steps
11+
shell: bash
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: uses-docker-url
2+
on: push
3+
4+
jobs:
5+
failing-composite-action:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- uses: ./uses-composite-with-error/composite_action2
10+
- run: echo should run
11+
if: failure()
12+
- run: echo should not run

0 commit comments

Comments
 (0)