How to wait for dynamic job to end?

I’m using a monorepo which runs a build job for each application/service that’s been updated. The only issue is when applications/services have strong dependencies on eachother and can’t be run in parallel.

I’m wondering if anyone knows of a way I can wait for a dynamic job to end in the same way the needs field waits for named jobs to end.

Here’s a paraphrased example of my workflow

      matrix: ${{ steps.set-matrix.outputs.matrix }}
      - name: set services matrix
        id: set-matrix
        run: |
          # ... get changed services
          # example output
          echo "::set-output name=matrix::{\"service\":[\"service-1\", \"service-2\"]}" 

    needs: get_changed_services
      matrix: ${{fromJson(needs.get_changed_services.outputs.matrix)}}

      - name: build service
        run: ...

Is there a way I could make some of the dynamic build jobs to wait for other dynamic build jobs?

The assumption for matrix jobs appears to be that there are no inter-dependencies.

You could try to wait in certain jobs that others finish, but that would be really hacky and there’s a chance that you hit the maximum runtime for jobs, especially if there are many jobs to run and a low limit to how many jobs can run in parallel.

Instead, you should probably split up the matrix into multiple jobs, perhaps even with their own matrices, so that you can actually use needs. That may require duplicating job code, but I can’t really think of a better way.