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.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate