GithubHelp home page GithubHelp logo

cypress-io / github-action Goto Github PK

View Code? Open in Web Editor NEW
1.3K 38.0 315.0 27.29 MB

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

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

License: MIT License

JavaScript 87.06% Shell 12.94%
github-actions actions cypress cypress-io

github-action's Introduction

cypress-io/github-action Action status cypress renovate-app badge

GitHub Action for running Cypress end-to-end and component tests. Includes npm, pnpm and Yarn installation, custom caching and lots of configuration options.

Placing use: cypress-io/github-action@v6 into a GitHub Action workflow gives you a simple way to run Cypress. The action takes the project's npm, pnpm or Yarn package manager lock file, installs dependencies and caches these dependencies for future use. It then proceeds to run Cypress end-to-end tests with the built-in Electron browser and provides a test summary after completion.

If you are testing against a running server like the Cypress Kitchen Sink showcase example on https://example.cypress.io/ no other parameters are necessary. In other cases where you need to fire up a development server, you can add the start parameter to the workflow. Browse through the examples to find other useful parameters.

Examples

Examples contained in this repository, based on current Cypress versions, can be found in the examples directory. Examples for Legacy Configuration, which use Cypress 9.7.0, are no longer maintained. They can be referred to in the examples/v9 directory of the v5 branch.

Live examples, such as example-basic.yml are shown together with a status badge. Click on the status badge to read the source code of the workflow, for example

End-to-End example

Older external examples based on a Legacy Configuration for Cypress 9 and earlier can be found in the README for version v5.

Note: this package assumes that cypress is declared as a development dependency in the package.json file. The cypress npm module is required to run Cypress via its Module API.

End-to-End Testing

name: End-to-end tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      # Install npm dependencies, cache them correctly
      # and run all Cypress tests
      - name: Cypress run
        uses: cypress-io/github-action@v6

End-to-End example

The workflow file example-basic.yml shows how Cypress runs on GH Actions using Ubuntu (20 and 22), Windows, and macOS without additional OS dependencies necessary.

This workflow uses the default test type of End-to-End (E2E) Testing. Alternatively, Component Testing can be utilized by referencing the Component Testing section below.

Component Testing

To use Cypress Component Testing add component: true

name: Component tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          component: true

Component Testing example

See the example project component-tests and the example-component-test.yml workflow for more details.

Action version

Best practice:

Our examples specify using branch v6 which is the action's recommended major version:

- name: Cypress run
  uses: cypress-io/github-action@v6

When using cypress-io/github-action@v6 from your workflow file, you will automatically use the latest tag from branch v6.

Alternatively, to mitigate unforeseen breaks, bind to a specific tag, for example:

- name: Cypress run
  uses: cypress-io/[email protected]

The changes associated with each tag are shown under GitHub's releases list. Refer also to the CHANGELOG for an overview of major changes.

Browser

Specify the browser name or path with the browser parameter. The default browser, if none is specified, is the built-in Electron browser.

Chrome

name: Chrome
on: push
jobs:
  chrome:
    runs-on: ubuntu-22.04
    name: E2E on Chrome
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          browser: chrome

Chrome example

Firefox

name: Firefox
on: push
jobs:
  firefox:
    runs-on: ubuntu-22.04
    name: E2E on Firefox
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          browser: firefox

Firefox example

Edge

name: Edge
on: push
jobs:
  edge:
    runs-on: ubuntu-22.04
    name: E2E on Edge
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          browser: edge

Edge example

Headed

Run the browser in headed mode - as of Cypress v8.0 the cypress run command executes tests in headless mode by default

name: Chrome headed
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          browser: chrome
          headed: true

Docker image

You can run the action in a Docker container.

name: Test in Docker
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    # Cypress Docker image from https://hub.docker.com/r/cypress
    # with browsers pre-installed
    container:
      image: cypress/browsers:latest
      options: --user 1001
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          browser: chrome

Replace the latest tag with a specific version image tag from cypress/browsers on Docker Hub to avoid breaking changes when new images are released (especially when they include new major versions of Node.js).

Include options: --user 1001 to avoid permissions issues.

Refer to cypress-io/cypress-docker-images for further information about using Cypress Docker images. Cypress offers the Cypress Docker Factory to generate additional Docker images with selected components and versions.

Docker example

Env

Specify the env argument with env parameter

name: Cypress tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run with env
        uses: cypress-io/github-action@v6
        with:
          env: host=api.dev.local,port=4222

When passing the environment variables this way, unfortunately due to GitHub Actions syntax, the variables should be listed in a single line, which can be hard to read. As an alternative, you can use the step's env block where every variable can be set on its own line. In this case, you should prefix every variable with CYPRESS_ because such variables are loaded by Cypress automatically. The above code example is equivalent to:

name: Cypress tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run with env
        uses: cypress-io/github-action@v6
        env:
          CYPRESS_host: api.dev.local
          CYPRESS_port: 4222

For more examples, see the workflows below, using environment variables for recording.

Env example

Specs

Specify the spec files to run with spec parameter

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          spec: cypress/e2e/spec1.cy.js

You can pass multiple specs and wild card patterns using multi-line parameter, see example-config.yml:

spec: |
  cypress/e2e/spec-a.cy.js
  cypress/**/*-b.cy.js

For more information, visit the Cypress command-line docs.

Project

Specify the project to run with project parameter

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          project: ./some/nested/folder

For more information, visit the Cypress command-line docs.

Record test results on Cypress Cloud

By setting the parameter record to true, you can record your test results into the Cypress Cloud. Read the Cypress Cloud documentation to learn how to sign up and create a Cypress Cloud project.

We recommend passing the GITHUB_TOKEN secret (created by the GH Action automatically) as an environment variable. This will allow correctly identifying every build and avoid confusion when re-running a build.

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
        env:
          # pass GitHub token to allow accurately detecting a build vs a re-run build
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

recording example

Project ID and Record Key

To record the project needs projectId and recordKey.

Typically, the projectId is stored in the Cypress Configuration File, while the recordKey is set as a CLI parameter. If you want to avoid this, both the projectId and recordKey can be provided as environment variables using GitHub secrets.

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
        env:
          # pass the Cypress Cloud record key as an environment variable
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          # pass the project ID from the secrets through environment variable
          CYPRESS_PROJECT_ID: ${{ secrets.PROJECT_ID }}

Git information

Cypress uses the @cypress/commit-info package to associate Git details (branch, commit message, author) with each run. It typically uses Git commands, expecting a .git folder. In Docker or similar environments where .git is absent, or if you need different data in the Cypress Cloud, Git information can be passed via custom environment variables.

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
        env:
          # Get the short ref name of the branch that triggered the workflow run
          COMMIT_INFO_BRANCH: ${{ github.ref_name }}

Please refer to the Cypress Cloud Git information environment variables section in our documentation for more examples.

Please refer to the default GitHub environment variables for additional GitHub examples.

Automatic PR number and URL detection

When recording runs to Cypress Cloud, the PR number and URL can be automatically detected if you pass GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} via the workflow env. When set, this value enables the Action to perform additional logic that grabs the related PR number and URL (if they exist) and sets them in the environment variables CYPRESS_PULL_REQUEST_ID and CYPRESS_PULL_REQUEST_URL, respectively.

