Skip to content

Commit 88b9287

Browse files
authored
Merge pull request #776 from webknjaz/maintenance/gha-cache-python-deps
🧪 Switch GHA to `re-actors/cache-python-deps`
2 parents a7084c1 + 1d91246 commit 88b9287

File tree

4 files changed

+86
-310
lines changed

4 files changed

+86
-310
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
3+
outputs:
4+
cache-key-for-dep-files:
5+
description: >-
6+
A cache key string derived from the dependency declaration files.
7+
value: ${{ steps.calc-cache-key-files.outputs.files-hash-key }}
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: >-
13+
Calculate dependency files' combined hash value
14+
for use in the cache key
15+
id: calc-cache-key-files
16+
run: |
17+
from os import environ
18+
from pathlib import Path
19+
20+
FILE_APPEND_MODE = 'a'
21+
22+
files_derived_hash = '${{
23+
hashFiles(
24+
'setup.cfg',
25+
'tox.ini',
26+
'pyproject.toml',
27+
'.pre-commit-config.yaml',
28+
'pytest.ini',
29+
'dependencies/**',
30+
'dependencies/*/**',
31+
'requirements-build.*',
32+
'docs/requirements.*'
33+
)
34+
}}'
35+
36+
print(f'Computed file-derived hash is {files_derived_hash}.')
37+
38+
with Path(environ['GITHUB_OUTPUT']).open(
39+
mode=FILE_APPEND_MODE,
40+
) as outputs_file:
41+
print(
42+
f'files-hash-key={files_derived_hash}',
43+
file=outputs_file,
44+
)
45+
shell: python
46+
47+
...

.github/workflows/ci-cd.yml

Lines changed: 27 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ run-name: >-
113113
}})
114114
115115
jobs:
116-
lint:
117-
uses: ./.github/workflows/reusable-linters.yml
118-
119116
pre-setup:
120117
name: ⚙️ Pre-set global build settings
121118

