name: "Bootstrap"
description: "Bootstrap all tools and dependencies"
inputs:
  go-version:
    description: "Go version to install"
    required: true
    default: "1.22.x"
  python-version:
    description: "Python version to install"
    required: true
    default: "3.10"
  go-dependencies:
    description: "Download go dependencies"
    required: true
    default: "true"
  cache-key-prefix:
    description: "Prefix all cache keys with this value"
    required: true
    default: "1ac8281053"
  compute-fingerprints:
    description: "Compute test fixture fingerprints"
    required: true
    default: "true"
  bootstrap-apt-packages:
    description: "Space delimited list of tools to install via apt"
    default: "libxml2-utils"

runs:
  using: "composite"
  steps:
    # note: go mod and build is automatically cached on default with v4+
    - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
      if: inputs.go-version != ''
      with:
        go-version: ${{ inputs.go-version }}

    - uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
      with:
        python-version: ${{ inputs.python-version }}

    - name: Restore tool cache
      id: tool-cache
      uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
      with:
        path: ${{ github.workspace }}/.tool
        key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-tool-${{ hashFiles('.binny.yaml') }}

    - name: Install project tools
      shell: bash
      run: make tools

    - name: Install go dependencies
      if: inputs.go-dependencies == 'true'
      shell: bash
      run: make ci-bootstrap-go

    - 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 }}

    - name: Create all cache fingerprints
      if: inputs.compute-fingerprints == 'true'
      shell: bash
      run: make fingerprints
