How do you build only the services that changed in a monorepo?
AdvancedConceptDebugging, Cost, Monorepos & Releases
Answer
Compute changed packages in a first job and feed a dynamic matrix:
jobs:
changes:
runs-on: ubuntu-24.04
outputs:
services: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
api: ['services/api/**', 'libs/common/**']
web: ['apps/web/**', 'libs/common/**']
build:
needs: changes
if: needs.changes.outputs.services != '[]'
strategy:
matrix:
service: ${{ fromJSON(needs.changes.outputs.services) }}
Include shared libraries in each filter, and finish with a fan-in ci-ok job so required checks work even when nothing changed. Build tools like Nx or Turborepo (affected) do the same from the dependency graph.
More on Debugging, Cost, Monorepos & Releases
How do you enable debug logging, and what does each flag show?BeginnerWhat tools help you inspect a run from the terminal?BeginnerHow is GitHub Actions billed for private repos, and what are the multipliers?IntermediateName the top ways to reduce Actions minutes and wall-clock time.IntermediateWhy are workflow-level `paths` filters problematic with required checks, and what is the fix?IntermediateHow do you automate releases with release-please?Intermediate