Skip to content

Commit 1818874

Browse files
agnersclaude
andauthored
Include Python patch version in CI cache keys (#315)
* Include Python patch version in CI cache keys The venv and pre-commit caches hold virtualenvs whose python symlink points at /opt/hostedtoolcache/Python/<patch>/... When the hosted toolcache bumps patch versions (e.g. 3.13.12 -> 3.13.13), the symlink dangles and every entry point fails with "required file not found". Keying on steps.python.outputs.python-version invalidates the cache on any patch bump. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Deduplicate cache-key generation via YAML anchor Pulls the "Generate cache keys" step into a &cache-keys-step anchor so all six jobs share one definition. Cache keys become short single-line references and a future toolcache bump or hash location change touches only the anchor. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Use YAML scalar anchors for cache keys instead of a shared step Anchors the venv and pre-commit cache key strings directly. Folded scalar line breaks sit inside ${{ ... }} expressions so they vanish at evaluation time. Drops the helper step and the $GITHUB_OUTPUT roundtrip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a0d868e commit 1818874

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ jobs:
4141
uses: actions/cache@v5.0.5
4242
with:
4343
path: venv
44-
key: >
45-
${{ runner.os }}-venv-${{ matrix.python-version }}-
46-
${{ hashFiles('pyproject.toml') }}
44+
key: &venv-key >-
45+
${{ runner.os }}-venv-${{
46+
steps.python.outputs.python-version }}-${{
47+
hashFiles('pyproject.toml') }}
4748
- name: Create Python virtual environment
4849
if: steps.cache-venv.outputs.cache-hit != 'true'
4950
run: |
@@ -57,9 +58,10 @@ jobs:
5758
with:
5859
path: ${{ env.PRE_COMMIT_CACHE }}
5960
lookup-only: true
60-
key: >
61-
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
62-
${{ hashFiles('.pre-commit-config.yaml') }}
61+
key: &pre-commit-key >-
62+
${{ runner.os }}-pre-commit-${{
63+
steps.python.outputs.python-version }}-${{
64+
hashFiles('.pre-commit-config.yaml') }}
6365
restore-keys: |
6466
${{ runner.os }}-pre-commit-
6567
- name: Install pre-commit dependencies
@@ -88,9 +90,7 @@ jobs:
8890
uses: actions/cache@v5.0.5
8991
with:
9092
path: venv
91-
key: >
92-
${{ runner.os }}-venv-${{ matrix.python-version }}-
93-
${{ hashFiles('pyproject.toml') }}
93+
key: *venv-key
9494
- name: Fail job if Python cache restore failed
9595
if: steps.cache-venv.outputs.cache-hit != 'true'
9696
run: |
@@ -101,9 +101,7 @@ jobs:
101101
uses: actions/cache@v5.0.5
102102
with:
103103
path: ${{ env.PRE_COMMIT_CACHE }}
104-
key: >
105-
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
106-
${{ hashFiles('.pre-commit-config.yaml') }}
104+
key: *pre-commit-key
107105
- name: Fail job if cache restore failed
108106
if: steps.cache-venv.outputs.cache-hit != 'true'
109107
run: |
@@ -137,9 +135,7 @@ jobs:
137135
uses: actions/cache@v5.0.5
138136
with:
139137
path: venv
140-
key: >
141-
${{ runner.os }}-venv-${{ matrix.python-version }}-
142-
${{ hashFiles('pyproject.toml') }}
138+
key: *venv-key
143139
- name: Fail job if Python cache restore failed
144140
if: steps.cache-venv.outputs.cache-hit != 'true'
145141
run: |
@@ -150,9 +146,7 @@ jobs:
150146
uses: actions/cache@v5.0.5
151147
with:
152148
path: ${{ env.PRE_COMMIT_CACHE }}
153-
key: >
154-
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
155-
${{ hashFiles('.pre-commit-config.yaml') }}
149+
key: *pre-commit-key
156150
- name: Fail job if cache restore failed
157151
if: steps.cache-venv.outputs.cache-hit != 'true'
158152
run: |
@@ -186,9 +180,7 @@ jobs:
186180
uses: actions/cache@v5.0.5
187181
with:
188182
path: venv
189-
key: >
190-
${{ runner.os }}-venv-${{ matrix.python-version }}-
191-
${{ hashFiles('pyproject.toml') }}
183+
key: *venv-key
192184
- name: Fail job if Python cache restore failed
193185
if: steps.cache-venv.outputs.cache-hit != 'true'
194186
run: |
@@ -199,9 +191,7 @@ jobs:
199191
uses: actions/cache@v5.0.5
200192
with:
201193
path: ${{ env.PRE_COMMIT_CACHE }}
202-
key: >
203-
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
204-
${{ hashFiles('.pre-commit-config.yaml') }}
194+
key: *pre-commit-key
205195
- name: Fail job if cache restore failed
206196
if: steps.cache-venv.outputs.cache-hit != 'true'
207197
run: |
@@ -278,9 +268,7 @@ jobs:
278268
uses: actions/cache@v5.0.5
279269
with:
280270
path: venv
281-
key: >
282-
${{ runner.os }}-venv-${{ matrix.python-version }}-
283-
${{ hashFiles('pyproject.toml') }}
271+
key: *venv-key
284272
- name: Fail job if Python cache restore failed
285273
if: steps.cache-venv.outputs.cache-hit != 'true'
286274
run: |
@@ -330,9 +318,7 @@ jobs:
330318
uses: actions/cache@v5.0.5
331319
with:
332320
path: venv
333-
key: >
334-
${{ runner.os }}-venv-${{ env.DEFAULT_PYTHON }}-
335-
${{ hashFiles('pyproject.toml') }}
321+
key: *venv-key
336322
- name: Fail job if Python cache restore failed
337323
if: steps.cache-venv.outputs.cache-hit != 'true'
338324
run: |

0 commit comments

Comments
 (0)