Skip to content
Back to Knowledge Base

Set the Affected Base Commit in CI

nx affected compares two commits, NX_BASE and NX_HEAD, to work out which projects changed. On a pull request, the base is where the branch left the main branch. On a push to the main branch, the most useful base is the last commit that passed CI, so every change since then gets checked. Each CI provider exposes that commit differently.

For complete workflows per provider, see CI workflow examples.

The nrwl/nx-set-shas action finds the last successful run on the main branch and sets NX_BASE and NX_HEAD. Add it after installing dependencies:

.github/workflows/ci.yml
- uses: nrwl/nx-set-shas@v5
- run: npx nx affected -t lint test build

For why the last successful commit matters, see the action documentation.

Last updated: