Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve job result state in case of failure #1519

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/runner/job_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,29 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo

func setJobResult(ctx context.Context, info jobInfo, rc *RunContext, success bool) {
logger := common.Logger(ctx)

jobResult := "success"
jobResultMessage := "succeeded"
// we have only one result for a whole matrix build, so we need
// to keep an existing result state if we run a matrix
if len(info.matrix()) > 0 && rc.Run.Job().Result != "" {
jobResult = rc.Run.Job().Result
}
Comment on lines 134 to +139
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too happy with this approach, but it is currently the right fix.
We should make this a bigger refactoring to integrate the continue-on-error for jobs and maybe rethink matrix handling.


if !success {
jobResult = "failure"
jobResultMessage = "failed"
}

info.result(jobResult)
if rc.caller != nil {
// set reusable workflow job result
rc.caller.runContext.result(jobResult)
}

jobResultMessage := "succeeded"
if jobResult != "success" {
jobResultMessage = "failed"
}

logger.WithField("jobResult", jobResult).Infof("\U0001F3C1 Job %s", jobResultMessage)
}

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 @@ -170,6 +170,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "remote-action-js", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:runner-latest"}, secrets}, // Test if this works with non root container
{workdir, "matrix", "push", "", platforms, secrets},
{workdir, "matrix-include-exclude", "push", "", platforms, secrets},
{workdir, "matrix-exitcode", "push", "Job 'test' failed", platforms, secrets},
{workdir, "commands", "push", "", platforms, secrets},
{workdir, "workdir", "push", "", platforms, secrets},
{workdir, "defaults-run", "push", "", platforms, secrets},
Expand Down
16 changes: 16 additions & 0 deletions pkg/runner/testdata/matrix-exitcode/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: test

on: push

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
val: ["success", "failure"]
fail-fast: false
steps:
- name: test
run: |
echo "Expected job result: ${{ matrix.val }}"
[[ "${{ matrix.val }}" = "success" ]] || exit 1