How to Deploy a Preview for Only the Changed App in a Monorepo in GitHub Actions
Detect which app changed and deploy only that preview, so a one-line docs edit does not redeploy every service.
In a monorepo, a paths filter or a changed-files detector limits work to affected apps. Use dorny/paths-filter to set boolean outputs per app, then gate each preview job on its filter.
Steps
- Run
dorny/paths-filterto set an output per app directory. - Gate each preview job with
if: needs.changes.outputs.<app> == 'true'. - Deploy only the apps that changed.
Workflow
.github/workflows/preview.yml
jobs:
changes:
runs-on: ubuntu-latest
outputs:
web: ${{ steps.filter.outputs.web }}
api: ${{ steps.filter.outputs.api }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
web: 'apps/web/**'
api: 'apps/api/**'
preview-web:
needs: changes
if: needs.changes.outputs.web == 'true'
runs-on: ubuntu-latest
steps:
- run: ./deploy-preview.sh --app webGotchas
- If a required check maps to a skipped app job, add a passing placeholder so merges are not blocked.
- Filters read the diff, so shared library changes may need to trigger multiple apps.
Related guides
How to Deploy a Multi-Service Preview Environment in GitHub ActionsBuild and deploy several services into one per-PR preview environment in GitHub Actions using a matrix to bui…
How to Prevent Duplicate Preview Deploys With Concurrency in GitHub ActionsUse a per-PR concurrency group in GitHub Actions so rapid pushes cancel the in-progress preview deploy instea…