Skip to content

Commit 7d60c27

Browse files
Explicitly save cache in primer jobs
Refs #9925 (comment)
1 parent 67acc96 commit 7d60c27

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

.github/workflows/primer_run_main.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ jobs:
4343
check-latest: true
4444

4545
# Create a re-usable virtual environment
46-
- name: Create Python virtual environment cache
46+
- name: Restore Python virtual environment cache
4747
id: cache-venv
48-
uses: actions/[email protected]
48+
uses: actions/cache/restore@v4.0.2
4949
with:
5050
path: venv
5151
key:
@@ -60,6 +60,18 @@ jobs:
6060
. venv/bin/activate
6161
python -m pip install -U pip setuptools wheel
6262
pip install -U -r requirements_test.txt
63+
# Save cached Python environment (explicit because cancel-in-progress: true)
64+
- name: Save Python virtual environment to cache
65+
if: steps.cache-venv.outputs.cache-hit != 'true'
66+
id: cache-venv
67+
uses: actions/cache/[email protected]
68+
with:
69+
path: venv
70+
key:
71+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
72+
env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml',
73+
'requirements_test.txt', 'requirements_test_min.txt',
74+
'requirements_test_pre_commit.txt') }}
6375

6476
# Cache primer packages
6577
- name: Get commit string
@@ -71,7 +83,7 @@ jobs:
7183
echo "commitstring=$output" >> $GITHUB_OUTPUT
7284
- name: Restore projects cache
7385
id: cache-projects
74-
uses: actions/[email protected]
86+
uses: actions/cache/restore@v4.0.2
7587
with:
7688
path: tests/.pylint_primer_tests/
7789
key: >-
@@ -82,6 +94,15 @@ jobs:
8294
run: |
8395
. venv/bin/activate
8496
python tests/primer/__main__.py prepare --clone
97+
- name: Save projects cache
98+
if: steps.cache-projects.outputs.cache-hit != 'true'
99+
id: cache-projects
100+
uses: actions/cache/[email protected]
101+
with:
102+
path: tests/.pylint_primer_tests/
103+
key: >-
104+
${{ runner.os }}-${{ matrix.python-version }}-${{
105+
steps.commitstring.outputs.commitstring }}-primer
85106
- name: Upload commit string
86107
uses: actions/[email protected]
87108
if: matrix.batchIdx == 0

.github/workflows/primer_run_pr.yaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
# Restore cached Python environment
5757
- name: Restore Python virtual environment
5858
id: cache-venv
59-
uses: actions/[email protected]
59+
uses: actions/cache/restore@v4.0.2
6060
with:
6161
path: venv
6262
key:
@@ -72,6 +72,18 @@ jobs:
7272
. venv/bin/activate
7373
python -m pip install -U pip setuptools wheel
7474
pip install -U -r requirements_test.txt
75+
# Save cached Python environment (explicit because cancel-in-progress: true)
76+
- name: Save Python virtual environment
77+
if: steps.cache-venv.outputs.cache-hit != 'true'
78+
id: cache-venv
79+
uses: actions/cache/[email protected]
80+
with:
81+
path: venv
82+
key:
83+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
84+
env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml',
85+
'requirements_test.txt', 'requirements_test_min.txt',
86+
'requirements_test_pre_commit.txt') }}
7587

7688
# Cache primer packages
7789
- name: Download last 'main' run info
@@ -140,7 +152,7 @@ jobs:
140152
echo "commitstring=$output" >> $GITHUB_OUTPUT
141153
- name: Restore projects cache
142154
id: cache-projects
143-
uses: actions/[email protected]
155+
uses: actions/cache/restore@v4.0.2
144156
with:
145157
path: tests/.pylint_primer_tests/
146158
key: >-
@@ -151,6 +163,14 @@ jobs:
151163
run: |
152164
. venv/bin/activate
153165
python tests/primer/__main__.py prepare --clone
166+
- name: Save projects cache
167+
if: steps.cache-projects.outputs.cache-hit != 'true'
168+
uses: actions/cache/[email protected]
169+
with:
170+
path: tests/.pylint_primer_tests/
171+
key: >-
172+
${{ runner.os }}-${{ matrix.python-version }}-${{
173+
steps.commitstring.outputs.commitstring }}-primer
154174
- name: Check cache
155175
run: |
156176
. venv/bin/activate

0 commit comments

Comments
 (0)