crumpled paper texture

PNPM GitHub Actions Cache

Fix pnpm caching issues in GitHub Actions with proper store directory configuration

––– views

1 min read

0 likes

PNPM caching in GitHub Actions template that they have in the docs is not working, at least for me.

If you're trying to cache pnpm dependencies in GitHub Actions, add this extra configuration. I found this solution in a GitHub issue.

The Solution

Use this steps configuration to properly cache pnpm dependencies:

.github/workflows/ci.yml
steps:
  - name: ⬇️ Checkout repo
    uses: actions/checkout@v4
 
  - name: 🤌 Setup pnpm
    uses: 'pnpm/action-setup@v4'
    with:
      version: 9.0.4
      run_install: false
 
  # @see Manual caching https://github.com/cypress-io/github-action/issues/1040
  - name: ⎔ Get pnpm store directory
    shell: bash
    run: |
      echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
  - name: ⎔ Setup pnpm cache
    uses: actions/cache@v4
    with:
      path: ${{ env.STORE_PATH }}
      key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
      restore-keys: |
        ${{ runner.os }}-pnpm-store-
 
  - name: ⎔ Setup node
    uses: actions/setup-node@v4
    with:
      node-version: 20
      cache: 'pnpm'
 
  - name: 📥 Download deps
    run: pnpm install --frozen-lockfile

Those highlighted lines are the ones that are different from the template.