cypress-io / github-action

GitHub Action for running Cypress end-to-end & component tests
https://on.cypress.io/guides/continuous-integration/github-actions
MIT License
1.37k stars 345 forks source link

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

Closed AndyLukac closed 1 month ago

AndyLukac commented 1 month ago

Hello, I've been trying to work out how to fix this issue within the github CI. I've tried several different methods, especially coming from this issue.

Here is my current yml file:

name: 🧪 Apps e2e

on:
  pull_request:
    types: [opened, reopened, synchronize, ready_for_review]
  workflow_dispatch:
    inputs:
      run_on_firefox:
        description: Include Firefox browser
        required: false
        default: false
  push:
    branches:
      - master

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name || github.ref }}
  cancel-in-progress: true

jobs:
  runTests:
    name: 🥒 E2e tests (cypress)
    if: github.event.pull_request.draft == false || github.event_name == 'workflow_dispatch'
    runs-on:
      - self-hosted
      - yarn-large
    strategy:
      max-parallel: 2
      fail-fast: false
      matrix:
        browser:
          - name: Chrome
            test_run: pnpm test:functional:run

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Use latest node and pnpm versions
        uses: ./.github/workflows/composites/lemo
        with:
          working-directory: ./apps
          with-install: true

      - name: Cache Cypress binary
        id: cache-cypress-binary
        uses: actions/cache@v3
        with:
          path: ~/.cache/Cypress # https://docs.cypress.io/guides/references/advanced-installation#Binary-cache
          key: ${{ runner.os }}-cypress-binary-${{ hashFiles('apps/e2e/package.json') }}

      - name: Install System dependencies
        run: |
          sudo ...
          sudo ...

      - name: Run e2e tests for ...
        if: always()
        timeout-minutes: 30
        working-directory: ./apps
        run: ${{matrix.browser.test_run}} ...

Here is the error I'm getting in the CI:


cypress run --browser chrome "--spec=cypress/e2e/app1"

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.9.0/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.
MikeMcC399 commented 1 month ago

@AndyLukac

I don't see you using cypress-io/github-action in your workflow. Did you miss this out from your posting or aren't you using it?

The best advice is to add pnpm cypress install into your workflow. If the Cypress binary is already installed, then it skips the installation. If it is not installed, then it installs it.

You should key off the lock file, not package.json.

You should check if you should be using actions/cache@v4 not v3. You may otherwise get a deprecation warning.

AndyLukac commented 1 month ago

Hi @MikeMcC399,

thanks for your prompt reply.

I managed to figure it out in the end, thanks!

MikeMcC399 commented 1 month ago

@AndyLukac

I managed to figure it out in the end, thanks!

Well done! I will close your issue now as I understand you have been able to resolve it.