name: Regression test
on:
  push:
    branches: [ main]
  pull_request:
    branches: [ main ]

  workflow_dispatch:
    inputs:
      desc:
        description: 'Description'
        required: false
        default: 'Manual regression test'
      dd_env:
        type: choice
        description: 'CI environment'
        required: true
        default: 'integration'
        options:
        - 'integration'
        - 'staging'
        - 'production'
      use_ci_reporter:
        type: choice
        description: 'Use CI Reporter'
        required: true
        default: 'false'
        options:
        - 'true'
        - 'false'
      dss_graphql_url:
        description: 'Set Dss GraphQL Url'
        required: true
        default: 'https://integration.datasense.pgdss.com/api/pgds-platform/graphql'
      dss_web_url:
        description: 'Set Dss Web Url'
        required: true
        default: 'https://integration.datasense.pgdss.com'

jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    env:
      DD_SERVICE: 'pgds-vantage-plus-web'
      DD_CIVISIBILITY_AGENTLESS_ENABLED: 'true'
      DD_API_KEY: ${{ secrets.DD_API_KEY }}
      DD_ENV: ${{ github.event.inputs.dd_env || 'integration' }}
      LOGIN_EMAIL: ${{ secrets.LOGIN_EMAIL }}
      LOGIN_PASSWORD: ${{ secrets.LOGIN_PASSWORD }}
      USE_CI_REPORTER: ${{ github.event.inputs.use_ci_reporter || 'true' }}
      DSS_GRAPHQL_URL: ${{ github.event.inputs.dss_graphql_url || 'https://integration.datasense.pgdss.com/api/pgds-platform/graphql' }}
      DSS_WEBSITE_URL: ${{ github.event.inputs.dss_web_url || 'https://integration.datasense.pgdss.com' }}
      GH_PAT: ${{ secrets.GH_PAT }}

    steps:
      - uses: actions/checkout@v2.4.0
        with:
            persist-credentials: false

      - name: Set Environment Variables
        uses: ./.github/actions/setvars
        with:
          varFilePath: ./.github/variables/node.env

      - name: Use Node.js
        uses: actions/setup-node@v3.1.0
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'yarn'

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

      - name: Install Playwright Browsers
        run: npx playwright install --with-deps

      - name: Run Regression Tests
        working-directory: test
        run: npx playwright test

      - uses: actions/upload-artifact@v2
        if: always()
        with:
          name: test-results
          path: test-results/
          retention-days: 30
