Skip to content

Commit b5b9496

Browse files
committed
Save CI venv caches even when later steps fail
actions/cache's built-in post-step skips saving on job failure, which threw away a perfectly good cold venv install just because a later check, audit, test, or docs build failed afterward. Split each `Cache all venvs` step into an explicit restore (actions/cache/restore) up front and a save (actions/cache/save) gated on the install step's own outcome, so a cold install is preserved regardless of what fails later, and skipped when the key already had an exact hit. - Bump actions/setup-python to v6, actions/cache to v5, and actions/upload-artifact to v6. - Widen the `build` job's timeout from 40 to 120 minutes: a cold prepare-envs over the whole workspace plus the full check suite doesn't fit in 40 minutes on the slower matrix legs, and the venvs cache only keeps the happy path short.
1 parent e7a51b6 commit b5b9496

2 files changed

Lines changed: 59 additions & 14 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ env:
3434
jobs:
3535
build:
3636
runs-on: ${{ matrix.os }}
37-
timeout-minutes: 40
37+
# A cold `prepare-envs` over the whole workspace plus the full check suite does
38+
# not fit in 40 minutes on the slower matrix legs. The venvs cache keeps the
39+
# happy path short; this budget only covers the cold run.
40+
timeout-minutes: 120
3841
strategy:
3942
fail-fast: false
4043
matrix:
@@ -71,7 +74,7 @@ jobs:
7174
fi
7275
7376
- name: Set up Python ${{ env.DEV_WORKSPACE_PYTHON_VERSION }}
74-
uses: actions/setup-python@v5
77+
uses: actions/setup-python@v6
7578
with:
7679
python-version: ${{ env.DEV_WORKSPACE_PYTHON_VERSION }}
7780

@@ -81,8 +84,9 @@ jobs:
8184
# skip reinstalling whenever a restored venv already looks valid, so a stale
8285
# partial-match restore could mask a dependency that was added since the cache
8386
# was written.
84-
- name: Cache all venvs
85-
uses: actions/cache@v4
87+
- name: Restore venvs cache
88+
id: venvs_cache
89+
uses: actions/cache/restore@v5
8690
with:
8791
path: |
8892
.venvs
@@ -169,18 +173,33 @@ jobs:
169173

170174
# TODO: try to replace by finecode action
171175
- name: Store the distribution packages
172-
uses: actions/upload-artifact@v5
176+
uses: actions/upload-artifact@v6
173177
if: runner.os == 'Linux'
174178
with:
175179
name: python-package-distributions
176180
path: dist/
177181

182+
# Save the venvs explicitly instead of relying on actions/cache's own post-step:
183+
# that post-step skips the save when the job fails, which throws away a perfectly
184+
# good cold install just because a later check or test failed. The only
185+
# precondition here is that the install itself succeeded; on an exact key match
186+
# there is nothing new to save.
187+
- name: Save venvs cache
188+
if: ${{ always() && steps.install.outcome == 'success' && steps.venvs_cache.outputs.cache-hit != 'true' }}
189+
uses: actions/cache/save@v5
190+
with:
191+
path: |
192+
.venvs
193+
**/.venvs
194+
key: ${{ runner.os }}-venvs-${{ hashFiles('**/pyproject.toml', '**/preset.toml') }}
195+
178196
audit-private:
179197
name: Audit (private layer)
180198
runs-on: ubuntu-24.04
181-
# The `build` job's 40min budget is not enough: this job pays a cold
182-
# prepare-envs over ~74 projects and then a workspace-wide audit_code, which
183-
# is slow by design (see docs/guides/developing-finecode.md "Running checks").
199+
# This job pays a cold prepare-envs over ~74 projects and then a
200+
# workspace-wide audit_code, which is slow by design (see
201+
# docs/guides/developing-finecode.md "Running checks"), so it carries its own
202+
# budget rather than inheriting the build matrix's.
184203
timeout-minutes: 60
185204
# `secrets` is NOT available in jobs.<job_id>.if -- only github, needs,
186205
# vars, inputs. An unavailable context evaluates to empty, so a secrets test
@@ -219,7 +238,7 @@ jobs:
219238
220239
- name: Set up Python ${{ env.DEV_WORKSPACE_PYTHON_VERSION }}
221240
if: env.HAS_PRIVATE_CLONE_APP == 'true'
222-
uses: actions/setup-python@v5
241+
uses: actions/setup-python@v6
223242
with:
224243
python-version: ${{ env.DEV_WORKSPACE_PYTHON_VERSION }}
225244

