name: Cleanup
description: 'Runs all the cleanup tasks to cleanup resources deployed during E2E'
inputs:
  account_id:
    description: "Account ID to access AWS"
    required: true
  role:
    description: "Role to access AWS"
    required: true
  region:
    description: "Region to access AWS"
    required: true
  cluster_name:
    description: 'Name of the cluster to be launched by eksctl'
    required: true
  git_ref:
    description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release"
  eksctl_version:
    description: "Version of eksctl to install"
    default: v0.191.0
  private_cluster:
    description: "Whether the cluster that has to be deleted is private or not. Valid values are 'true' or 'false'"
    default: 'false'
runs:
  using: "composite"
  steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      with:
        ref: ${{ inputs.git_ref }}
    - uses: ./.github/actions/e2e/install-eksctl
      with:
        version: ${{ inputs.eksctl_version }}
    - name: delete-cluster
      if: ${{ inputs.private_cluster == 'false' }}
      shell: bash
      env:
        CLUSTER_NAME: ${{ inputs.cluster_name }}
      run: |
        eksctl delete cluster --name "$CLUSTER_NAME" --timeout 60m --wait || true
    - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
      with:
        go-version-file: test/hack/resource/go.mod
        cache-dependency-path: test/hack/resource/go.sum
        check-latest: true
        cache: false
    - name: "Run cleanup script"
      shell: bash
      env:
        CLUSTER_NAME: ${{ inputs.cluster_name }}
      run: |
        go run main.go --cluster-name "$CLUSTER_NAME"
      working-directory: ./test/hack/resource/clean