Example workflow using the variables:

name: Example echo PR number and URL
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
      - run: echo "PR number is $CYPRESS_PULL_REQUEST_ID"
      - run: echo "PR URL is $CYPRESS_PULL_REQUEST_URL"
    env:
      CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Triggering event: pull_request/pull_request_target

For either of these events, we set CYPRESS_PULL_REQUEST_ID and CYPRESS_PULL_REQUEST_URL to that of the PR number and URL, respectively, of the PR that triggered the workflow.

Triggering event: push

When a commit on a branch without a PR is made, the Cypress GitHub Action checks to see if the commit that triggered the workflow has a related PR. If the commit exists in any other PRs, it's considered a related PR. When there are related PRs, we grab the first related PR and use that PR's number and URL for CYPRESS_PULL_REQUEST_ID and CYPRESS_PULL_REQUEST_URL, respectively.

If no related PR is detected, CYPRESS_PULL_REQUEST_ID and CYPRESS_PULL_REQUEST_URL will be undefined.

Merge SHA into SHA

We recommend using the action with on: push rather than on: pull_request or on: merge_group for more accurate commit information in Cypress Cloud. When running on pull_request or merge_group, the commit message defaults to "merge SHA into SHA". You can overwrite the commit message sent to Cypress Cloud by setting an environment variable.

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
        env:
          # overwrite commit message sent to Cypress Cloud
          COMMIT_INFO_MESSAGE: ${{github.event.pull_request.title}}
          # re-enable PR comment bot
          COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha}}

See issue 124 for details.

Tag recordings

You can pass a single or multiple tags when recording a run. For example

name: tags
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    # let's make sure our "app" works on several versions of Node
    strategy:
      matrix:
        node: [18, 20, 21]
    name: E2E on Node v${{ matrix.node }}
    steps:
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - run: node -v

      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
          tag: node-${{ matrix.node }}
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The recording will have tags as labels on the run.

Tags

You can pass multiple tags using commas like tag: node-18,nightly,staging.

Specify auto cancel after failures

Specify the number of failed tests that will cancel a run when using the Cypress Cloud Auto Cancellation feature.

This feature requires Cypress 12.6.0 or later and a Cypress Cloud Business or Enterprise account.

name: Cypress E2E Tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    name: E2E
    steps:

      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
          # Cancel the run after 2 failed tests
          auto-cancel-after-failures: 2
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

See Auto Cancellation for more information.

Artifacts

If you don't record the test run on Cypress Cloud, you can still store generated videos and screenshots as CI artifacts. See the workflow example below.

