Files
esphome/.github/actions/restore-python/action.yml
T
J. Nick Koston 6d62b3af5f [ci] Use uv for pip installs across CI workflows
Follow-up to #16449 / #16448, extending the uv switch to the workflows
that actually dominate CI cost (every push + every PR):

* ``.github/actions/restore-python`` -- the composite action invoked by
  almost every downstream job as the venv cache-miss fallback. Installs
  setup-uv only when the venv cache misses and swaps ``pip install``
  for ``uv pip install`` (no ``--system``: ``VIRTUAL_ENV`` is set by the
  activate step, so installs land in the venv that downstream jobs
  expect to ``. venv/bin/activate``).

* ``.github/workflows/ci.yml`` ``common`` job -- the canonical venv
  builder whose cache feeds the rest of the workflow.

* ``.github/workflows/ci.yml`` ``integration-tests`` job -- has its
  own venv create path on cache miss for the 3.13 matrix entry.

* ``.github/workflows/ci-api-proto.yml`` -- single ``pip install``
  step; uses ``uv pip install --system`` since this workflow does not
  set up or restore a venv.

All four call sites use ``astral-sh/setup-uv@v8.1.0`` (SHA-pinned) with
``enable-cache: true`` for a persistent wheel cache across runs.

Cache-hit paths are unchanged -- setup-uv only runs on cache miss for
the venv-restoring jobs, so steady-state behavior matches today.
2026-05-15 09:53:27 -07:00

56 lines
2.0 KiB
YAML

name: Restore Python
inputs:
python-version:
description: Python version to restore
required: true
type: string
cache-key:
description: Cache key to use
required: true
type: string
outputs:
python-version:
description: Python version restored
value: ${{ steps.python.outputs.python-version }}
runs:
using: "composite"
steps:
- name: Set up Python ${{ inputs.python-version }}
id: python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ inputs.python-version }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: venv
# yamllint disable-line rule:line-length
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ inputs.cache-key }}
- name: Set up uv
# Only needed on cache miss to populate the venv. ``uv pip install``
# detects the activated venv via ``VIRTUAL_ENV`` so the venv layout
# downstream jobs rely on is preserved.
if: steps.cache-venv.outputs.cache-hit != 'true'
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true' && runner.os != 'Windows'
shell: bash
run: |
python -m venv venv
source venv/bin/activate
python --version
uv pip install -r requirements.txt -r requirements_test.txt
uv pip install -e .
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true' && runner.os == 'Windows'
shell: bash
run: |
python -m venv venv
source ./venv/Scripts/activate
python --version
uv pip install -r requirements.txt -r requirements_test.txt
uv pip install -e .