Skip to content

Commit 101110d

Browse files
committed
ci: cache poetry venv keyed on lockfile and cython sources
Caches the poetry-managed .venv plus the built Cython artefacts (src/zeroconf/**/*.so) for both the test matrix and benchmark jobs, keyed on runner OS + image version + python version + extension mode + hash of poetry.lock/pyproject.toml/build_ext.py + hash of src/zeroconf/**/*.py and **/*.pxd. On a cache hit, the Install Dependencies step is skipped. Pure Python and Cython source changes both invalidate the cache, so tests never run against stale .so files. POETRY_VIRTUALENVS_IN_PROJECT="true" is set at the job level so poetry creates .venv inside the repo and the cache can target a single path.
1 parent d03ea36 commit 101110d

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ jobs:
7575
- os: macos-latest
7676
python-version: "pypy-3.10"
7777
runs-on: ${{ matrix.os }}
78+
env:
79+
POETRY_VIRTUALENVS_IN_PROJECT: "true"
7880
steps:
7981
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
8082
- name: Set up uv
@@ -89,13 +91,21 @@ jobs:
8991
python-version: ${{ matrix.python-version }}
9092
cache: "poetry"
9193
allow-prereleases: true
94+
- name: Cache poetry venv
95+
id: cache-venv
96+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
97+
with:
98+
path: |
99+
.venv
100+
src/zeroconf/**/*.so
101+
key: venv-v1-${{ runner.os }}-${{ env.ImageOS }}-${{ env.ImageVersion }}-py${{ matrix.python-version }}-${{ matrix.extension }}-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py') }}-${{ hashFiles('src/zeroconf/**/*.py', 'src/zeroconf/**/*.pxd') }}
92102
- name: Install Dependencies no cython
93-
if: ${{ matrix.extension == 'skip_cython' }}
103+
if: ${{ matrix.extension == 'skip_cython' && steps.cache-venv.outputs.cache-hit != 'true' }}
94104
env:
95105
SKIP_CYTHON: 1
96106
run: poetry install --only=main,dev
97107
- name: Install Dependencies with cython
98-
if: ${{ matrix.extension != 'skip_cython' }}
108+
if: ${{ matrix.extension != 'skip_cython' && steps.cache-venv.outputs.cache-hit != 'true' }}
99109
env:
100110
REQUIRE_CYTHON: 1
101111
run: poetry install --only=main,dev
@@ -108,6 +118,8 @@ jobs:
108118

109119
benchmark:
110120
runs-on: ubuntu-latest
121+
env:
122+
POETRY_VIRTUALENVS_IN_PROJECT: "true"
111123
steps:
112124
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
113125
- name: Setup Python 3.13
@@ -120,7 +132,16 @@ jobs:
120132
enable-cache: true
121133
- name: Install poetry
122134
run: uv tool install poetry
135+
- name: Cache poetry venv
136+
id: cache-venv
137+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
138+
with:
139+
path: |
140+
.venv
141+
src/zeroconf/**/*.so
142+
key: venv-v1-${{ runner.os }}-${{ env.ImageOS }}-${{ env.ImageVersion }}-benchmark-py3.13-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py') }}-${{ hashFiles('src/zeroconf/**/*.py', 'src/zeroconf/**/*.pxd') }}
123143
- name: Install Dependencies
144+
if: steps.cache-venv.outputs.cache-hit != 'true'
124145
run: |
125146
REQUIRE_CYTHON=1 poetry install --only=main,dev
126147
shell: bash

0 commit comments

Comments
 (0)