name: Reusable workflow to run smoke tests

on:
  workflow_call:
    inputs:
      runs-on:
        required: true
        type: string
      kubernetesVersion:
        required: true
        type: string
      kindImage:
        required: true
        type: string
jobs:
  smoke-tests:
    name: Validate k8s-${{ inputs.kubernetesVersion }}
    runs-on: ${{ inputs.runs-on }}
    steps:
      - name: Setup Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.19

      - name: Install prerequisites
        run: |
          sudo apt update
          sudo apt install curl make ca-certificates gcc libc-dev -y
        env:
          DEBIAN_FRONTEND: noninteractive

      - name: Check out code
        uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: Create k8s ${{ inputs.kubernetesVersion }} Kind Cluster
        uses: helm/kind-action@v1.4.0
        with:
          node_image: ${{ inputs.kindImage }}
          cluster_name: smoke-tests-cluster-${{ inputs.kubernetesVersion }}

      - name: Run smoke test
        run: make smoke-test

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