name: Artifacts
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    name: Artifacts
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
      # after the test run completes store videos and any screenshots
      - uses: actions/upload-artifact@v4
        # add the line below to store screenshots only on failures
        # if: failure()
        with:
          name: cypress-screenshots
          path: cypress/screenshots
          if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
      - uses: actions/upload-artifact@v4
        with:
          name: cypress-videos
          path: cypress/videos
          if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`

Quiet flag

You can provide quiet flag for cypress run to silence any Cypress specific output from stdout

name: example-quiet
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      # Install npm dependencies, cache them correctly
      # and run all Cypress tests with `quiet` parameter
      - name: Cypress run
        uses: ./
        with:
          working-directory: examples/quiet
          quiet: true

example-quiet

Config

Specify configuration values with config parameter

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          config: pageLoadTimeout=100000,baseUrl=http://localhost:3000

example-config

Config File

Specify the path to your Configuration File with config-file parameter

name: Cypress tests
on: push
jobs:
  cypress-run:
    name: Cypress run
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          config-file: cypress.config-alternate.js

example-config

Parallel

Note: Cypress parallelization requires a Cypress Cloud account.

You can spin multiple containers running in parallel using strategy: matrix argument. Just add more dummy items to the containers: [1, 2, ...] array to spin more free or paid containers. Then use record and parallel parameters to load balance tests.

name: Parallel Cypress Tests
on: push
jobs:
  test:
    name: Cypress run
    runs-on: ubuntu-22.04
    strategy:
      # when one test fails, DO NOT cancel the other
      # containers, because this will kill Cypress processes
      # leaving Cypress Cloud hanging ...
      # https://github.com/cypress-io/github-action/issues/48
      fail-fast: false
      matrix:
        # run 3 copies of the current job in parallel
        containers: [1, 2, 3]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      # because of "record" and "parallel" parameters
      # these containers will load balance all found tests among themselves
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
          parallel: true
          group: 'Actions example'
        env:
          # pass the Cypress Cloud record key as an environment variable
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          # Recommended: pass the GitHub token lets this action correctly
          # determine the unique run id necessary to re-run the checks
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Parallel run

The Cypress GH Action does not spawn or create any additional containers - it only links the multiple containers spawned using the matrix strategy into a single logical Cypress Cloud run where it splits the specs amongst the machines. See the Cypress Cloud Smart Orchestration guide for a detailed explanation.

If you use the GitHub Actions facility for Re-running workflows and jobs, note that Re-running failed jobs in a workflow is not suited for use with parallel recording into Cypress Cloud. Re-running failed jobs in this situation does not simply re-run failed Cypress tests. Instead it re-runs all Cypress tests, load-balanced over the containers with failed jobs.

To optimize runs when there are failing tests present, refer to optional Cypress Cloud Smart Orchestration Premium features:

During staged rollout of a new GitHub-hosted runner version, GitHub may provide a mixture of current and new image versions used by the container matrix. It is recommended to use a Docker image in the parallel job run which avoids any Cypress Cloud errors due to browser major version mismatch from the two different image versions. A Docker image is not necessary if testing against the default built-in Electron browser because this browser version is fixed by the Cypress version in use and it is unaffected by any GitHub runner image rollout.

Component and E2E Testing

Component Testing and End-to-End (E2E) Testing types can be combined in the same job using separate steps

- name: Run E2E tests
  uses: cypress-io/github-action@v6

- name: Run Component Testing
  uses: cypress-io/github-action@v6
  with:
    # we have already installed everything
    install: false
    component: true

See the example project component-test and the example-component-test.yml workflow for more details.

Build app

You can run a build step before starting tests

name: Build
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          build: npm run build

Start server

If your tests run against a local server, use the start parameter to start your server. The server will run in the background.

name: With server
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          start: npm start

Caution: use the start parameter only to start a server, not to run Cypress, otherwise tests may be run twice. The action runs Cypress tests by default, unless the parameter runTests is set to false.

Note: sometimes on Windows you need to run a different start command. You can use the start-windows parameter for this.

name: With server
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          # Linux and MacOS
          start: npm start
          # Takes precedences on Windows
          start-windows: npm run start:windows:server

start example

Note: A server continues to run until the end of the GitHub workflow job that started it. At the end of the job the GitHub workflow runner executes a "Complete job" phase automatically where it terminates any server processes which are still running.

Start multiple servers

You can start multiple server processes. For example, if you have an API to start using npm run api and the web server to start using npm run web you can put those commands in start using comma separation.

name: With servers
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          start: npm run api, npm run web

You can place the start commands in separate lines

with:
  start: |
    npm run api
    npm run web

start example

Wait-on

If you are starting a local server and it takes a while to start, you can add a parameter wait-on and pass url to wait for the server to respond.

name: After server responds
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          start: npm start
          # quote the url to be safe against YML parsing surprises
          wait-on: 'http://localhost:8080'

wait-on example

Webpack Dev Server example (also uses wait-on)

By default, wait-on will retry for 60 seconds. You can pass a custom timeout in seconds using wait-on-timeout.

- uses: cypress-io/github-action@v6
  with:
    start: npm start
    wait-on: 'http://localhost:8080/status'
    # wait for 2 minutes for the server to respond
    wait-on-timeout: 120

You can wait for multiple URLs to respond by separating urls with a comma

- uses: cypress-io/github-action@v6
  with:
    # API runs on port 3050
    # Web server runs on port 8080
    start: npm run api, npm run web
    # wait for all services to respond
    wait-on: 'http://localhost:3050, http://localhost:8080'

The action will wait for the first url to respond, then will check the second url, and so on.

You can even use your own command (usually by using npm, yarn, npx) to wait for the server to respond. For example, if you want to use the wait-on utility to ping the server and run the Cypress tests after the server responds:

- uses: cypress-io/github-action@v6
  with:
    start: npm start
    wait-on: 'npx wait-on --timeout 60000 http://localhost:3000'

See example-wait-on.yml workflow file.

If this action times out waiting for the server to respond, please see Debugging section in this README file.

wait-on with Node.js 18+

Under Node.js version 18 and later, wait-on may fail to recognize that a localhost server is running. This affects development web servers which do not listen on both IPv4 and IPv6 network stacks.

  • Check your server documentation to see if it can be started using 0.0.0.0 (all addresses) and use this if available. If this option is not available or does not resolve the issue then carry on to the next steps:
  • If the action log shows that wait-on is failing to connect to 127.0.0.1, replace localhost by [::1] (the IPv6 loopback address)
  • If the action log shows that wait-on is failing to connect to ::1, replace localhost by 127.0.0.1 (the IPv4 loopback address)

Custom install command

If you want to overwrite the install command

- uses: cypress-io/github-action@v6
  with:
    install-command: yarn --frozen-lockfile --silent

See example-install-command.yml workflow file.

Command prefix

You can prefix the default test command using the command-prefix option. This is useful for example when running Percy, which requires the test command to be wrapped with percy exec --.

name: Visual
on: push
jobs:
  e2e:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          start: npm start
          # quote the url to be safe against YML parsing surprises
          wait-on: 'http://localhost:8080'
          # the entire command will automatically be prefixed with "npm"
          # and we need the second "npm" to execute "cypress run ..." command line
          command-prefix: 'percy exec -- npx'

Custom test command

You can overwrite the Cypress run command with your own command.

steps:
  - name: Checkout ๐Ÿ›Ž
    uses: actions/checkout@v4

  - name: Custom tests ๐Ÿงช
    uses: cypress-io/github-action@v6
    with:
      command: npm run e2e:ci

Caution: using the action parameter command causes multiple other parameters to be ignored including: auto-cancel-after-failures, browser, ci-build-id, command-prefix, component, config, config-file, env, group, headed, parallel, project, publish-summary, quiet, record, spec and tag.

See example-custom-command.yml file.

Custom build id

You can overwrite ci-build-id used to link separate machines running tests into a single parallel run.

name: Parallel
on: push
jobs:
  test:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        # run 3 copies of the current job in parallel
        containers: [1, 2, 3]
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          record: true
          parallel: true
          group: 'Actions example'
          ci-build-id: '${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}'
        env:
          # pass the Cypress Cloud record key as an environment variable
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Tip: see Learn GitHub Actions, with sections on Expressions, Contexts and Environment variables.

Robust custom build id

If you re-run the GitHub workflow, if you use the same custom build id during recording, Cypress Cloud will cancel the run with "Build already finished" error. To avoid this, you need to generate a new custom build id on every workflow re-run. A good solution showing in the example-custom-ci-build-id.yml file is to run a common job first that just generates a new random ID. This ID can be used by the testing jobs to tie the build together. If the user re-runs the workflow a new unique build id is generated, allowing recording the new Cypress Cloud run.

jobs:
  # single job that generates and outputs a common id
  prepare:
    outputs:
      uuid: ${{ steps.uuid.outputs.value }}
    steps:
      - name: Generate unique ID ๐Ÿ’Ž
        id: uuid
        # take the current commit + timestamp together
        # the typical value would be something like
        # "sha-5d3fe...35d3-time-1620841214"
        run: echo "value=sha-$GITHUB_SHA-time-$(date +"%s")" >> $GITHUB_OUTPUT
  smoke-tests:
    needs: ['prepare']
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          record: true
          parallel: true
          ci-build-id: ${{ needs.prepare.outputs.uuid }}
        env:
          # pass the Cypress Cloud record key as an environment variable
          CYPRESS_RECORD_KEY: ${{ secrets.EXAMPLE_RECORDING_KEY }}

See the example-custom-ci-build-id.yml for the full workflow.

Working directory

In a monorepo, the end-to-end or component test might be placed in a different sub-folder from the application itself. This sub-folder is the Cypress "working directory" which you can specify using the working-directory parameter.

In the following example of a directory layout for end-to-end testing, the Cypress working directory is app-test. The working directory contains the Cypress tests and a package manager lock file:

repo/
  app/
  app-test/
    cypress/
      e2e/
      fixtures/
      support/
    cypress.config.js
  package.json
  package-lock.json

We use working-directory: app-test to match the above example directory structure:

on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          start: npm start
          working-directory: app-test

See the Cypress documentation Folder structure section for examples of standard directory layouts, covering end-to-end testing and component testing with both JavaScript and TypeScript options.

Each of the examples in this monorepo is separated from other examples by using different working directories. See example-basic.yml for one end-to-end test example using the parameter working-directory and example-component-test.yml for a component test example.

Subfolders

Sometimes the application under test and the Cypress end-to-end tests may have separately defined dependencies. In the example below, Cypress has its own package.json file in a subfolder:

root/
  e2e/
    (code for installing and running Cypress tests)
    package.json
    package-lock.json
    cypress.config.js
    cypress/

  (code for running the "app" with "npm start")
  package.json
  package-lock.json

In this case you can first install the dependencies for the application (npm ci), then start the application server (npm start) before calling cypress-io/github-action to install the dependencies for Cypress and to run Cypress. You may also need to use the wait-on parameter to make sure that the app server is fully available.

name: E2E
on: push
jobs:
  test:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Install root dependencies
        run: npm ci

      - name: Start server in the background
        run: npm start &

      # Cypress has its own package.json in folder "e2e"
      - name: Install Cypress and run tests
        uses: cypress-io/github-action@v6
        with:
          working-directory: e2e

pnpm

The package manager pnpm is not pre-installed in GitHub Actions runner images (unlike npm and yarn) and so it must be installed in a separate workflow step (see below). If the action finds a pnpm-lock.yaml file, it uses the pnpm command pnpm install --frozen-lockfile by default to install dependencies. At this time the action does not automatically cache dependencies installed by pnpm. The example below includes steps to locate the pnpm store directory and to cache its contents for later use.

name: example-basic-pnpm
on: push
jobs:
  basic-pnpm:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install pnpm
        run: npm install -g pnpm@8
      - 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('examples/basic-pnpm/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          working-directory: examples/basic-pnpm

pnpm example

pnpm workspaces

If you are using pnpm workspaces you need to install dependencies and run Cypress tests in a workspace in separate steps. The snippet below shows this principle.

      ...
      - name: Install dependencies
        uses: cypress-io/github-action@v6
        with:
          working-directory: examples/start-and-pnpm-workspaces
          runTests: false

      - name: Cypress test
        uses: cypress-io/github-action@v6
        with:
          install: false
          working-directory: examples/start-and-pnpm-workspaces/packages/workspace-1
        ...

pnpm workspaces example

See the example project start-and-pnpm-workspaces and the example-start-and-pnpm-workspaces.yml workflow for a full working example including pnpm caching.

Yarn Classic

If a yarn.lock file is found, the action uses the Yarn 1 (Classic) command yarn --frozen-lockfile by default to install dependencies.

name: example-yarn-classic
on: push
jobs:
  yarn-classic:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          working-directory: examples/yarn-classic

Yarn classic example

Yarn Modern

To install dependencies using a yarn.lock file from Yarn Modern (Yarn 2 and later) you need to override the default Yarn 1 (Classic) installation command yarn --frozen-lockfile. You can do this by using the install-command parameter and specifying yarn install for example:

name: example-yarn-modern
on: push
jobs:
  yarn-modern:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          working-directory: examples/yarn-modern
          install-command: yarn install

This example covers the .yarnrc.yml configuration nodeLinker: node-modules which Yarn uses by default for projects updated from Yarn Classic. For nodeLinker: pnp see Yarn Plug'n'Play below. (Note that github-action is not compatible with the nodeLinker: pnpm setting.)

Yarn Modern example

Yarn Plug'n'Play

When using Yarn Modern (Yarn 2 and later) with Plug'n'Play enabled, you will need to use the command parameter to run yarn instead of npx.

name: example-yarn-modern-pnp
on: push
jobs:
  yarn-classic:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          working-directory: examples/yarn-modern-pnp
          install-command: yarn install
          command: yarn run --binaries-only cypress run

This example covers the .yarnrc.yml configuration when nodeLinker is undefined or set to nodeLinker: pnp corresponding to Yarn Plug'n'Play. Yarn uses this by default for projects newly created with Yarn Modern.

Yarn Plug'n'Play example

Caution: using the action parameter command causes multiple other parameters to be ignored. See command section for more information.

Yarn workspaces

This action should discover the Yarn workspaces correctly. For example, see folder examples/start-and-yarn-workspaces and workflow file example-start-and-yarn-workspaces.yml

name: example-start-and-yarn-workspaces
on: push
jobs:
  single:
    # the example has Yarn workspace in its "root" folder
    # examples/start-and-yarn-workspaces
    # and tests in a subfolder like "workspace-1"
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        with:
          working-directory: examples/start-and-yarn-workspaces/workspace-1
          build: yarn run build
          start: yarn start
          wait-on: 'http://localhost:5000'

Yarn workspaces example

Custom cache key

Sometimes the default cache key does not work. For example, if you cannot share the Node modules across Node versions due to native extensions. In that case pass your own cache-key parameter.

name: End-to-end tests
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    # let's make sure our "app" works on several versions of Node
    strategy:
      matrix:
        node: [18, 20, 21]
    name: E2E on Node v${{ matrix.node }}
    steps:
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - name: Checkout
        uses: actions/checkout@v4
      # run Cypress tests and record them under the same run
      # associated with commit SHA and just give a different group name
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          record: true
          group: Tests on Node v${{ matrix.node }}
          cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('yarn.lock') }}
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Node versions

You can run your tests across multiple Node versions.

name: Node versions
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        node: [18, 20, 21]
    name: E2E on Node v${{ matrix.node }}
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6

See the Node.js section for information about supported versions and usage of Node.js.

Node versions example

Split install and tests

Sometimes you may want to run additional commands between installation and tests. To enable this use the install and runTests parameters.

name: E2E
on: push
jobs:
  test:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        uses: cypress-io/github-action@v6
        with:
          # just perform install
          runTests: false
      - run: yarn lint
      - name: Run e2e tests
        uses: cypress-io/github-action@v6
        with:
          # we have already installed all dependencies above
          install: false
          # Cypress tests and config file are in "e2e" folder
          working-directory: e2e

See cypress-gh-action-monorepo for a working example.

Custom install

Finally, you might not need this GH Action at all. For example, if you want to split the npm dependencies installation from the Cypress binary installation, then it makes no sense to use this action. Instead you can install and cache Cypress yourself.

Install Cypress only

If the project has many dependencies, but you want to install just Cypress you can combine this action with actions/cache and npm i cypress commands yourself.

- uses: actions/checkout@v4
- uses: actions/cache@v4
  with:
    path: |
      ~/.cache/Cypress
      node_modules
    key: my-cache-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- run: npm i cypress
- uses: cypress-io/github-action@v6
  with:
    install: false

Install only Cypress example

Timeouts

You can tell the CI to stop the job or the individual step if it runs for longer then a given time limit. This is a good practice to ensure the hanging process does not accidentally use up all your CI minutes.

jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    # stop the job if it runs over 10 minutes
    # to prevent a hanging process from using all your CI minutes
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v4
      - uses: cypress-io/github-action@v6
        # you can specify individual step timeout too
        timeout-minutes: 5

More examples

Name Description
cypress-io/cypress-example-kitchensink Runs every API command in Cypress using various CI platforms including GitHub Actions
cypress-io/cypress-realworld-app A real-world example payment application. Uses GitHub Actions and CircleCI.
cypress-gh-action-monorepo Splits install and running tests commands, runs Cypress from sub-folder
cypress-examples Shows separate install job from parallel test jobs
cypress-gh-action-split-jobs Shows a separate install job with the build step, and another job that runs the tests

Notes

Installation

This action installs local dependencies using lock files. Ensure that exactly one type of lock file is used for each project or working-directory from the following supported package managers:

Lock file Package Manager Installation command
package-lock.json npm npm ci
pnpm-lock.yaml pnpm pnpm install --frozen-lockfile
yarn.lock Yarn Classic yarn --frozen-lockfile

See section Yarn Modern for information about using Yarn version 2 and later.

Debugging

This action uses the debug module to output additional verbose logs. You can see these debug messages by setting the following environment variable:

DEBUG: @cypress/github-action

You can set the environment variable using GitHub UI interface, or in the workflow file:

- name: Cypress tests with debug logs
  uses: cypress-io/github-action@v6
  env:
    DEBUG: '@cypress/github-action'

See the example-debug.yml workflow file.

To collect more verbose GitHub Action logs you can set a GitHub secret or variable ACTIONS_STEP_DEBUG to true. This is useful to see detailed caching steps. See Enabling debug logging from GitHub Actions documentation for more information.

Logs from the test runner

To see the Cypress debug logs add an environment variable to the action:

- name: Cypress tests with debug logs
  uses: cypress-io/github-action@v6
  env:
    DEBUG: 'cypress:*'

Debugging waiting for URL to respond

If you have a problem with wait-on not working, you can check the src/ping.js logic from the local machine.

  • clone this repository to the local machine
  • install dependencies with npm install
  • start your server
  • from another terminal call the ping yourself to validate the server is responding:
$ node src/ping-cli.js <url>

For example

$ node src/ping-cli.js https://example.cypress.io
pinging url https://example.cypress.io for 30 seconds
::debug::pinging https://example.cypress.io has finished ok

More information

Extras

Manual trigger

If you add workflow_dispatch event to your workflow, you will be able to start the workflow by clicking a button on the GitHub page, see the Test External Site Using GitHub Actions video.

Outputs

This action sets a GitHub step output resultsUrl if the run was recorded on Cypress Cloud using the action parameter setting record: true (see Record test results on Cypress Cloud). Note that using a Custom test command with the command parameter overrides the record parameter and in this case no resultsUrl step output is saved.

This is an example of using the step output resultsUrl:

- name: Cypress tests
  uses: cypress-io/github-action@v6
  # let's give this action an ID so we can refer
  # to its output values later
  id: cypress
  with:
    record: true
  env:
    CYPRESS_RECORD_KEY: ${{ secrets.RECORDING_KEY }}
- name: Print Cypress Cloud URL
  if: always()
  run: |
    echo Cypress finished with: ${{ steps.cypress.outcome }}
    echo See results at ${{ steps.cypress.outputs.resultsUrl }}

The GitHub step output dashboardUrl is deprecated. Cypress Dashboard is now Cypress Cloud.

recording example

Note: every GitHub workflow step can have outcome and conclusion properties. See the GitHub Contexts documentation section steps context. In particular, the outcome or conclusion value can be success, failure, cancelled, or skipped which you can use in any following steps.

Print Cypress info

Sometimes you might want to print Cypress and OS information, like the list of detected browsers. You can use the cypress info command for this.

If you are NOT using the build command in your project, you can run the cypress info command:

name: info
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          build: npx cypress info

If you are already using the build parameter, you can split the installation and the test steps and insert the cypress info command in between:

name: info
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress install
        uses: cypress-io/github-action@v6
        with:
          # just perform install
          runTests: false
      - name: Cypress info
        run: npx cypress info
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          # we have already installed all dependencies above
          install: false
          # rest of your parameters

Nightly tests

Sometimes you want to execute the workflow on a schedule. For example, to run Cypress tests nightly, you can schedule the workflow using cron syntax:

name: example-cron
on:
  schedule:
    # runs tests every day at 4am
    - cron: '0 4 * * *'
jobs:
  nightly:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress nightly tests ๐ŸŒƒ
        uses: cypress-io/github-action@v6

cron example

Job summary title

By default, the action produces a job summary in the GitHub Actions log for each workflow step where github-action is used. Each job summary shows a Passing / Failing status, the test counts for Passed, Failed, Pending & Skipped, followed by the Duration of the run. The job summaries are grouped by job.

To specify a title for a Job Summary, use the parameter summary-title. If no title is specified, then the default "Cypress Results" is used:

name: Summary titles
on: push
jobs:
  tests:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
      - name: Cypress headless tests
        uses: cypress-io/github-action@v6
        with:
          summary-title: 'Headless'
      - name: Cypress headed tests
        uses: cypress-io/github-action@v6
        with:
          install: false
          headed: true
          summary-title: 'Headed'

The name of the GitHub Actions job is shown at the top of one or more job summaries from the same job. If multiple summaries belong to the same job, then giving them separate titles allows them to be uniquely identified.

See the example-chrome.yml workflow, with multiple calls to cypress-io/github-action in one job, making use of the summary-title parameter. View the example-chrome.yml - actions log for an example of the resulting job summaries.

Suppress job summary

The default job summary can be suppressed by using the parameter publish-summary and setting its value to false.

name: Example no summary
on: push
jobs:
  cypress-run:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Cypress run
        uses: cypress-io/github-action@v6
        with:
          publish-summary: false

Node.js

Support

Node.js is required to run this action. The recommended version v6 supports:

  • Node.js 18.x
  • Node.js 20.x and above

and is generally aligned with Node.js's release schedule.

Usage

github-action command-type options such as install-command, build, start and command are executed with the runner's version of Node.js. You can use GitHub's actions/setup-node to install an explicit Node.js version into the runner.

Node versions example

Cypress itself runs with a fixed Node.js version specified by the runs.using parameter of action.yml. github-action@v6 uses node20.

Changelog

View the CHANGELOG document for an overview of version changes.

Compatibility

  • github-action@v6 is the current recommended version and uses node20
  • github-action versions v1 to v5 are unsupported: they rely on Node.js 12 and 16 in End-of-life status.

Contributing

Please see our Contributing Guideline which explains how to contribute fixes or features to the repo and how to test.

License

license

This project is licensed under the terms of the MIT license.

github-action's People

Contributors

admah avatar bahmutov avatar conversayshawn avatar dlgshi avatar emilyrohrbough avatar emmenko avatar estrada9166 avatar jaffrepaul avatar jdborneman-terminus avatar jennifer-shehane avatar karlhorky avatar kocal avatar lukaw3d avatar martijnhols avatar mattvollmer avatar mikemcc399 avatar nihalgonsalves avatar philipparndt avatar piotrekkr avatar prescottprue avatar quisido avatar renovate-bot avatar renovate[bot] avatar robertguss avatar sergiubcn avatar soldierboy31 avatar ssong avatar uzaeirazhar avatar v-dimitroff avatar yakkomajuri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

github-action's Issues

wait-on times out, even tough app is ready

First of all: It's awesome to see how much effort the Cypress team invests into creating examples and bindings for all kinds of tools and services. Thank you.

Now for the issue: I have an app with the following configuration:

cypress-run:
  runs-on: ubuntu-latest
  steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Cypress run
      uses: cypress-io/github-action@v1
      with:
        start: yarn run parcel src/index.html
        wait-on: http://localhost:1234

Full configuration: https://github.com/rbuetzer/kinder/blob/4e3ce07bf651ab5f8f9edcdeda0666d7c93c67da/.github/workflows/run-tests.yml

Observed behaviour:

wait-on times out after 60 seconds, even tough the app is ready after <30 seconds.

starting server with command "yarn run parcel src/index.html"
current working directory "/home/runner/work/kinder/kinder"
/usr/bin/yarn run parcel src/index.html
waiting on "http://localhost:1234" with timeout of 60 seconds
/usr/local/bin/npx wait-on --timeout 60000 "http://localhost:1234"
yarn run v1.19.1
$ /home/runner/work/kinder/kinder/node_modules/.bin/parcel src/index.html
Server running at http://localhost:1234 
โœจ  Built in 22.57s.
Error: Timeout
    at Timeout._onTimeout (/home/runner/.npm/_npx/2839/lib/node_modules/wait-on/lib/wait-on.js:113:10)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

Full log: https://github.com/rbuetzer/kinder/runs/316750720

Expected behaviour

wait-on does not time out.

Analysis

Edit: Ignore the analysis below. Turns out the & variant does not work on GH pages. See #41 (comment)

If I use wait-on with a background process instead of using the configuration, the test runs successfully.

start: yarn run parcel src/index.html & npx wait-on http://localhost:1234

Full configuration: https://github.com/rbuetzer/kinder/blob/13e239b1f055fd1e7b222f0697343d0510679085/.github/workflows/run-tests.yml

Successful run: https://github.com/rbuetzer/kinder/runs/316749597

App version which has the issue:
https://github.com/rbuetzer/kinder/tree/4e3ce07bf651ab5f8f9edcdeda0666d7c93c67da

App version which does not have the issue:
https://github.com/rbuetzer/kinder/tree/13e239b1f055fd1e7b222f0697343d0510679085

Diff between the two:
https://github.com/rbuetzer/kinder/compare/4e3ce07bf651ab5f8f9edcdeda0666d7c93c67da..13e239b1f055fd1e7b222f0697343d0510679085

Feature request, add verbose flag to wait option

The current wait implementation adds a log of log statements, like the following waiting on an angular dev server:

16043 ms GET localhost:4200 ECONNREFUSED
17045 ms GET localhost:4200 ECONNREFUSED
18047 ms GET localhost:4200 ECONNREFUSED
19048 ms GET localhost:4200 ECONNREFUSED
20051 ms GET localhost:4200 ECONNREFUSED
21053 ms GET localhost:4200 ECONNREFUSED
22056 ms GET localhost:4200 ECONNREFUSED
23058 ms GET localhost:4200 ECONNREFUSED
24060 ms GET localhost:4200 ECONNREFUSED
25063 ms GET localhost:4200 ECONNREFUSED
26064 ms GET localhost:4200 ECONNREFUSED

Would be epic if we could toggle this ๐Ÿ˜‡

Start command does not work on Windows

start: npm start does not work on windows :(

starting server with command "npm start"
current working directory "d:\a\cypress-example-kitchensink\cypress-example-kitchensink"
child process unref
Running Cypress tests
Cypress test command: npx cypress run --record --parallel --ci-build-id "Using Cypress GH Action - 52315829bed30d850a34a2d775c9a3400a93bff3" --group "Parallel 2x on windows-latest"
C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npx.cmd" cypress run --record --parallel --ci-build-id """Using Cypress GH Action - 52315829bed30d850a34a2d775c9a3400a93bff3""" --group """Parallel 2x on windows-latest""""
(node:2276) UnhandledPromiseRejectionWarning: Error: spawn npm start ENOENT
    at notFoundError (d:\a\_actions\cypress-io\github-action\22f7a76\dist\index.js:6400:26)
    at verifyENOENT (d:\a\_actions\cypress-io\github-action\22f7a76\dist\index.js:6434:16)
    at ChildProcess.cp.emit (d:\a\_actions\cypress-io\github-action\22f7a76\dist\index.js:6421:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
(node:2276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2276) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

start command failure does not exit if wait_on is provided

My start command is failing due to unrelated issues, but since I provide a wait_on the github action waits indefinitely. After seeing it run for over an hour, I manually quit the action, then I was able to see the logs explaining why the startcommand failed.

Not sure how possible it is, but if we could exit the action if the start command fails/exits regardless of whether the wait_on is set. It could be really helpful for folks to debug issues with starting up the dev server like what I am experiencing.

Need Help, Error when run test

/usr/local/bin/npx cypress run --config-file cypress.json --env false

Error: There was an error when attempting to execute the process '/usr/local/bin/npx'. This may indicate the process failed to start. Error: spawn /usr/local/bin/npx ENOENT
    at ExecState._setResult (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:891:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:877:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:764:27)
    at ChildProcess.emit (events.js:200:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)
##[error]There was an error when attempting to execute the process '/usr/local/bin/npx'. This may indicate the process failed to start. Error: spawn /usr/local/bin/npx ENOENT
##[error]Node run failed with exit code 1```

