name: e2e-checks
on:
  pull_request_target:
    types: ["opened", "edited", "reopened", "synchronize"]
    paths:
      - "kafka-ui-api/**"
      - "kafka-ui-contract/**"
      - "kafka-ui-react-app/**"
      - "kafka-ui-e2e-checks/**"
      - "pom.xml"
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Set the values
        id: set_env_values
        run: |
          cat "./kafka-ui-e2e-checks/.env.ci" >> "./kafka-ui-e2e-checks/.env"
      - name: pull docker
        id: pull_chrome
        run: |
          docker pull selenium/standalone-chrome:103.0
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'zulu'
          cache: 'maven'
      - name: Build with Maven
        id: build_app
        run: |
          ./mvnw -B -ntp versions:set -DnewVersion=${{ github.event.pull_request.head.sha }}
          ./mvnw -B -V -ntp clean package -Pprod -Dmaven.test.skip=true ${{ github.event.inputs.extraMavenOptions }}
      - name: compose app
        id: compose_app
        # use the following command until #819 will be fixed
        run: |
          docker-compose -f ./documentation/compose/e2e-tests.yaml up -d
      - name: e2e run
        run: |
          ./mvnw -B -ntp versions:set -DnewVersion=${{ github.event.pull_request.head.sha }}
          ./mvnw -B -V -ntp -DQASEIO_API_TOKEN=${{ secrets.QASEIO_API_TOKEN }} -pl '!kafka-ui-api' test -Pprod
      - name: Generate allure report
        uses: simple-elf/allure-report-action@master
        if: always()
        id: allure-report
        with:
          allure_results: ./kafka-ui-e2e-checks/allure-results
          gh_pages: allure-results
          allure_report: allure-report
          subfolder: allure-results
      - name: Deploy allure report to Github Pages
        if: always()
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: allure-history
          publish_branch: gh-pages
          destination_dir: ./allure
      - name: Post the link to allure report
        if: always()
        uses: Sibz/github-status-action@v1.1.6
        with:
          authToken: ${{secrets.GITHUB_TOKEN}}
          context: "Test report"
          state: "success"
          sha: ${{ github.event.pull_request.head.sha  || github.sha }}
          target_url: https://${{ github.repository_owner }}.github.io/kafka-ui/allure/allure-results/${{ github.run_number }}
      - name: Dump docker logs on failure
        if: failure()
        uses: jwalton/gh-docker-logs@v2.2.1
