name: sonobuoy
description: "Execute the e2e test framework sonobuoy."

inputs:
  artifactNameSuffix:
    description: "Suffix for artifact naming."
    required: true
  sonobuoyTestSuiteCmd:
    description: "Which tests should be run?"
    required: true
  kubeconfig:
    description: "The kubeconfig of the cluster to test."
    required: true

runs:
  using: "composite"
  steps:
    - name: Install sonobuoy
      shell: bash
      env:
        SONOBUOY_VER: "0.56.17"
      run: |
        HOSTOS="$(go env GOOS)"
        HOSTARCH="$(go env GOARCH)"
        curl -fsSLO https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VER}/sonobuoy_${SONOBUOY_VER}_${HOSTOS}_${HOSTARCH}.tar.gz
        tar -xzf sonobuoy_${SONOBUOY_VER}_${HOSTOS}_${HOSTARCH}.tar.gz
        install sonobuoy /usr/local/bin

    - name: Sonobuoy version
      shell: bash
      run: sonobuoy version

    - name: Run e2e test
      shell: bash
      env:
        KUBECONFIG: ${{ inputs.kubeconfig }}
      run: sonobuoy run --wait=300 ${{ inputs.sonobuoyTestSuiteCmd }} --kubeconfig constellation-admin.conf

    - name: Download results
      shell: bash
      env:
        KUBECONFIG: ${{ inputs.kubeconfig }}
      run: sonobuoy retrieve --kubeconfig constellation-admin.conf

    - name: Upload test results
      if: always() && !env.ACT
      uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
      with:
        name: "sonobuoy-logs-${{ inputs.artifactNameSuffix }}.tar.gz"
        path: "*_sonobuoy_*.tar.gz"

    # Only works on "sonobuoy full" tests (e2e plugin)
    - name: Extract test results
      if: (!env.ACT) && contains(inputs.sonobuoyTestSuiteCmd, '--plugin e2e')
      shell: bash
      run: tar -xf *_sonobuoy_*.tar.gz

    - name: Publish test results
      if: (!env.ACT) && contains(inputs.sonobuoyTestSuiteCmd, '--plugin e2e')
      uses: mikepenz/action-junit-report@150e2f992e4fad1379da2056d1d1c279f520e058 # v3.8.0
      with:
        report_paths: "**/junit_01.xml"
        fail_on_failure: true
