Job depending on job using matrix starts even though not all jobs in job matrix have completed

I use a setup where a have a bunch of jobs:

  • code-coverage
  • coding-standards
  • dependency-analysis
  • mutation-tests
  • static-code-analysis
  • tests

Here, the tests job uses a matrix strategy.

In addition to these jobs, I have a merge job, which needs all of these jobs to pass. In this job, I attempt to merge the pull request, assuming that all builds have completed).

I have observed, though, that the merge job is started (and, consequently fails) when the first job in the job matrix of the test job has completed. At this time, however, the pull request cannot (branch protection) and should not be merged.

I am not sure whether this is supposed to be a feature, but from my point of view, this is a bug. If a job depends on a different job in the same workflow that uses a matrix strategy, then I would not expect the former job to start unless all of the jobs in the latter job matrix are completed.

What do you think?

@localheinz ,

According to my test and check, a job will start only after all of its needs jobs complete successfully, include waiting for all the needed matrix jobs complete successfully. Any one of the needed jobs (include any one of the needed matrix jobs) runs failed, the jobs that need it will be skipped.

jobs:
  job01:
    name: Job 01
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - name: Run matrix jobs
        run: echo "Run matrix jobs"

  job02:
    name: Job 02
    runs-on: ubuntu-latest
    steps:
      - name: Run Job 02
        run: echo "Run Job 02"

  job03:
    name: Job 03
    needs: [job01, job02]
    runs-on: ubuntu-latest
    steps:
      - name: all jobs completed
        run: echo "all need jobs completed successfully"

Looks like, all the behaviors are correct as expected on my side. 

If possible, please share your repository with us, so that we can check more detailed configurations of the workflow in your repository to analyze the root cause.

@brightran 

Here’s an example of where the merge job has started and attempted to merge a pull request while required status checks have not yet completed

https://github.com/ergebnis/factory-bot/runs/549669372

Here’s the corresponding workflow configuration

https://github.com/ergebnis/factory-bot/blob/6da9b0160d09e33760dde0ade05b6f0a1cec9528/.github/workflows/integrate.yaml

@localheinz ,

Thanks for sharing your repository.

I forked your repository and tested on my side (see here), however I still did not reproduce the problem you reported.

The " Merge" job won’t start before all of its needs jobs (include the all the matrix jobs setup on " Tests" job) complete successfully.

I also checked the detailed syntaxes in the workflow, and I did not find any serious wrong syntax that may cause the problem.

Please confirm again whether the problem still occurs on your repository, and you also can fork/import this repository in another repository on the different organization to see if the problem still exists.

If the problem still exists, I will help you report this problem to the appropriate engineering team for further investigation and evaluation.

@brightran 

I would not have opened this issue if I had experienced this problem once only.

I have experienced it probably hundreds of times since I started adding jobs like that.

@localheinz ,

OK, I have helped you report this ticket to the appropriate engineering team. If they have any progress, I will notify you in time, and sometimes the appropriate engineers may directly reply you here.

1 Like

Thank you, @brightran!

Many Thanks for the repository, it has helped in a project I am handling here https://www.topnigerianjobs.com/ You have saved me hours and hours of work.