Upgrade to latest actions/cache

Please consider upgrading to the latest version of actions/cache, specifically v1.1.0. This version increases the upload cap (400 MBs -> 2 GBs) and also parallelizes the upload to reduce upload time.

Option to override ci-build-id

Would be awesome for us to be able to override the ci-build-id. Right now when using either -record or -parallel, it is set for us as ${GITHUB_WORKFLOW} - ${GITHUB_SHA}

Should we include checkout step?

Right now we check out code using

- name: Checkout
  uses: actions/checkout@v1
# the rest of the steps

Can we include the checkout step ourselves by default?

Add support for Percy visual testing

We just switched to using the Cypress GitHub Action as opposed to setting it up and running it manually in our workflow. We are now looking to integrate visual testing into our Cypress E2E tests using Percy โ€“ย https://docs.percy.io/docs/cypress.

The Cypress GitHub Action runs cypress run while Percy requires percy exec -- cypress run and so Percy currently won't work with this.

Action does not work out of the box without a package.json file

Example output:

Run cypress-io/github-action@v1
  with:
    wait-on: http://localhost:5050
    spec: tests/initual-setup.js
    record: false
    config-file: cypress.json
    env: false
internal/fs/utils.js:220
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/home/runner/work/polaris-web/polaris-web/package-lock.json'
    at Object.openSync (fs.js:440:3)
    at Object.readFileSync (fs.js:342:35)
    at Function.module.exports.309.hasha.fromFileSync (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:4486:54)
    at lockHash (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:2467:16)
    at getNpmCache (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:2475:16)
    at restoreCachedNpm (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:2518:21)
    at installMaybe (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:2816:5)
    at Object.104 (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:2837:1)
    at __webpack_require__ (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:22:30)
    at startup (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:37:19) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/runner/work/polaris-web/polaris-web/package-lock.json'
}

