#### THIS IS A TEMPLATE ####
# This workflow is created to be a template for every time an e2e test is required,

on:
  workflow_call:
    inputs:
      k8s-version:
        required: true
        type: string
      variation:
        type: string

permissions:
  contents: read

jobs:
  kubernetes:
    name: Kubernetes ${{ inputs.variation }}
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

      - name: cache
        uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
        with:
          name: docker.tar.gz

      - name: Create Kubernetes ${{ inputs.k8s-version }} cluster
        id: kind
        run: |
          kind create cluster --image=kindest/node:${{ inputs.k8s-version }} --config test/e2e/kind.yaml

      - name: Load images from cache
        run: |
          echo "loading docker images..."
          gzip -dc docker.tar.gz | docker load

      - name: Run e2e tests ${{ inputs.variation }}
        env:
          KIND_CLUSTER_NAME: kind
          SKIP_CLUSTER_CREATION: true
          SKIP_INGRESS_IMAGE_CREATION: true
          SKIP_E2E_IMAGE_CREATION: true
          IS_CHROOT: ${{ inputs.variation == 'CHROOT' }}
        run: |
          kind get kubeconfig > $HOME/.kube/kind-config-kind
          make kind-e2e-test

      - name: Upload e2e junit-reports ${{ inputs.variation }}
        uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
        if: success() || failure()
        with:
          name: e2e-test-reports-${{ inputs.k8s-version }}${{ inputs.variation }}
          path: 'test/junitreports/report*.xml'

