name: "Bootstrap"
description: "Bootstrap all tools and dependencies"
inputs:
  go-version:
    description: "Go version to install"
    required: true
    default: "1.24.x"
  cache-key-prefix:
    description: "Prefix all cache keys with this value"
    required: true
    default: "efa04b89c1b1"
  bootstrap-apt-packages:
    description: "Space delimited list of tools to install via apt"
    default: ""

runs:
  using: "composite"
  steps:
    - uses: actions/setup-go@v5
      with:
        go-version: ${{ inputs.go-version }}

    - name: Restore tool cache
      id: tool-cache
      uses: actions/cache@v4
      with:
        path: ${{ github.workspace }}/.tmp
        key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-tool-${{ hashFiles('Makefile') }}

    - name: (cache-miss) Bootstrap project tools
      shell: bash
      if: steps.tool-cache.outputs.cache-hit != 'true'
      run: make tools

    - name: (cache-miss) Bootstrap go dependencies
      shell: bash
      if: steps.go-mod-cache.outputs.cache-hit != 'true'
      run: go mod download -x

    - name: Install apt packages
      if: inputs.bootstrap-apt-packages != ''
      shell: bash
      run: |
        DEBIAN_FRONTEND=noninteractive sudo apt update && sudo -E apt install -y ${{ inputs.bootstrap-apt-packages }}
