Interview Prep/CI/CD/GitHub Actions

You want one workflow job to decide dynamically which services to build, then fan out.

AdvancedScenarioGitHub Actions
Answer

Situation read → Dynamic matrix.

What I'd do →

jobs:
  plan:
    runs-on: ubuntu-latest
    outputs:
      services: ${{ steps.p.outputs.services }}
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - id: p
        run: echo "services=$(./scripts/changed-services.sh | jq -cR '[., inputs]')" >> "$GITHUB_OUTPUT"
  build:
    needs: plan
    if: needs.plan.outputs.services != '[]'
    strategy:
      matrix:
        service: ${{ fromJSON(needs.plan.outputs.services) }}
    runs-on: ubuntu-latest
    steps:
      - run: ./build.sh ${{ matrix.service }}

Why → fromJSON turns job output into a matrix, so the graph adapts to the change set.

Interview tip → Guard the empty list case; an empty matrix fails the workflow.

All CI/CD questions

More on GitHub Actions