Skip to content

Commit

Permalink
fix: handle composite action on error and continue
Browse files Browse the repository at this point in the history
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 <bjoern.brauer@new-work.se>
  • Loading branch information
2 people authored and github-actions committed Dec 3, 2021
1 parent 6788ad8 commit 91aa7fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,16 @@ type Output struct {
func ReadAction(in io.Reader) (*Action, error) {
a := new(Action)
err := yaml.NewDecoder(in).Decode(a)
return a, err
if err != nil {
return nil, err
}

for i, _ := range a.Runs.Steps {
step := &a.Runs.Steps[i]
if (*step).If.Value == "" {
(*step).If.Value = "success()"
}
}

return a, nil
}
4 changes: 4 additions & 0 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ func (rc *RunContext) CompositeExecutor() common.Executor {
stepcopy := step
steps = append(steps, rc.newStepExecutor(&stepcopy))
}

steps = append(steps, func(ctx context.Context) error {
return common.JobError(ctx)
})
return common.NewPipelineExecutor(steps...)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestRunEvent(t *testing.T) {
{"testdata", "workdir", "push", "", platforms, ""},
{"testdata", "defaults-run", "push", "", platforms, ""},
{"testdata", "uses-composite", "push", "", platforms, ""},
{"testdata", "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, ""},
{"testdata", "uses-nested-composite", "push", "", platforms, ""},
{"testdata", "issue-597", "push", "", platforms, ""},
{"testdata", "issue-598", "push", "", platforms, ""},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "Test Composite Action"
description: "Test action uses composite"

runs:
using: "composite"
steps:
- run: exit 1
shell: bash
- run: echo should not run in composite steps
shell: bash
12 changes: 12 additions & 0 deletions pkg/runner/testdata/uses-composite-with-error/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: uses-docker-url
on: push

jobs:
failing-composite-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./uses-composite-with-error/composite_action2
- run: echo should run
if: failure()
- run: echo should not run

0 comments on commit 91aa7fb

Please sign in to comment.