Skip to content

Commit 41e5825

Browse files
authored
Add pre-commit caching and fix poetry extras cache (#817)
Caching pre-commit halves the linting time and the `action/setup-python` cache does not handle `--extras` [properly ](actions/setup-python#505) so switching to action/cache for the poetry cache
1 parent 063518b commit 41e5825

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@ jobs:
2222
- name: Install poetry
2323
run: pipx install poetry
2424
- uses: "actions/setup-python@v5"
25+
id: setup-python
2526
with:
2627
python-version: "${{ matrix.python-version }}"
2728
cache: 'poetry'
2829
- name: "Install dependencies"
2930
run: |
3031
poetry install
32+
- name: Read pre-commit version
33+
id: pre-commit-version
34+
run: >-
35+
echo "PRE_COMMIT_VERSION=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
36+
- uses: actions/cache@v3
37+
with:
38+
path: ~/.cache/pre-commit/
39+
key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.PRE_COMMIT_VERSION }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
3140
- name: "Check supported device md files are up to date"
3241
run: |
3342
poetry run pre-commit run generate-supported --all-files
@@ -91,9 +100,19 @@ jobs:
91100
- name: Install poetry
92101
run: pipx install poetry
93102
- uses: "actions/setup-python@v5"
103+
id: setup-python
94104
with:
95105
python-version: "${{ matrix.python-version }}"
96-
cache: 'poetry'
106+
- name: Read poetry cache location
107+
id: poetry-cache-location
108+
shell: bash
109+
run: |
110+
echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
111+
- uses: actions/cache@v3
112+
with:
113+
path: |
114+
${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }}
115+
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-extras-${{ matrix.extras }}
97116
- name: "Install dependencies (no extras)"
98117
if: matrix.extras == false
99118
run: |

0 commit comments

Comments
 (0)