22 Nov, 2026Aishwarya Palta
GitHub Actions: pnpm, Turborepo and Nx Caching
Set up GitHub Actions monorepo caching with pnpm and Turborepo or Nx. Separate package downloads from task outputs, and check whether cache restores help.
GitHub Actions monorepo caching works best when package downloads and completed tasks have separate caches. pnpm manages dependencies; Turborepo or Nx can reuse build and test results when their inputs match.
Our developer view: identify the repeated work before adding another cache. A restored package store does not mean compilation or tests have been reused.
What should each cache contain?
| Layer | Reuses | Still required |
|---|---|---|
| pnpm package store | Downloaded packages | Dependency installation and linking |
| Turborepo task cache | Configured task outputs and logs | Correct inputs, outputs and task definitions |
| Nx task cache | Cacheable task results | Correct inputs, outputs and cache configuration |
Use the task runner already configured in your repository. Turborepo and Nx are alternatives here; the example does not require installing both.
How do you cache pnpm dependencies?
Install the project’s pinned pnpm version before invoking setup-node with cache: pnpm and cache-dependency-path: pnpm-lock.yaml. Run installation at the workspace root:
pnpm install --frozen-lockfileThe setup-node documentation confirms that its package cache excludes node_modules. Keep installation after a cache hit, and commit the workspace lockfile.
If your repository has multiple independently installed projects, match dependency-file paths and working directories to that structure. Avoid copying a single-package cache key into a different workspace layout.
How do you reuse completed tasks?
For an existing Turborepo workspace:
pnpm exec turbo run build testDeclare outputs in turbo.json and configure persistent access to cached results. The Turborepo Actions guide documents remote caching and an actions/cache alternative.
For Nx, configure cacheable targets and use Nx remote caching when results must survive ephemeral jobs. Selecting affected tasks and caching their results solve different problems; use both when appropriate.
Cache only reproducible tasks whose relevant inputs are tracked. A test depending on changing external data may need fresh execution even when source files are unchanged.
How do you check the benefit?
Compare restore, installation, execution and save times across cold runs, repeated runs and dependency changes. Check that expected output files are restored, not just that logs report a hit.
Use our cache troubleshooting guide, Node.js workflow and cache-backend documentation when adapting this to Monk CI.
Takeaway: measure the work avoided and the transfer overhead together.