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

Cypress binary randomly missing with pnpm

enjikaka opened this issue · comments

Branching out my case from #1054

I added the cypess GH action a few days ago in this repo and it has run fine, until I open a PR with a version bump to a package in the monorepo and it suddenly decided to fail on the cypress binary being missing.

I've tried the following solutions after looking through old issues here:

  • Add PNPM cache
  • Add Cypress binary cache
  • Switch cypress gh action to install: true
  • Tried working-dir: with pnpm command instead of pnpm --dir workdir command

Neither yield any different result. Still:

> @tidal-music/player@0.1.3 internal:cypress:run /home/runner/work/tidal-sdk-web/tidal-sdk-web/packages/player
> pnpm cypress run

The cypress npm package is installed, but the Cypress binary is missing.

We expected the binary to be installed here: /home/runner/.cache/Cypress/13.6.6/Cypress/Cypress

Reasons it may be missing:

- You're caching 'node_modules' but are not caching this path: /home/runner/.cache/Cypress
- You ran 'npm install' at an earlier build step but did not persist: /home/runner/.cache/Cypress

Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.

Alternatively, you can run 'cypress install' to download the binary again.

https://on.cypress.io/not-installed-ci-error

Mr PR with alot of different commits where I've tried different combos: tidal-music/tidal-sdk-web#80

I hope someone is able to help finding out the issue :)

@enjikaka

Disabled the cypress workflow in that branch and enabled it here in a new one instead: tidal-music/tidal-sdk-web#82

Run: https://github.com/tidal-music/tidal-sdk-web/actions/runs/8157333147/job/22296765645

@enjikaka

The branch https://github.com/tidal-music/tidal-sdk-web/tree/player-release/0.1.3 which I was going to look at has been deleted, so it's difficult for me to investigate your latest attempt. (OK - I saw you just moved it.)

jobs:
  run-test:
    runs-on: ubuntu-22.04
    name: Run test
    timeout-minutes: 60
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3

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

      - name: Setup Node 18
        uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
          cache: 'pnpm'

      - name: Set up Cypress binary cache
        uses: actions/cache@v3
        with:
          path: ~/.cache/Cypress
          key: cypress-${{ runner.os }}-cypress-${{ hashFiles('pnpm-lock.yaml') }}

      - name: Install dependencies
        run: |
          pnpm i --frozen-lockfile

      - name: Test
        uses: cypress-io/github-action@v6
        with:
          install: false
          working-directory: ./packages/test/
          browser: chrome

That would probably work in principle for you too, updating the versions of the actions used and changing the directory from test to player.

You can let me know if you want to try that out for yourself, or if you want me to work on your branch https://github.com/tidal-music/tidal-sdk-web/tree/re-enable-cypress.

@enjikaka

I ran the following successfully in a fork of your repo. I suspect this failed for you previously due to the pnpm cache preventing the Cypress binary installing.

If you cache the pnpm store and then you add caching for Cypress without allowing for Cypress to install and run the postinstallation script (again) to install the Cypress binary, then the Cypress binary will never be installed and can't be cached.

If you delete the relevant cache from https://github.com/tidal-music/tidal-sdk-web/actions/caches after you have added Cypress binary caching then pnpm will reinstall everything and Cypress will get its binary installed and cached.

jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: ./.github/actions/setup
      - uses: ./.github/actions/build-projects
      - name: Prepare test user for player tests
        id: json
        run: |
          echo ${{ env.TEST_USER }} | base64 -d > test-user.json
          json=$(cat test-user.json)
          replacement=${{ secrets.PLAYER_REFRESH_TOKEN }}
          fixed_json="$(echo ${json/\[TOKEN\]/$replacement})"
          encoded_json=$(echo "$fixed_json" | base64 | tr -d '\n')
          echo "encoded=\"$encoded_json\"" >> $GITHUB_OUTPUT
        env:
          TEST_USER: ${{ secrets.PLAYER_TEST_USER }}

      - name: Set up Cypress binary cache
        uses: actions/cache@v4
        with:
          path: ~/.cache/Cypress
          key: ${{ runner.os }}-cypress-${{ hashFiles('pnpm-lock.yaml') }}

      - name: Cypress run
        uses: cypress-io/github-action@v6
        env:
          CYPRESS_TEST_USER: ${{ steps.json.outputs.encoded }}
        with:
          install: false
          browser: chrome
          start: pnpm --dir packages/player/ dev
          wait-on: 'http://localhost:5173/demo/test-case-1.html'
          command: pnpm --dir packages/player/ internal:cypress:run

@enjikaka

I ran the following successfully in a fork of your repo. I suspect this failed for you previously due to the pnpm cache preventing the Cypress binary installing.
/.../
If you delete the relevant cache from https://github.com/tidal-music/tidal-sdk-web/actions/caches after you have added Cypress binary caching then pnpm will reinstall everything and Cypress will get its binary installed and cached.

That worked! Now it runs again. Thank you very much Mike!

Would the hash not changing be an issue for pnpm/action-setup or is the fact that Cypress store it outside the module folder the "issue" (outside their scope/concern), which needs this extra cache step?

Hm, my second run failed on the binary missing again. I don't see a ${{ runner.os }}-cypress-${{ hashFiles('pnpm-lock.yaml') }} entry in caches though... https://github.com/tidal-music/tidal-sdk-web/actions/runs/8170953305/job/22338441775?pr=82

Found this, I guess this is what I'm seeing. I need to run on the main branch. https://github.com/orgs/community/discussions/27059

@enjikaka

GitHub caches are linked to the branch of the workflow which addresses the cache.

To test workflows using caches you always need to run a workflow twice. Once to populate the cache and then a second time to make sure that the cached contents is being picked up.

It sounds like you have found your issue. Come back here again if you still can't get it to work and I will take another look.

Would the hash not changing be an issue for pnpm/action-setup or is the fact that Cypress store it outside the module folder the "issue" (outside their scope/concern), which needs this extra cache step?

The Cypress binary cache is outside of the scope of the pnpm cache store.

@enjikaka

We've added a new example .github/workflows/example-start-and-pnpm-workspaces.yml to show how the action can be used with pnpm workspaces and there is an explanation about the principle behind it on README > pnpm workspaces. The workflow itself is heavily commented.

You don't need to use this to solve your issue, it just avoids having to handle the Cypress binary cache manually.

Have you already got your workflow running?

@enjikaka

I suggest to close this issue now, as this is not a bug in the action.

  • I've added also an enhancement request #1144

It's running fine in our workflow now. Thanks.