name: Reusable workflow to run e2e tests on main branch

on:
  workflow_call:

jobs:
  e2e-tests:
    name: Run e2e test
    runs-on: ubuntu-latest
    # build-tools is built from ../../tools/build-tools.Dockerfile
    container: ghcr.io/kedacore/build-tools:1.19.7
    concurrency: e2e-tests
    steps:
      - name: Check out code
        uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: Register workspace path
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

      - uses: oNaiPs/secrets-to-env-action@v1
        with:
          secrets: ${{ toJSON(secrets) }}

      - name: Run end to end tests
        env:
          AWS_RUN_IDENTITY_TESTS: true
          AZURE_RUN_AAD_POD_IDENTITY_TESTS: true
          AZURE_RUN_WORKLOAD_IDENTITY_TESTS: true
          GCP_RUN_IDENTITY_TESTS: true
        run: make e2e-test

      - name: Delete all e2e related namespaces
        if: ${{ always() }}
        run: make e2e-test-clean

      - name: Upload test logs
        uses: actions/upload-artifact@v3
        if: ${{ always() }}
        with:
          name: e2e-test-logs
          path: '${{ github.workspace }}/tests/**/*.log'
          if-no-files-found: ignore
