From 4be9062dd2745c1657ad7b98683397a393159436 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 21 Jan 2022 17:08:30 +0100 Subject: [PATCH] fix: set composite outputs on failure (#945) fix: conclusion and outcome after error with failure condition fix: continue-on-error doesn't work correctly for composite actions --- pkg/runner/run_context.go | 4 +++- pkg/runner/runner_test.go | 1 + pkg/runner/step_context.go | 5 +---- .../actions/composite-fail-with-output/action.yml | 13 +++++++++++++ .../testdata/composite-fail-with-output/push.yml | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 pkg/runner/testdata/actions/composite-fail-with-output/action.yml create mode 100644 pkg/runner/testdata/composite-fail-with-output/push.yml diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 32a52f6..5949dae 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -299,7 +299,9 @@ func (rc *RunContext) CompositeExecutor() common.Executor { } steps = append(steps, common.JobError) - return common.NewPipelineExecutor(steps...) + return func(ctx context.Context) error { + return common.NewPipelineExecutor(steps...)(common.WithJobErrorContainer(ctx)) + } } func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor { diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 636a872..6e3841b 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -122,6 +122,7 @@ func TestRunEvent(t *testing.T) { {"testdata", "uses-composite", "push", "", platforms, ""}, {"testdata", "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, ""}, {"testdata", "uses-nested-composite", "push", "", platforms, ""}, + {"testdata", "composite-fail-with-output", "push", "", platforms, ""}, {"testdata", "issue-597", "push", "", platforms, ""}, {"testdata", "issue-598", "push", "", platforms, ""}, {"testdata", "env-and-path", "push", "", platforms, ""}, diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index f7ba353..e5fd374 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -722,9 +722,6 @@ func (sc *StepContext) execAsComposite(ctx context.Context, step *model.Step, _ compositerc.Inputs = inputs compositerc.ExprEval = compositerc.NewExpressionEvaluator() err = compositerc.CompositeExecutor()(ctx) - if err != nil { - return err - } // Map outputs to parent rc eval = (&StepContext{ @@ -744,7 +741,7 @@ func (sc *StepContext) execAsComposite(ctx context.Context, step *model.Step, _ backup.Env[k] = v } } - return nil + return err } func (sc *StepContext) populateEnvsFromInput(action *model.Action, rc *RunContext) { diff --git a/pkg/runner/testdata/actions/composite-fail-with-output/action.yml b/pkg/runner/testdata/actions/composite-fail-with-output/action.yml new file mode 100644 index 0000000..896022a --- /dev/null +++ b/pkg/runner/testdata/actions/composite-fail-with-output/action.yml @@ -0,0 +1,13 @@ +outputs: + customoutput: + value: my-customoutput-${{ steps.random-color-generator.outputs.SELECTED_COLOR }} +runs: + using: composite + steps: + - name: Set selected color + run: echo '::set-output name=SELECTED_COLOR::green' + id: random-color-generator + shell: bash + - name: fail + run: exit 1 + shell: bash \ No newline at end of file diff --git a/pkg/runner/testdata/composite-fail-with-output/push.yml b/pkg/runner/testdata/composite-fail-with-output/push.yml new file mode 100644 index 0000000..b167d00 --- /dev/null +++ b/pkg/runner/testdata/composite-fail-with-output/push.yml @@ -0,0 +1,14 @@ +name: composite-fail-with-output +on: push + +jobs: + test-for-output: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./actions/composite-fail-with-output + id: composite-fail-with-output + continue-on-error: true + - run: | + echo ${{steps.composite-fail-with-output.outputs.customoutput}} + exit ${{steps.composite-fail-with-output.outputs.customoutput == 'my-customoutput-green' && '0' || '1'}} \ No newline at end of file