name: Cypress Tests

on:
  workflow_dispatch:
  push:
    branches: ['main', 'next']
  pull_request:
    branches: ['main', 'next']

jobs:
  cypress-run:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false # https://github.com/cypress-io/github-action/issues/48
      matrix:
        containers: [1, 2] # Uses 2 parallel instances

    steps:
      - uses: actions/checkout@v3

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          cache: yarn
          cache-dependency-path: |
            yarn.lock
            packages/app/yarn.lock
            packages/core/yarn.lock
            packages/docs/yarn.lock
          node-version: 18

      - name: Install
        run: |
          yarn install --frozen-lockfile

      - name: Run Cypress Tests
        uses: cypress-io/github-action@v6
        with:
          start: yarn dev
          wait-on: 'http://localhost:8080'
          record: true # Records to Cypress Cloud
          parallel: true # Runs test in parallel using settings above
        env:
          # For recording and parallelization to work you must set your CYPRESS_RECORD_KEY
          # in GitHub repo → Settings → Secrets → Actions
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          # Creating a token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
          GITHUB_TOKEN: ${{ secrets.CYPRESS_GITHUB_TOKEN }}