From https://github.com/agersant/polaris-web/commit/dcaf31ed3339aa6b49afb54e96e0ee790304744b/checks?check_suite_id=396158425

Poor browser performance when viewing logs in Github Actions

Hello,

When viewing logs inside Github Actions for cypress, the page is very slow/unresponsive; (scrolling is lagging or freeze the scrolls for few secs)

Also, it's not related to you, but when having Github Refined extension, the tab is completely frozen/crashed (refined-github/refined-github#2725).

Is this due to the huge "output log" that cypress generate ? or something else ?

Is there anything you can improve so the browser is not slowed down ?

environment:

  • Chrome (v79.0.3945.130)
  • Macbook Pro 2019
  • 2,3Ghz Intel core i9
  • 32Go RAM

upgrade_JS_deps_by_tristanbes_ยทPull_Request__794ยท_Yproximite_condictio

Can't run 'start' in background

Hi!

I'm using this action as follows:

name: Tests
on: push
jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: docker://cypress/browsers:chrome69

      - name: Checkout
        uses: actions/checkout@v1

      - name: Install dependencies
        run: yarn install && cd e2e && yarn install

      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          start: yarn start
          wait-on: http-get://localhost:4200

And this is my folder structure (Angular project):

image

Cypress is separated into it's own package to avoid conflicts with TypeScript.

