name: InstallDependencies
description: 'Installs Go Downloads and installs Karpenter Dependencies'
inputs:
  k8sVersion:
    description: Kubernetes version to use when installing the toolchain
    default: "1.31.x"
runs:
  using: "composite"
  steps:
    - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
      id: setup-go
      with:
        go-version-file: go.mod
        check-latest: true
        cache-dependency-path: "**/go.sum"
    # Root path permission workaround for caching https://github.com/actions/cache/issues/845#issuecomment-1252594999
    - run: sudo chown "$USER" /usr/local
      shell: bash
    - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
      id: cache-toolchain
      with:
        path: |
          /usr/local/kubebuilder/bin
          ~/go/bin
        # Added go version to compensate for this issue with govulncheck: https://github.com/golang/go/issues/65590. Could re-evaluate if this is necessary once the
        # upstream go issue is corrected and if this is causing too many cache misses.
        key: ${{ runner.os }}-${{ inputs.k8sVersion }}-${{ steps.setup-go.outputs.go-version }}-toolchain-cache-${{ hashFiles('hack/toolchain.sh') }}
    - if: ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }}
      shell: bash
      env:
        K8S_VERSION: ${{ inputs.k8sVersion }}
      run: make toolchain
