# Entry conditions:
# - `setup/checkout` has already happened
# - working dir is the root directory of your project (e.g. `reflex/`).
# - You have a `uv.lock` file in the root directory of your project
# - You have a `pyproject.toml` file in the root directory of your project
#
# Exit conditions:
# - Python of version `python-version` is ready to be invoked as `python`.
# - If `run-uv-sync` is true, deps as defined in `pyproject.toml` will have been installed into the venv at `create-venv-at-path`.

name: "Setup Reflex build environment"
description: "Sets up Python, install uv (cached), install project deps (cached)"
inputs:
  python-version:
    description: "Python version setup"
    required: true
  run-uv-sync:
    description: "Whether to run uv sync on current dir"
    required: false
    default: false
  working-directory:
    description: "Directory to run uv sync from. Defaults to the repo root."
    required: false
    default: "."
  create-venv-at-path:
    description: "Path to venv (if uv sync is enabled)"
    required: false
    default: ".venv"

runs:
  using: "composite"
  steps:
    - name: Install UV
      uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
      with:
        python-version: ${{ inputs.python-version }}
        enable-cache: true
        prune-cache: false
        activate-environment: true
        cache-dependency-glob: "uv.lock"
        working-directory: ${{ inputs.working-directory }}
    - name: Setup Node
      uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
      with:
        node-version: 22
    - name: Install Dependencies
      if: inputs.run-uv-sync == 'true'
      run: uv sync
      shell: bash
      working-directory: ${{ inputs.working-directory }}