The issue is that yarn start never passes away to cypress run, running infinitely. Also, I have a doubt that this action would work with my different cypress setup?

In my root package.json:
"cypress:run": "cd e2e && yarn cypress:run",

In e2e/package.json:
"cypress:run": "cypress run --browser chrome"

Thanks in advance!

Dashboard state not updating

In the following cases the dashboard remains in the "running" state (as if it was never notified):

  • If a test fails the action run fails
  • As mentioned in #36 - Quitting a Github Action run while it is running

This results in test runs being indicated as taking 2+ hours within the dashboard even when the Github Action itself is done in less than 10 minutes (it shuts off due to the cypress command shutting down due to the failed test)

Input for specifying browser

Couldn't find a way to specify which browser is used.

It would be nice if there was an input for selecting which browser to use for tests, but anyway of setting it at all should be fine initially.

Thanks!

Provide option to upload videos/screenshots as Artifacts

Hello! This is rad, I'm excited to try it out! One thing I've played with in my own usage of Cypress + Actions is uploading the generated videos/screenshots as Artifacts, using actions/upload-artifact.

# Run the e2e tests (cypress run)
- run: npm run test:e2e
- uses: actions/upload-artifact@v1
  with:
    name: cypress-videos
    path: cypress/videos

This works great as-is, but when a step fails it doesn't move on to the next step, which would be uploading those videos. Workflows can leverage continue-on-error, but it gets weird pretty quickly (you need to capture the exit code to ensure a failed test run causes a failed Actions run).

This action looks like it would have more control over when/how the step exits, so it could make for a great addition!

Cypress get long time after run on CI

I have 2 file test and script below

// API
describe('Group of test', function() {
  it('api test', function() {
    cy.getTodos()
  })
})
// frontend
describe('Group of test', function() {
  before(function() {
    cy.log('run me on 1 time at all test start')
  })
  after(function() {
    cy.log('run me on 1 time at all test end')
  })
  beforeEach(function() {
    cy.log('run me always time at it is run')
  })
  afterEach(function() {
    cy.log('run me always time at it is run end')
  })
  context('Sub group of test', function() {
    it('test case 1', function() {
      cy.visit('/')
    })
    it('test case 2', function() {
      cy.visit('/')
    })
  })
})

The first file is passed but the second file isn't run. Can you help me ?
Can see my repo at repo

Adding both `working-directory` and `start` does not work.

We have a monorepo containing many repos, therefore we use the working-directory directive in many of our GitHub Actions.

This did not work:

      - name: Run integration tests with cypress.
        uses: cypress-io/github-action@master
        with:
          start: npm ./web run dev
          wait-on: http://localhost:8000
          working-directory: ./web

and errored like:

/usr/local/bin/npm run dev
waiting on "http://localhost:8000" with timeout of 60 seconds
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/codebase/codebase/package.json
npm ERR! errno -2

but this did:

      - name: Run integration tests with cypress.
        uses: cypress-io/github-action@master
        with:
          start: npm --prefix ./web run dev
          wait-on: http://localhost:8000
          working-directory: ./web

note the --prefix command to specify the same directory as the working-directory command.

Do we have input for the "spec" argument?

// example
      - uses: cypress-io/github-action@v1
        with:
          spec: cypress/integration/custom/**/*.custom.spec.js

or

// example
      - uses: cypress-io/github-action@v1
        with:
          args: --spec cypress/integration/custom/**/*.custom.spec.js

Cypress tests never starts with wait-on

I am trying to setup this action with a simple Angular + Nodejs server, but I am stuck. No tests actually starts. This might be a possible duplicate of #41

- name: Run e2e tests
  uses: cypress-io/github-action@v1
  with:
    # we have already installed all dependencies above
    install: false
    start: npm run -s start:test & npm run -s start:test --prefix aveiro-server
    wait-on: http-get://localhost:4200/
    config-file: cypress.json
    wait-on-timeout: 180

But the wait-on property does not seem to work when executing on Github. When I look at the logs, I can confirm that both the server and angular is serving - but nothing happens. Then after 180 seconds the job times out.

The weird thing is that if i on localhost do npm run -s start:test & npm run -s start:test --prefix aveiro-server and in another window wait-on http-get://localhost:4200/ && echo Ready! everything works as expected - after the server and angular is up and running, I see "Ready!" in the other console window.

Any help is very welcome.

Angular + Node.js fails without any output

After trying out Cypress on Github actions some months ago, we have today decided to switch from Circle CI to github actions and cypress dashboard.

But now the github actions does not work ๐Ÿคท๐Ÿพโ€โ™‚๏ธ

We have a simple Angular + Nodejs server setup, with the server in a folder called aveiro-server, and the angular app in the root. The relevant part of the yml file thus contains this:

jobs:
  cypress-run:
    runs-on: ubuntu-16.04
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Install aveiro dependencies
        uses: bahmutov/npm-install@v1
        with:
          working-directory: ./aveiro-server
      - name: Install & run e2e tests
        uses: cypress-io/github-action@v1
        with:
          browser: chrome
          headless: true
          record: true # Record results to cypress dashboard
          start: npm run -s serve:test & npm run -s start:test --prefix aveiro-server
          wait-on: 'http://localhost:4200'
          config-file: cypress.json
          wait-on-timeout: 180

When the above runs, it fails right after the npm run -s serve:test & npm run -s start:test --prefix aveiro-server commands. I tried running it on my local machine, and here it works with no problems.

The only thing I get from the logs is something about an UnhandledPromiseRejectionWarning.

Here is the relevant logs:

Screenshot 2020-01-24 at 08 50 31

different cypress package.json in e2e/

hi,

our folder structure is slightly different. we outsourced cypress to e2e/

repo/
  app/
  e2e/
    cypress
    cypress.json
    package.json <- (e2e is a seperate package)
  package.json

is there a solution to handle this?

Action immediately errors out

Hello!
I've been happily using the Cypress github actions for a few days and it has stopped working all of a sudden, with no changes in my CI setup.

Runs immediately fail with:
image

Example failed run: https://github.com/agersant/polaris-web/runs/404434946 (I re-ran it several times to rule out flukes)
Previous successful run: https://github.com/agersant/polaris-web/commit/7d3972d617c088d2189cddfc28a6761b743c23f3/checks?check_suite_id=408103643

Is this an issue with the action or with Github actions in general? Many thanks in advance!

Cypress Start and Build inputs should resolve to working directory

I'm unable to run this action because my server is started in a working directory because it is in a mono repo.

I've noticed this line hinting at those commands running under the working directory.

Is there a current workaround for starting a server that is not in the root directory?

Fails to find cypress.json on windows-latest

With the config below, my tests run successfully on ubuntu-latest and macos-latest, but fail on windows latest with this message

Could not find a Cypress configuration file, exiting.
466

