|
| 1 | +# Entry conditions: |
| 2 | +# - `setup/checkout` has already happened |
| 3 | +# - working dir is the root directory of your project (e.g. `reflex/`). |
| 4 | +# - You have a `uv.lock` file in the root directory of your project |
| 5 | +# - You have a `pyproject.toml` file in the root directory of your project |
| 6 | +# |
| 7 | +# Exit conditions: |
| 8 | +# - Python of version `python-version` is ready to be invoked as `python`. |
| 9 | +# - Uv of version `uv-version` is ready to be invoked as `uv`. |
| 10 | +# - If `run-uv-sync` is true, deps as defined in `pyproject.toml` will have been installed into the venv at `create-venv-at-path`. |
| 11 | + |
| 12 | +name: "Setup Reflex build environment" |
| 13 | +description: "Sets up Python, install uv (cached), install project deps (cached)" |
| 14 | +inputs: |
| 15 | + python-version: |
| 16 | + description: "Python version setup" |
| 17 | + required: true |
| 18 | + uv-version: |
| 19 | + description: "Uv version to install" |
| 20 | + required: false |
| 21 | + default: "0.8.0" |
| 22 | + run-uv-sync: |
| 23 | + description: "Whether to run uv sync on current dir" |
| 24 | + required: false |
| 25 | + default: false |
| 26 | + create-venv-at-path: |
| 27 | + description: "Path to venv (if uv sync is enabled)" |
| 28 | + required: false |
| 29 | + default: ".venv" |
| 30 | + |
| 31 | +runs: |
| 32 | + using: "composite" |
| 33 | + steps: |
| 34 | + - name: Install UV |
| 35 | + uses: astral-sh/setup-uv@v5 |
| 36 | + with: |
| 37 | + version: ${{ inputs.uv-version }} |
| 38 | + python-version: ${{ inputs.python-version }} |
| 39 | + enable-cache: true |
| 40 | + prune-cache: false |
| 41 | + cache-dependency-glob: "uv.lock" |
| 42 | + |
| 43 | + - name: Restore cached project python deps |
| 44 | + id: restore-pydeps-cache |
| 45 | + uses: actions/cache/restore@v4 |
| 46 | + with: |
| 47 | + path: ${{ inputs.create-venv-at-path }} |
| 48 | + key: ${{ runner.os }}-python-${{ inputs.python-version }}-pydeps-${{ hashFiles('**/uv.lock') }} |
| 49 | + |
| 50 | + - if: ${{ inputs.run-uv-sync == 'true' && steps.restore-pydeps-cache.outputs.cache-hit != 'true' }} |
| 51 | + name: Run uv sync (will get cached) |
| 52 | + # We skip over installing the root package (the current project code under CI) |
| 53 | + # Root package should not be cached - its content is not reflected in uv.lock / cache key |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + uv sync --all-extras --dev --no-install-project --prerelease=allow |
| 57 | +
|
| 58 | + - if: steps.restore-pydeps-cache.outputs.cache-hit != 'true' |
| 59 | + name: Save Python deps to cache |
| 60 | + uses: actions/cache/save@v4 |
| 61 | + with: |
| 62 | + path: ${{ inputs.create-venv-at-path }} |
| 63 | + key: ${{ steps.restore-pydeps-cache.outputs.cache-primary-key }} |
| 64 | + |
| 65 | + - if: ${{ inputs.run-uv-sync == 'true' }} |
| 66 | + name: Run uv sync (root package) |
| 67 | + # Here we really install the root package (the current project code under CI).env: |
| 68 | + # This should not be cached. |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + uv sync --all-extras --dev |
0 commit comments