Skip to content
Latchkey

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-filter to 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 web

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →