Skip to content

Commit

Permalink
fix: ensure all post steps are executed (#1286)
Browse files Browse the repository at this point in the history
This fixes an issue in the chain of post steps introduced
while updating the step-logger for composite actions.

It includes a test case so we make sure this does not happen
again.
  • Loading branch information
KnisterPeter authored Jul 29, 2022
1 parent 9d76bac commit 3364f95
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/runner/action_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps {
// run the post executor in reverse order
if postExecutor != nil {
stepPost := rc.newCompositeCommandExecutor(step.post())
postExecutor = newCompositeStepLogExecutor(stepPost, stepID)
stepPost.Finally(postExecutor)
postExecutor = newCompositeStepLogExecutor(stepPost.Finally(postExecutor), stepID)
} else {
stepPost := rc.newCompositeCommandExecutor(step.post())
postExecutor = newCompositeStepLogExecutor(stepPost, stepID)
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 @@ -178,6 +178,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "actions-environment-and-context-tests", "push", "", platforms},
{workdir, "uses-action-with-pre-and-post-step", "push", "", platforms},
{workdir, "evalenv", "push", "", platforms},
{workdir, "ensure-post-steps", "push", "Job 'second-post-step-should-fail' failed", platforms},
{"../model/testdata", "strategy", "push", "", platforms}, // TODO: move all testdata into pkg so we can validate it with planner and runner
// {"testdata", "issue-228", "push", "", platforms, }, // TODO [igni]: Remove this once everything passes
{"../model/testdata", "container-volumes", "push", "", platforms},
Expand Down
10 changes: 10 additions & 0 deletions pkg/runner/testdata/ensure-post-steps/action-composite/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "action composite"
description: "action composite"
runs:
using: composite
steps:
# second post action should fail if executed (we do check on the exit code)
- uses: ./ensure-post-steps/action-post/
with:
fail: "true"
- uses: ./ensure-post-steps/action-post/
11 changes: 11 additions & 0 deletions pkg/runner/testdata/ensure-post-steps/action-post/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "action post"
description: "action post"
inputs:
fail:
description: "true if this should fail"
required: false
default: "false"
runs:
using: node16
main: "./main.js"
post: "./post.js"
Empty file.
3 changes: 3 additions & 0 deletions pkg/runner/testdata/ensure-post-steps/action-post/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (process.env["INPUT_FAIL"] === "true") {
process.exit(1);
}
8 changes: 8 additions & 0 deletions pkg/runner/testdata/ensure-post-steps/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: test
on: push
jobs:
second-post-step-should-fail:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./ensure-post-steps/action-composite/

0 comments on commit 3364f95

Please sign in to comment.