@@ -257,16 +276,18 @@ jobs:
257276
if: env.HAS_PRIVATE_CLONE_APP == 'true'
258277
run: cp .github/ci/finecode-user.ci.toml finecode-user.toml
259278

260-
- name: Cache all venvs
279+
- name: Restore venvs cache
280+
id: venvs_cache
261281
if: env.HAS_PRIVATE_CLONE_APP == 'true'
262-
uses: actions/cache@v4
282+
uses: actions/cache/restore@v5
263283
with:
264284
path: |
265285
.venvs
266286
**/.venvs
267287
key: ${{ runner.os }}-private-venvs-${{ hashFiles('**/pyproject.toml', '**/preset.toml', 'finecode-user.toml') }}
268288

269289
- name: Install dependencies
290+
id: install
270291
if: env.HAS_PRIVATE_CLONE_APP == 'true'
271292
run: |
272293
# CI must exercise this branch's local source, so finecode and its sibling
@@ -303,3 +324,14 @@ jobs:
303324
source .venvs/dev_workspace/bin/activate
304325
python -m finecode run --log-level="$FINECODE_LOG_LEVEL" run_tests
305326
shell: bash
327+
328+
# See the matching step in the `build` job for the rationale: save the venvs
329+
# whenever the install succeeded, even if a later check, audit or test failed.
330+
- name: Save venvs cache
331+
if: ${{ always() && env.HAS_PRIVATE_CLONE_APP == 'true' && steps.install.outcome == 'success' && steps.venvs_cache.outputs.cache-hit != 'true' }}
332+
uses: actions/cache/save@v5
333+
with:
334+
path: |
335+
.venvs
336+
**/.venvs
337+
key: ${{ runner.os }}-private-venvs-${{ hashFiles('**/pyproject.toml', '**/preset.toml', 'finecode-user.toml') }}

.github/workflows/docs.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ jobs:
2727
fi
2828
2929
- name: Set up Python
30-
uses: actions/setup-python@v5
30+
uses: actions/setup-python@v6
3131
with:
3232
python-version: '3.14'
3333

3434
# Same cache key pattern as ci-cd.yml so a preceding CI run on the same commit
3535
# can seed this cache and skip most of the install work.
36-
- name: Cache all venvs
37-
uses: actions/cache@v4
36+
- name: Restore venvs cache
37+
id: venvs_cache
38+
uses: actions/cache/restore@v5
3839
with:
3940
path: |
4041
.venvs
4142
**/.venvs
4243
key: ${{ runner.os }}-venvs-${{ hashFiles('**/pyproject.toml', '**/preset.toml') }}
4344

4445
- name: Install dependencies
46+
id: install
4547
run: sh scripts/setup-dev-workspace.sh
4648

4749
- name: Build docs
@@ -58,3 +60,14 @@ jobs:
5860
external_repository: finecode-dev/finecode.github.io
5961
publish_branch: main
6062
publish_dir: ./site
63+
64+
# Save the venvs whenever the install succeeded, even if the docs build or
65+
# deploy failed: the cold install is the expensive part and is still valid.
66+
- name: Save venvs cache
67+
if: ${{ always() && steps.install.outcome == 'success' && steps.venvs_cache.outputs.cache-hit != 'true' }}
68+
uses: actions/cache/save@v5
69+
with:
70+
path: |
71+
.venvs
72+
**/.venvs
73+
key: ${{ runner.os }}-venvs-${{ hashFiles('**/pyproject.toml', '**/preset.toml') }}

0 commit comments

Comments
 (0)