name: Setup
description: Sets up Python with uv and pre-commit

# note:
# this is a local composite action
# documentation: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
# code example: https://github.com/GuillaumeFalourd/poc-github-actions/blob/main/.github/actions/local-action/action.yaml

inputs:
  pre-commit:
    description: Whether pre-commit shall be setup, too
    required: false
    default: "" # == false
  python-version:
    description: The python version to install
    required: true
    default: "3.12"
  install-nox:
    description: Whether nox shall be installed
    required: false
    default: "" # == false
runs:
  using: "composite"
  steps:
    - name: Install uv
      uses: astral-sh/setup-uv@v4
      with:
        enable-cache: true
        cache-dependency-glob: "uv.lock"

    - name: Set up Python ${{ inputs.python-version }}
      shell: bash
      run: uv python install ${{ inputs.python-version }}

    - name: Install dependencies
      shell: bash
      run: uv sync --group dev

    - name: Hash python version
      if: ${{ inputs.pre-commit }}
      shell: bash
      run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

    - name: Caching for Pre-Commit
      if: ${{ inputs.pre-commit }}
      uses: actions/cache@v3
      with:
        path: ~/.cache/pre-commit
        key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
