cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests

Home Page:https://on.cypress.io/guides/continuous-integration/github-actions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PNPM Cache does not work properly

FFdhorkin opened this issue · comments

I have a workflow file that contains these steps:

        -   name: Install pnpm
            uses: pnpm/action-setup@v2
            with:
                version: 8

        -   name: Install Cypress node dependencies
            uses: cypress-io/github-action@v6
            with:
                # just perform install
                runTests: false

        -   name: Run Cypress tests
            uses: cypress-io/github-action@v6
            with:
                spec: |
                    ${{ inputs.spec}}
                # we have already installed all dependencies above
                install: false

The resulting log when I run this action:

Install Cypress node dependencies

Run cypress-io/github-action@v6
  with:
    runTests: false
    record: false
    publish-summary: true
    component: false
  env:
    LANG: en_US.UTF-8
    LANGUAGE: en_US:en
    LC_ALL: en_US.UTF-8
    PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
Received 1296 of 1296 (100.0%), 0.0 MBs/sec
Cache Size: ~0 MB (1296 B)
/usr/bin/tar -xf /runner/_work/_temp/6a12e4a6-f1fb-4cbd-8ce3-459325a65e4b/cache.tzst -P -C /runner/_work/my_repo_name/my_repo_name --use-compress-program unzstd
Cache restored successfully
Received 0 of 335911813 (0.0%), 0.0 MBs/sec
Received 46137344 of 335911813 (13.7%), 22.0 MBs/sec
Received 134217728 of 335911813 (40.0%), 42.1 MBs/sec
Received 213909504 of 335911813 (63.7%), 50.5 MBs/sec
Received 268435456 of 335911813 (79.9%), 50.8 MBs/sec
Received 335911813 of 335911813 (100.0%), 54.5 MBs/sec
Cache Size: ~320 MB (335911813 B)
/usr/bin/tar -xf /runner/_work/_temp/a3c276a3-657e-44f5-87e6-7653ff6c6f6e/cache.tzst -P -C /runner/_work/my_repo_name/my_repo_name--use-compress-program unzstd
Cache restored successfully
/home/runner/setup-pnpm/node_modules/.bin/pnpm install --frozen-lockfile
Lockfile is up to date, resolution step is skipped
Progress: resolved 1, reused 0, downloaded 0, added 0
Packages: +1407
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 1407, reused 0, downloaded 113, added 112
Progress: resolved 1407, reused 0, downloaded 446, added 446
Progress: resolved 1407, reused 0, downloaded 656, added 656
Progress: resolved 1407, reused 0, downloaded 924, added 925
Progress: resolved 1407, reused 0, downloaded 1250, added 1251
Progress: resolved 1407, reused 0, downloaded 1404, added 1406
Progress: resolved 1407, reused 0, downloaded 1405, added 1407, done
...

While it does indicate there is a 320MB cache, the cache actually isn't working. You can see at the end of the log that it is still downloading packages.

Compare this to the result of running rm -rf node_modules && pnpm install --frozen-lockfile on my local machine:

╰─ rm -rf node_modules && pnpm install --frozen-lockfile ─╯
Lockfile is up to date, resolution step is skipped
Packages: +1407
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/username/.local/share/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 1407, reused 1405, downloaded 0, added 1407, done

@FFdhorkin

Which GitHub runner have you selected in your workflow in the runs-on parameter?

For github-action to avoid reinstalling pnpm packages it would need to cache the directory shown by executing pnpm store path. On a ubuntu-22.04 runner after using pnpm/action-setup@v2 with pnpm version 8 the directory is shown as /home/runner/setup-pnpm/node_modules/.bin/store/v3.

Running the example from .github/workflows/example-basic-pnpm.yml with ACTIONS_STEP_DEBUG set to true (see Enabling step debug logging) shows that the empty directory /home/runner/.npm is being cached instead of the pnpm cache directory /home/runner/setup-pnpm/node_modules/.bin/store/v3.

The two clues in the logs from the original posting are:

Cache Size: ~0 MB (1296 B)
Progress: resolved 1407, reused 0, downloaded 1405, added 1407, done

The Cache Size should not be 0 and downloaded should be 0.

So caching for pnpm seems to be missing functionality which has not been implemented.

  • pnpm support was added through #586

@FFdhorkin

As a workaround for the missing pnpm caching functionality in github-action you can use the caching documented in pnpm/action-setup > Use cache to reduce installation time.

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8
          run_install: false

      - name: Get pnpm store directory
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

@FFdhorkin

Which GitHub runner have you selected in your workflow in the runs-on parameter?

It's a self-hosted runner based on summerwind/actions-runner

@FFdhorkin

As a workaround for the missing pnpm caching functionality in github-action you can use the caching documented in pnpm/action-setup > Use cache to reduce installation time.

      - uses: pnpm/action-setup@v2
        name: Install pnpm
        with:
          version: 8
          run_install: false

      - name: Get pnpm store directory
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

That's exactly what I ended up doing yesterday :) thanks

I imagine the best solution is to do exactly what you said rather than hardcoding, but in case it is useful somehow, my store path is /runner/_work/.pnpm-store/v3

I don't understand why the pnpm/action-setup doesn't have a built-in cache option. I guess I'll go file a ticket on them 😄

@FFdhorkin

It's good to hear that you have a solution now! Hard-coding the path would be fine for an individual situation. Getting it dynamically just protects against any change and is cross-compatible to other operating systems.

You may like to close this issue now since I picked up the missing functionality in the issue / PR listed in #1040 (comment) ^^.