467
We looked but did not find a "cypress.json" file in this folder: d:\a\repo\repo
468
Error: The process 'C:\Program Files\nodejs\npx.cmd' failed with exit code 1
469
    at ExecState._setResult (d:\a\_actions\cypress-io\github-action\v1\dist\index.js:894:25)
470
    at ExecState.CheckComplete (d:\a\_actions\cypress-io\github-action\v1\dist\index.js:877:18)
471
    at ChildProcess.<anonymous> (d:\a\_actions\cypress-io\github-action\v1\dist\index.js:777:27)
472
    at ChildProcess.emit (events.js:210:5)
473
    at maybeClose (internal/child_process.js:1021:16)
474
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
475
##[error]The process 'C:\Program Files\nodejs\npx.cmd' failed with exit code 1
476
##[error]Node run failed with exit code 1
name: Cypress Tests
on: [push]
jobs:
  cypress-run:
    strategy:
      matrix:
        platform: [ubuntu-latest, macos-latest, windows-latest]
        machines: [1, 2] # Add items to this list to increase parallelism.
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Cypress run
        uses: cypress-io/github-action@v1
        with:
          record: true
          parallel: true
          group: ${{ matrix.platform }}
          start: $START_COMMAND
          wait-on: http://$HOST:$PORT
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}

Any idea what's wrong? Got the same result when using actions/checkout@v1 as well.

Cannot run on default Cypress E2E Vue project

I am trying to set up a CI workflow for a Vue project using this Action. I am able to run the cypress commands manually and directly in the GitHub workflow without issue, but this Action fails to resolve the necessary dependencies for a Vue project due to its caching behavior.

First, I can run cypress with the following workflow steps:

# https://github.com/actions/cache/blob/master/examples.md#node---npm
- name: Cache Dependencies
  uses: actions/cache@v1
  id: cache
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-

- name: Install and Build
  run: |
    npm ci
    npm run build --if-present
  env:
    CI: true
#...
- name: Cypress E2E Test
  run: |
    npm run serve &
    PID=`echo $!`
    npx cypress run
    kill -9 $PID
  env:
    CI: true
    NODE_ENV: production
    CYPRESS_baseUrl: http://localhost:8080/

Successful result:
image

Explanation of the parameters:

Creating a default project with the Vue CLI sets up Cypress at certain defaults. npm run serve triggers the command vue-cli-service serve. I am not sure what vue-cli-service command ends up running (it adds several things to the command line beyond the vue serve).

To run E2E tests, Vue creates a vue run test:e2e command that triggers vue-cli-service e2e. I am not sure the full changes this command makes to the command line, but it at least sets the CYPRESS_baseUrl environment variable based on what port that e2e command successfully launches the local Vue server. NODE_ENV=production is used to trigger prod optimizations in the serve command.

Attempting with this Action:

- name: Cypress E2E Test
  uses: cypress-io/github-action@v1
  with:
    start: npm run serve
    wait-on: http://localhost:8080/
    browser: ${{ matrix.browser }}
    config_file: cypress.json
    spec: "tests/e2e/**/*"
  env:
    CYPRESS_baseUrl: http://localhost:8080/
    CI: true
    # For E2E testing
    NODE_ENV: production

The config_file and spec may not be needed. I am not sure because this fails with the below error:

restoring cache /home/runner/.npm
primary key npm-linux-x64-08664ecdc08feabb2c70ddb0bb5e9cf01740547f7e1be85204da6a61a375a7114e8bedeb70bb98b0693188508010712f0fc80afc8468f8191a57ef90f1a1adc6
restoring cache /home/runner/.cache/Cypress
primary key cypress-linux-x64-08664ecdc08feabb2c70ddb0bb5e9cf01740547f7e1be85204da6a61a375a7114e8bedeb70bb98b0693188508010712f0fc80afc8468f8191a57ef90f1a1adc6
/bin/tar -xz -f /home/runner/work/_temp/0eeda399-804e-4102-b9bb-6116542e0157/cache.tgz -C /home/runner/.npm
/bin/tar -xz -f /home/runner/work/_temp/c4b055c6-1e34-4c92-b9bd-38833f856062/cache.tgz -C /home/runner/.cache/Cypress
Cache restored from key: npm-linux-x64-08664ecdc08feabb2c70ddb0bb5e9cf01740547f7e1be85204da6a61a375a7114e8bedeb70bb98b0693188508010712f0fc80afc8468f8191a57ef90f1a1adc6
Cache restored from key: cypress-linux-x64-08664ecdc08feabb2c70ddb0bb5e9cf01740547f7e1be85204da6a61a375a7114e8bedeb70bb98b0693188508010712f0fc80afc8468f8191a57ef90f1a1adc6
/opt/hostedtoolcache/node/12.14.0/x64/bin/npm ci
npm WARN prepare removing existing node_modules/ before installation

> [email protected] postinstall /home/runner/work/proj/proj/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

added 64 packages in 10.417s
starting server with command "npm run serve"
current working directory "/home/runner/work/proj/proj"
/opt/hostedtoolcache/node/12.14.0/x64/bin/npm run serve
waiting on "http://localhost:8080/" with timeout of 60 seconds
6 ms GET localhost:8080 ECONNREFUSED

> [email protected] serve /home/runner/work/proj/proj
> vue-cli-service serve

sh: 1: vue-cli-service: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] serve: `vue-cli-service serve`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-01-04T04_58_34_563Z-debug.log
(node:3196) UnhandledPromiseRejectionWarning: Error: The process '/opt/hostedtoolcache/node/12.14.0/x64/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:894:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:877:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/cypress-io/github-action/v1/dist/index.js:777:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:3196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3196) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I am not sure why this is failing. I see this Action running npm ci, just as I am. I see that completes successfully, which should place vue-cli-service in the node_modules folder. However, for some reason that is not the case.

Since Cypress is one of the 2 default options for E2E testing in Vue, this Action should probably be able to support the default project construction provided by @vue/cli. As it stands currently that does not appear to be the case.

As a side note, because Cypress is one of the default Vue E2E testing options, it may be beneficial to add a note to the README regarding the necessity of adding the CYPRESS_baseUrl environment variable to get this action working with npm run serve in a Vue project.

Specify node version

Even when using the node setup action before this action, node 12.13 is still being used:

    - name: Setup Node
      uses: actions/setup-node@v1
      with:
        node-version: 10

    - name: Cypress Run
      uses: cypress-io/github-action@v1
      with:
        record: true
      env:
        # pass the Dashboard record key as an environment variable
        CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_KEY }}

The error that includes node version:

image

Is there a way to set node version that I am missing? If not, it would awesome if this was an input

Improve Cypress Dashboard Support

There are a few things happening when using with Cypress Dashboard:

  1. Commit message is not showing, instead a somewhat unclear of merge info is included even though no merge is going on (see picture below)
  2. The branch name doesn't show at all (usually above the commit message)
  3. The environment shows up as "Unknown". For Gitlab it shows "Gitlab #123" the number being the build number. Maybe for this it could be a link to the action run? (see picture below)
  4. Quitting a Github Action run while it is running test leaves the run in the dashboard in the "running" state (as if the dashboard was never notified about the cancel)

image

Not sure if this is the right code base for the changes, but wanted to get it reported

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.