name: setup-env
description: Setup Environment
inputs:
  python-version:
    description: Version of python
    required: true
outputs:
  python-version:
    value: ${{ steps.detect-python.outputs.version }}
    description: Detected Python version.
runs:
  using: "composite"
  steps:
    - name: Detect Python Version
      id: detect-python
      run: |
        if [[ -z "${{ inputs.python-version }}" ]]; then
          echo "version=$(head -n1 .python-version | tr -d '\n')" >> $GITHUB_OUTPUT
        else
          echo "version=${{ inputs.python-version }}" >> $GITHUB_OUTPUT
        fi
      shell: bash
    - name: Detect Poetry Version
      id: detect-poetry
      run: |
        echo "version=$(head -n1 .poetry-version | tr -d '\n')" >> $GITHUB_OUTPUT
      shell: bash
    - name: Set up Python ${{ inputs.python-version }}
      uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
      with:
        python-version: ${{ inputs.python-version }}
        allow-prereleases: true
    - name: Install Poetry
      uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
      with:
        version: ${{ steps.detect-poetry.outputs.version }}
        virtualenvs-create: true
        virtualenvs-in-project: true