@@ -153,8 +150,8 @@ jobs:
153150
}}
154151
profiling-enabled: >-
155152
${{ steps.profiling-check.outputs.profiling-enabled || false }}
156-
cache-key-files: >-
157-
${{ steps.calc-cache-key-files.outputs.files-hash-key }}
153+
cache-key-for-dep-files: >-
154+
${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }}
158155
git-tag: ${{ steps.git-tag.outputs.tag }}
159156
sdist-artifact-name: ${{ steps.artifact-name.outputs.sdist }}
160157
wheel-artifact-name: ${{ steps.artifact-name.outputs.wheel }}
@@ -225,74 +222,20 @@ jobs:
225222
&& 1 || 0
226223
}}
227224
ref: ${{ github.event.inputs.release-committish }}
228-
- name: >-
229-
Calculate Python interpreter version hash value
230-
for use in the cache key
231-
if: >-
232-
steps.request-check.outputs.release-requested != 'true'
233-
id: calc-cache-key-py
234-
run: |
235-
from hashlib import sha512
236-
from os import environ
237-
from pathlib import Path
238-
from sys import version
239-
240-
FILE_APPEND_MODE = 'a'
241-
242-
hash = sha512(version.encode()).hexdigest()
243-
244-
with Path(environ['GITHUB_OUTPUT']).open(
245-
mode=FILE_APPEND_MODE,
246-
) as outputs_file:
247-
print(f'py-hash-key={hash}', file=outputs_file)
248225
- name: >-
249226
Calculate dependency files' combined hash value
250227
for use in the cache key
251228
if: >-
252229
steps.request-check.outputs.release-requested != 'true'
253230
id: calc-cache-key-files
254-
run: |
255-
from hashlib import sha512
256-
from os import environ
257-
from pathlib import Path
258-
259-
FILE_APPEND_MODE = 'a'
260-
261-
hashes_combo = sha512('-'.join((
262-
"${{ hashFiles('setup.cfg') }}",
263-
"${{ hashFiles('tox.ini')}}",
264-
"${{ hashFiles('pyproject.toml') }}",
265-
"${{ hashFiles('.pre-commit-config.yaml') }}",
266-
"${{ hashFiles('pytest.ini') }}",
267-
"${{ hashFiles('requirements-build.*') }}",
268-
"${{ hashFiles('docs/requirements.*') }}",
269-
)).encode()).hexdigest()
270-
271-
with Path(environ['GITHUB_OUTPUT']).open(
272-
mode=FILE_APPEND_MODE,
273-
) as outputs_file:
274-
print(f"files-hash-key={hashes_combo}", file=outputs_file)
231+
uses: ./.github/actions/cache-keys
275232
- name: Set up pip cache
276233
if: >-
277234
steps.request-check.outputs.release-requested != 'true'
278-
uses: actions/cache@v4
235+
uses: re-actors/cache-python-deps@release/v1
279236
with:
280-
path: >-
281-
${{
282-
runner.os == 'Linux'
283-
&& '~/.cache/pip'
284-
|| '~/Library/Caches/pip'
285-
}}
286-
key: >-
287-
${{ runner.os }}-pip-${{
288-
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
289-
steps.calc-cache-key-files.outputs.files-hash-key }}
290-
restore-keys: |
291-
${{ runner.os }}-pip-${{
292-
steps.calc-cache-key-py.outputs.py-hash-key
293-
}}-
294-
${{ runner.os }}-pip-
295-
${{ runner.os }}-
237+
cache-key-for-dependency-files: >-
238+
${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }}
296239
- name: Drop Git tags from HEAD for non-release requests
297240
if: >-
298241
steps.request-check.outputs.release-requested != 'true'
@@ -415,6 +358,13 @@ jobs:
415358
|| steps.scm-version.outputs.dist-version-for-filenames
416359
}}', file=outputs_file)
417360
361+
lint:
362+
needs:
363+
- pre-setup # transitive, for accessing settings
364+
uses: ./.github/workflows/reusable-linters.yml
365+
with:
366+
cache-key-files: ${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
367+
418368
build-changelog:
419369
name: >-
420370
👷📝 ${{ needs.pre-setup.outputs.git-tag }} changelog
@@ -480,44 +430,11 @@ jobs:
480430
fetch-depth: 1 # Enough for this job to generate the changelog
481431
ref: ${{ github.event.inputs.release-committish }}
482432

483-
- name: >-
484-
Calculate Python interpreter version hash value
485-
for use in the cache key
486-
id: calc-cache-key-py
487-
run: |
488-
from hashlib import sha512
489-
from os import environ
490-
from pathlib import Path
491-
from sys import version
492-
493-
FILE_APPEND_MODE = 'a'
494-
495-
hash = sha512(version.encode()).hexdigest()
496-
497-
with Path(environ['GITHUB_OUTPUT']).open(
498-
mode=FILE_APPEND_MODE,
499-
) as outputs_file:
500-
print(f'py-hash-key={hash}', file=outputs_file)
501-
shell: python
502433
- name: Set up pip cache
503-
uses: actions/cache@v4
434+
uses: re-actors/cache-python-deps@release/v1
504435
with:
505-
path: >-
506-
${{
507-
runner.os == 'Linux'
508-
&& '~/.cache/pip'
509-
|| '~/Library/Caches/pip'
510-
}}
511-
key: >-
512-
${{ runner.os }}-pip-${{
513-
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
514-
needs.pre-setup.outputs.cache-key-files }}
515-
restore-keys: |
516-
${{ runner.os }}-pip-${{
517-
steps.calc-cache-key-py.outputs.py-hash-key
518-
}}-
519-
${{ runner.os }}-pip-
520-
${{ runner.os }}-
436+
cache-key-for-dependency-files: >-
437+
${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
521438
- name: Install tox
522439
run: >-
523440
python -m
@@ -871,44 +788,11 @@ jobs:
871788
git update-index --assume-unchanged $(git ls-files --modified)
872789
shell: bash
873790

874-
- name: >-
875-
Calculate Python interpreter version hash value
876-
for use in the cache key
877-
id: calc-cache-key-py
878-
run: |
879-
from hashlib import sha512
880-
from os import environ
881-
from pathlib import Path
882-
from sys import version
883-
884-
FILE_APPEND_MODE = 'a'
885-
886-
hash = sha512(version.encode()).hexdigest()
887-
888-
with Path(environ['GITHUB_OUTPUT']).open(
889-
mode=FILE_APPEND_MODE,
890-
) as outputs_file:
891-
print(f'py-hash-key={hash}', file=outputs_file)
892-
shell: python
893791
- name: Set up pip cache
894-
uses: actions/cache@v4
792+
uses: re-actors/cache-python-deps@release/v1
895793
with:
896-
path: >-
897-
${{
898-
runner.os == 'Linux'
899-
&& '~/.cache/pip'
900-
|| '~/Library/Caches/pip'
901-
}}
902-
key: >-
903-
${{ runner.os }}-pip-${{
904-
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
905-
needs.pre-setup.outputs.cache-key-files }}
906-
restore-keys: |
907-
${{ runner.os }}-pip-${{
908-
steps.calc-cache-key-py.outputs.py-hash-key
909-
}}-
910-
${{ runner.os }}-pip-
911-
${{ runner.os }}-
794+
cache-key-for-dependency-files: >-
795+
${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
912796
- name: Install tox
913797
run: >-
914798
python -m
@@ -1255,7 +1139,7 @@ jobs:
12551139
release-requested: >-
12561140
${{ needs.pre-setup.outputs.release-requested }}
12571141
yolo: ${{ fromJSON(needs.pre-setup.outputs.is-yolo-mode) }}
1258-
cache-key-files: ${{ needs.pre-setup.outputs.cache-key-files }}
1142+
cache-key-files: ${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
12591143
source-tarball-name: >-
12601144
${{ needs.pre-setup.outputs.sdist-artifact-name }}
12611145
dists-artifact-name: >-
@@ -1290,7 +1174,7 @@ jobs:
12901174
release-requested: >-
12911175
${{ needs.pre-setup.outputs.release-requested }}
12921176
yolo: ${{ fromJSON(needs.pre-setup.outputs.is-yolo-mode) }}
1293-
cache-key-files: ${{ needs.pre-setup.outputs.cache-key-files }}
1177+
cache-key-files: ${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
12941178
source-tarball-name: >-
12951179
${{ needs.pre-setup.outputs.sdist-artifact-name }}
12961180
dists-artifact-name: >-
@@ -1326,44 +1210,11 @@ jobs:
13261210
workflow-artifact-name: >-
13271211
${{ needs.pre-setup.outputs.dists-artifact-name }}
13281212
1329-
- name: >-
1330-
Calculate Python interpreter version hash value
1331-
for use in the cache key
1332-
id: calc-cache-key-py
1333-
run: |
1334-
from hashlib import sha512
1335-
from os import environ
1336-
from pathlib import Path
1337-
from sys import version
1338-
1339-
FILE_APPEND_MODE = 'a'
1340-
1341-
hash = sha512(version.encode()).hexdigest()
1342-
1343-
with Path(environ['GITHUB_OUTPUT']).open(
1344-
mode=FILE_APPEND_MODE,
1345-
) as outputs_file:
1346-
print(f'py-hash-key={hash}', file=outputs_file)
1347-
shell: python
13481213
- name: Set up pip cache
1349-
uses: actions/cache@v4
1214+
uses: re-actors/cache-python-deps@release/v1
13501215
with:
1351-
path: >-
1352-
${{
1353-
runner.os == 'Linux'
1354-
&& '~/.cache/pip'
1355-
|| '~/Library/Caches/pip'
1356-
}}
1357-
key: >-
1358-
${{ runner.os }}-pip-${{
1359-
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
1360-
needs.pre-setup.outputs.cache-key-files }}
1361-
restore-keys: |
1362-
${{ runner.os }}-pip-${{
1363-
steps.calc-cache-key-py.outputs.py-hash-key
1364-
}}-
1365-
${{ runner.os }}-pip-
1366-
${{ runner.os }}-
1216+
cache-key-for-dependency-files: >-
1217+
${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
13671218
- name: Install tox
13681219
run: >-
13691220
python -m
@@ -1830,44 +1681,11 @@ jobs:
18301681
uses: actions/[email protected]
18311682
with:
18321683
python-version: 3.11
1833-
- name: >-
1834-
Calculate Python interpreter version hash value
1835-
for use in the cache key
1836-
id: calc-cache-key-py
1837-
run: |
1838-
from hashlib import sha512
1839-
from os import environ
1840-
from pathlib import Path
1841-
from sys import version
1842-
1843-
FILE_APPEND_MODE = 'a'
1844-
1845-
hash = sha512(version.encode()).hexdigest()
1846-
1847-
with Path(environ['GITHUB_OUTPUT']).open(
1848-
mode=FILE_APPEND_MODE,
1849-
) as outputs_file:
1850-
print(f'py-hash-key={hash}', file=outputs_file)
1851-
shell: python
18521684
- name: Set up pip cache
1853-
uses: actions/cache@v4
1685+
uses: re-actors/cache-python-deps@release/v1
18541686
with:
1855-
path: >-
1856-
${{
1857-
runner.os == 'Linux'
1858-
&& '~/.cache/pip'
1859-
|| '~/Library/Caches/pip'
1860-
}}
1861-
key: >-
1862-
${{ runner.os }}-pip-${{
1863-
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
1864-
needs.pre-setup.outputs.cache-key-files }}
1865-
restore-keys: |
1866-
${{ runner.os }}-pip-${{
1867-
steps.calc-cache-key-py.outputs.py-hash-key
1868-
}}-
1869-
${{ runner.os }}-pip-
1870-
${{ runner.os }}-
1687+
cache-key-for-dependency-files: >-
1688+
${{ needs.pre-setup.outputs.cache-key-for-dep-files }}
18711689
- name: Install dumb-pypi dist from PyPI
18721690
run: python -m pip install dumb-pypi --user
18731691
- name: Generate a dumb PyPI website

0 commit comments

Comments
 (0)