name: E2E Tests

on: [pull_request]

env:
  GITHUB_PR_NUMBER: ${{github.event.pull_request.number}}

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  functional:
    name: Functional
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.37.0-jammy
    steps:
      - uses: actions/checkout@v3
      - name: Set up environment
        uses: ./.github/actions/setup
      - name: Wait for Netlify build to finish
        id: netlify
        env:
          COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: ./.github/actions/netlify-wait-for-build
      - name: Run E2E Tests on Netlify URL
        run: yarn e2e
        env:
          E2E_START_URL: ${{ steps.netlify.outputs.url }}
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: desktop-client-test-results
          path: packages/desktop-client/test-results/
          retention-days: 30
  vrt:
    name: Visual regression
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.37.0-jammy
    steps:
      - uses: actions/checkout@v3
      - name: Set up environment
        uses: ./.github/actions/setup
      - name: Wait for Netlify build to finish
        id: netlify
        env:
          COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: ./.github/actions/netlify-wait-for-build
      - name: Run VRT Tests on Netlify URL
        run: yarn vrt
        env:
          E2E_START_URL: ${{ steps.netlify.outputs.url }}
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: desktop-client-test-results
          path: packages/desktop-client/test-results/
          retention-days: 30
