Notes

CI/CDMonorepoGitHub Actions

Ship only what changed in a monorepo

How I set up CI/CD for a monorepo with about thirty deployable apps: deploy against what’s actually live, build once, and turn every painful bug into a check.

Applies to
A monorepo with several deployable apps on GitHub Actions, using Nx or another tool that knows which projects a change affects.
Verified with
An Nx monorepo pipeline I built and ran in 2025 and 2026.

A monorepo is great until every pull request builds everything and every push redeploys every app. Here's what I settled on for a repo with about thirty deployable apps, after a lot of slow pipelines.

  1. Pushto main or a deploy branch
  2. Build oncedeployable apps, written to the shared cache
  3. Then, in parallel
    Releasedeploy what changed since each service's live commit, queued
    Checkslint, typecheck and tests reuse the build
  4. Doneunchanged apps never rebuild or redeploy
One build per push feeds both the release and the checks. Pull requests only read the cache.

Deploy against what's live, not against the last push

Most setups decide what to deploy by diffing against the previous commit. That breaks as soon as one deploy fails or gets skipped: the next push only looks at its own diff, and the app that missed out stays behind.

Instead, the release starts by asking each running service which commit it's serving (we tag every image with its commit SHA, so the live image tells you). Then it works out which apps changed since that commit and deploys only those. A failed deploy simply gets picked up next time, and a docs change deploys nothing.

Build once, then reuse it

Every push to a deploy branch runs one build job that builds the deployable apps and writes the results to a shared Nx cache. The release and the post-merge checks both start when it finishes and reuse its output instead of building again. If that output doesn't cover every app a release needs, the release builds them itself.

Keep the cache read-only for almost everyone

A shared build cache is only safe if you trust what's in it. Pull requests and most jobs can read the cache but not write to it. Only the main build job and the post-merge checks get a token that can write, and a small script in CI fails if any other workflow asks for one.

Queue deploys, never cancel them

For pull request checks, cancelling the old run when a new commit lands saves time. For deploys it's dangerous: a cancelled run can stop a database migration halfway, or leave the "what's live" baseline unsettled for the next run. So deploys to the same environment wait in line.

One place for environments and apps

Project IDs, regions and how each environment authenticates live in one JSON file, and the list of deployable apps in another. Every job reads them instead of copying values into each workflow, so adding an environment or an app is one edit. A CI check validates the app list, so a bad entry fails the pull request instead of surfacing halfway through a release. Production authenticates keylessly through workload identity, so there's no long-lived key to leak.

Turn every painful bug into a check

This is the part I'd keep if I could only keep one. When a class of bug cost us real time, we wrote a small script that fails CI if it can happen again. For example:

There are thirteen of these validators now. Most take a few seconds and run together in one job that needs no install. Six of them also have a self-test mode that feeds the check a known-bad example and confirms it fails, because a check that can't fail tells you nothing.

One required check

Branch protection only requires a single job, "CI Success", which looks at every other job and fails if any of them failed or was cancelled. Jobs can then skip themselves when a change doesn't touch them (no React files changed, no React checks) without blocking the merge, and adding a job never means editing branch protection.