WEBDASTUDIO
0%
Initializing Global Environment
Loading core modules...
Back to Blog
Engineering

Optimizing CI/CD: Caching PNPM Dependencies in GitHub Actions

By Dipanjal Maitra
January 3, 2024
5 min read
Optimizing CI/CD: Caching PNPM Dependencies in GitHub Actions

CI/CD execution times directly affect deployment cycles. Re-downloading node packages on every workflow build is highly inefficient. Let's configure custom caching for pnpm projects in GitHub Actions.

1. Setting up PNPM Store Path

PNPM uses a content-addressable store coordinates mechanism to reference modules. We instruct the runner pipeline to fetch the store location using pnpm store path commands, saving the output path as a dynamic workflow state variable.

2. Integration with actions/cache

We configure the actions/cache action to save and restore the store directory, using a cache key based on the lock file: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}. This ensures modules are fetched only when dependencies change.

Conclusion

Setting up pnpm store caching reduces build times by up to 60%, allowing you to push features and hotfixes to production servers in under 2 minutes.

Share this writeup:

Related Articles