name: Cypress Tests

on:
  push:
    branches:
      - master
  pull_request:
jobs:
  cypress:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        containers: [1, 2, 3, 4, 5]
        os: ["ubuntu-latest"]
        browser: [chrome]
    name: E2E tests on ${{ matrix.browser }} - ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: 16.10.0
          cache: 'npm'
          cache-dependency-path: frontend/package-lock.json
      - name: ${{ matrix.browser }} browser tests (Mempool)
        uses: cypress-io/github-action@v2
        with:
          tag: ${{ github.event_name }}
          working-directory: frontend
          build: npm run config:defaults:mempool
          start: npm run start:local-staging
          wait-on: 'http://localhost:4200'
          wait-on-timeout: 120
          record: true
          parallel: true
          spec: |
            cypress/integration/mainnet/*.spec.ts
            cypress/integration/signet/*.spec.ts
            cypress/integration/testnet/*.spec.ts
          group: Tests on ${{ matrix.browser }} (Mempool)
          browser: ${{ matrix.browser }}
          ci-build-id: '${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}'
        env:
          COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}

      - name: ${{ matrix.browser }} browser tests (Liquid)
        uses: cypress-io/github-action@v2
        if: always()
        with:
          tag: ${{ github.event_name }}
          working-directory: frontend
          build: npm run config:defaults:liquid
          start: npm run start:local-staging
          wait-on: 'http://localhost:4200'
          wait-on-timeout: 120
          record: true
          parallel: true
          spec: |
            cypress/integration/liquid/liquid.spec.ts
            cypress/integration/liquidtestnet/liquidtestnet.spec.ts
          group: Tests on ${{ matrix.browser }} (Liquid)
          browser: ${{ matrix.browser }}
          ci-build-id: '${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}'
        env:
          COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}

      - name: ${{ matrix.browser }} browser tests (Bisq)
        uses: cypress-io/github-action@v2
        if: always()
        with:
          tag: ${{ github.event_name }}
          working-directory: frontend
          build: npm run config:defaults:bisq
          start: npm run start:local-staging
          wait-on: 'http://localhost:4200'
          wait-on-timeout: 120
          record: true
          parallel: true
          spec: cypress/integration/bisq/bisq.spec.ts
          group: Tests on ${{ matrix.browser }} (Bisq)
          browser: ${{ matrix.browser }}
          ci-build-id: '${{ github.sha }}-${{ github.workflow }}-${{ github.event_name }}'
        env:
          COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
