22 Nov, 2026Aishwarya Palta
Monorepo CI: Run Only Affected Checks
Make monorepo CI selective without missing shared-code changes. Configure affected checks, choose the right Git base and verify required checks still run.
Monorepo CI should validate every task affected by a change, including consumers of shared code. Checking only the directory named in a pull request can miss those relationships.
Our developer view: reduce unnecessary execution only after verifying what selects each check. A shorter pipeline is useful when it preserves confidence in the merge.
How do you select affected work?
In an Nx workspace, start with configured task inputs and outputs. Current Nx affected-task guidance explains how changed inputs select tasks and how dependencies influence execution.
For example, changing a shared UI implementation should select the checks that consume it. Changing an unrelated documentation file might select none. Shared configuration, generated files and lockfile changes need explicit review; a directory filter cannot infer your build relationships.
After installing the repository’s pinned Node, pnpm and Nx versions, run:
pnpm exec nx affected -t lint test build --base="$NX_BASE" --head="$NX_HEAD"The targets must exist in your workspace. Fetch the required Git history before calculating the comparison, and log the chosen commit SHAs for debugging.
Which commits should you compare?
Compare the full pull request against its appropriate base, rather than only its latest commit. For default-branch validation, using the last successful run’s commit includes changes left unverified by earlier failures.
The nx-set-shas action derives these values for GitHub Actions. Configure its branch and workflow settings, supply the documented read permissions, and choose explicit failure behavior when no successful baseline exists. Never silently interpret a missing baseline as “nothing changed.”
How do you prove the selection is safe?
Test representative changes before enabling selection broadly:
- Change an application file and inspect its selected tasks.
- Change a shared library and verify relevant consumers.
- Change common build configuration and inspect wider coverage.
- Confirm failures still block merging.
GitHub warns that workflows skipped by path filters can leave required checks pending. Keep required-check behavior explicit.
Use the cache guide for reusing selected work, the workflow-maintenance guide for organizing scripts, and the cost guide to measure impact.
Takeaway: affected selection is a correctness rule before it is a speed optimization.