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

Required status check job is skipped when one of the dependent job fails #2566

Closed
jaymalasinha opened this issue Apr 25, 2023 · 8 comments
Closed
Labels
bug Something isn't working

Comments

@jaymalasinha
Copy link

jaymalasinha commented Apr 25, 2023

Describe the bug
When one of the required dependent jobs fail in the workflow, the job requiring it is skipped.

  • job "results" needs jobs needs: [build-one, build-two, test, test-more]
  • when job "test" fails, "results" is skipped
  • as "results" is a required status check for merge, it allows merging with failed dependent job

To Reproduce
Create the following workflow file:

name: build

on:
  workflow_dispatch:
  pull_request:
  push:

jobs:
  pre-requisite:
    runs-on: ubuntu-latest
    steps:
      - name: Get Req
        id: get-req
        run: echo "get req"

  build-one:
    name: build one
    runs-on: ubuntu-latest
    needs: pre-requisite
    steps:
      - run: echo "build-one"

  build-two:
    name: build two
    runs-on: ubuntu-latest
    needs: pre-requisite
    steps:
      - run: echo "build-two"

  test:
    name: Test initial
    needs:
      - pre-requisite
      - build-two
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "Testing builds"
          exit 1

  test-more:
    name: Test more
    needs:
      - pre-requisite
      - build-two
    runs-on: ubuntu-latest
    steps:
      - run: echo "Test more"

  results:
    runs-on: ubuntu-latest
    needs:
      - build-one
      - build-two
      - test
      - test-more
    steps:
      - run: echo "Workflows have succeeded!"

The job "results" is a required status check for merge. When the job "test" fails the job "results" is skipped

Expected behavior
The job "results" needs "test" to succeed, so I would expect it to not be skipped, as skipped status check allows merge.
Expect "results" to be skipped if any of the dependent jobs are skipped, like if "test" is skipped, but expect it to fail if any of the dependent jobs fail.

Runner Version and Platform

Current runner version: '2.303.0'

Ubuntu
22.04.2
LTS

Runner Image Provisioner
2.0.139.1

OS of the machine running the runner? OSX/Windows/Linux/...
Ubuntu

What's not working?

image

@ChristopherHX
Copy link
Contributor

Workaround, let GitHub Actions throw an exception instead adding result skipped (you get no check status for the job, rerun will clear the old job status before execution of dependencies) I know this is not supported.

if: success() || ((!cancelled() || contains(needs.*.result, 'cancelled')) && fromjson('throw'))

The if condition is complex to preserve beeing able to cancel the job, if it is running.

Every job depending on that one won't get the chance to run if the condition fails even if you use always()

@jaymalasinha
Copy link
Author

jaymalasinha commented Apr 26, 2023

echo "Workflows have succeeded!"

Thank you @ChristopherHX for the workaround. With the workaround, If the pre-requisite job is skipped results get no check status.

image

@jaymalasinha
Copy link
Author

jaymalasinha commented Apr 26, 2023

updated the workaround to force fail for both failure and cancelled conditions

results:
    if: ${{ cancelled() || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure') }}
    runs-on: ubuntu-latest
    needs: [build-one, build-two, test, test-more]
    steps:
      - run: |
          echo "Some workflows have failed!"
          exit 1

image

That seems to also work with skipping "results" job when "pre-requisite" job is skipped

@ruvceskistefan
Copy link
Collaborator

Hey @jaymalasinha,
I see you have figured out how to fix your workflow for your case, I'll close this issue. If you think we need to reopen it just let me know.

@jaymalasinha
Copy link
Author

Hey @jaymalasinha, I see you have figured out how to fix your workflow for your case, I'll close this issue. If you think we need to reopen it just let me know.

Hi @ruvceskistefan, We figured a workaround for the issue, but won't the expected behavior be that the status check job fails if any of its dependent jobs fail ? We did see that behavior in earlier workflows when we added a required status check job with multiple dependent jobs, but now noticed it started skipping the job incase of dependency failures. So reported it as a bug. We have to workaround it by negating the status check condition, which seems like a temporary hack. Can you please reopen, thanks.

@marcispauls
Copy link

same issue there, seems some breaking changes happened

@saiichihashimoto
Copy link

The workaround didn't work for me. While it failed when the dependent job failed, it also skipped when the dependent job succeeded, which is a massive regression.

@zorzella-tome
Copy link

The workaround is an ugly hack. I would love to have a proper way of doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants