Skip to content

Commit a90be24

Browse files
committed
Improve cache usage for prek hooks
Previously we were only using prek cache from canary builds, but since we are starting to use several separate prek runs, it makes sense to install prek hooks only once and store them in cache and reuse even in the same build. This PR removes "only-canary" prek cache preparation - now all builds including all PRs from fork preapare prek cache once and upload them as artifacts - then restoring prek cache for every prek run should be much faster.
1 parent 8d7cc72 commit a90be24

File tree

5 files changed

+36
-79
lines changed

5 files changed

+36
-79
lines changed

.github/actions/install-prek/action.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
skip-prek-hooks:
3232
description: "Skip some prek hooks from installation"
3333
default: ""
34+
save-cache:
35+
description: "Whether to save prek cache"
36+
required: true
3437
platform:
3538
description: 'Platform for the build - linux/amd64 or linux/arm64'
3639
required: true
@@ -61,7 +64,7 @@ runs:
6164
uses: apache/infrastructure-actions/stash/restore@1c35b5ccf8fba5d4c3fdf25a045ca91aa0cbc468
6265
with:
6366
# yamllint disable rule:line-length
64-
key: cache-prek-v6-${{ inputs.platform }}-${{ inputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
67+
key: cache-prek-v6-${{ inputs.platform }}-${{ inputs.python-version }}-${{inputs.skip-prek-hooks}}-${{ hashFiles('.pre-commit-config.yaml') }}
6568
path: /tmp/
6669
id: restore-prek-cache
6770
- name: "Check if prek cache tarball exists"
@@ -91,3 +94,17 @@ runs:
9194
working-directory: ${{ github.workspace }}
9295
env:
9396
SKIP: ${{ inputs.skip-prek-hooks }}
97+
- name: "Prepare .tar file from prek cache"
98+
run: |
99+
tar -C ~ -czf /tmp/cache-prek.tar.gz .cache/prek
100+
shell: bash
101+
if: inputs.save-cache == 'true'
102+
- name: "Save prek cache"
103+
uses: apache/infrastructure-actions/stash/save@1c35b5ccf8fba5d4c3fdf25a045ca91aa0cbc468
104+
with:
105+
# yamllint disable rule:line-length
106+
key: cache-prek-v6-${{ inputs.platform }}-${{ steps.breeze.outputs.host-python-version }}-${{inputs.skip-prek-hooks}}-${{ hashFiles('.pre-commit-config.yaml') }}
107+
path: /tmp/cache-prek.tar.gz
108+
if-no-files-found: 'error'
109+
retention-days: '2'
110+
if: inputs.save-cache == 'true'

.github/workflows/basic-tests.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -183,40 +183,13 @@ jobs:
183183
retention-days: '2'
184184
if: steps.restore-eslint-cache-simple-am-ui.outputs.stash-hit != 'true'
185185

186-
install-prek:
187-
timeout-minutes: 5
188-
name: "Install prek for cache"
189-
runs-on: ${{ fromJSON(inputs.runners) }}
190-
env:
191-
PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
192-
SKIP: ${{ inputs.skip-prek-hooks }}
193-
steps:
194-
- name: "Cleanup repo"
195-
shell: bash
196-
run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*"
197-
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
198-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
199-
with:
200-
persist-credentials: false
201-
- name: "Install Breeze"
202-
uses: ./.github/actions/breeze
203-
id: breeze
204-
- name: "Install prek"
205-
uses: ./.github/actions/install-prek
206-
id: prek
207-
with:
208-
python-version: ${{steps.breeze.outputs.host-python-version}}
209-
skip-prek-hooks: ${{ inputs.skip-prek-hooks }}
210-
platform: ${{ inputs.platform }}
211-
212186
# Those checks are run if no image needs to be built for checks. This is for simple changes that
213187
# Do not touch any of the python code or any of the important files that might require building
214188
# The CI Docker image and they can be run entirely using the prek virtual environments on host
215189
static-checks-basic-checks-only:
216190
timeout-minutes: 30
217191
name: "Static checks: basic checks only"
218192
runs-on: ${{ fromJSON(inputs.runners) }}
219-
needs: install-prek
220193
if: inputs.basic-checks-only == 'true'
221194
steps:
222195
- name: "Cleanup repo"
@@ -238,6 +211,7 @@ jobs:
238211
python-version: ${{ steps.breeze.outputs.host-python-version }}
239212
skip-prek-hooks: ${{ inputs.skip-prek-hooks }}
240213
platform: ${{ inputs.platform }}
214+
save-cache: false
241215
- name: Fetch incoming commit ${{ github.sha }} with its parent
242216
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
243217
with:
@@ -269,7 +243,6 @@ jobs:
269243
timeout-minutes: 45
270244
name: "Upgrade checks"
271245
runs-on: ${{ fromJSON(inputs.runners) }}
272-
needs: install-prek
273246
env:
274247
PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
275248
if: inputs.canary-run == 'true'
@@ -290,9 +263,10 @@ jobs:
290263
uses: ./.github/actions/install-prek
291264
id: prek
292265
with:
293-
python-version: ${{steps.breeze.outputs.host-python-version}}
266+
python-version: ${{ steps.breeze.outputs.host-python-version }}
294267
skip-prek-hooks: ${{ inputs.skip-prek-hooks }}
295268
platform: ${{ inputs.platform }}
269+
save-cache: false
296270
- name: "Autoupdate all prek hooks"
297271
run: prek autoupdate --freeze
298272
- name: "Autoupdate Lucas-C hooks to bleeding edge"

.github/workflows/ci-amd.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ jobs:
167167
env:
168168
PR_LABELS: ${{ steps.source-run-info.outputs.pr-labels }}
169169
GITHUB_CONTEXT: ${{ toJson(github) }}
170+
- name: "Install and cache prek"
171+
uses: ./.github/actions/install-prek
172+
id: prek
173+
with:
174+
python-version: ${{ steps.breeze.outputs.host-python-version }}
175+
skip-prek-hooks: ${{ needs.build-info.outputs.skip-prek-hooks }}
176+
platform: ${{ inputs.platform }}
177+
save-cache: true
170178

171179
run-pin-versions-hook:
172180
name: "Run pin-versions hook"
@@ -184,6 +192,7 @@ jobs:
184192
# octopin needs python 3.11
185193
python-version: "3.11"
186194
platform: "linux/amd64"
195+
save-cache: false
187196
- name: "Run pin-versions"
188197
run: >
189198
prek -c .github/.pre-commit-config.yaml --all-files --verbose --hook-stage manual
@@ -201,8 +210,8 @@ jobs:
201210
run-www-tests: ${{needs.build-info.outputs.run-www-tests}}
202211
run-api-codegen: ${{needs.build-info.outputs.run-api-codegen}}
203212
default-python-version: "${{ needs.build-info.outputs.default-python-version }}"
204-
basic-checks-only: ${{needs.build-info.outputs.basic-checks-only}}
205-
skip-prek-hooks: ${{needs.build-info.outputs.skip-prek-hooks}}
213+
basic-checks-only: ${{ needs.build-info.outputs.basic-checks-only }}
214+
skip-prek-hooks: ${{ needs.build-info.outputs.skip-prek-hooks }}
206215
canary-run: ${{needs.build-info.outputs.canary-run}}
207216
latest-versions-only: ${{needs.build-info.outputs.latest-versions-only}}
208217
use-uv: ${{needs.build-info.outputs.use-uv}}

.github/workflows/ci-arm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ jobs:
170170
run-www-tests: ${{needs.build-info.outputs.run-www-tests}}
171171
run-api-codegen: ${{needs.build-info.outputs.run-api-codegen}}
172172
default-python-version: "${{ needs.build-info.outputs.default-python-version }}"
173-
basic-checks-only: ${{needs.build-info.outputs.basic-checks-only}}
174-
skip-prek-hooks: ${{needs.build-info.outputs.skip-prek-hooks}}
173+
basic-checks-only: ${{ needs.build-info.outputs.basic-checks-only }}
174+
skip-prek-hooks: ${{ needs.build-info.outputs.skip-prek-hooks }}
175175
canary-run: ${{needs.build-info.outputs.canary-run}}
176176
latest-versions-only: ${{needs.build-info.outputs.latest-versions-only}}
177177
use-uv: ${{needs.build-info.outputs.use-uv}}

.github/workflows/ci-image-checks.yml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -122,54 +122,10 @@ on: # yamllint disable-line rule:truthy
122122
permissions:
123123
contents: read
124124
jobs:
125-
install-prek:
126-
timeout-minutes: 5
127-
name: "Install prek for cache (only canary runs)"
128-
runs-on: ${{ fromJSON(inputs.runners) }}
129-
env:
130-
PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
131-
if: inputs.basic-checks-only == 'false'
132-
steps:
133-
- name: "Cleanup repo"
134-
shell: bash
135-
run: docker run -v "${GITHUB_WORKSPACE}:/workspace" -u 0:0 bash -c "rm -rf /workspace/*"
136-
if: inputs.canary-run == 'true'
137-
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
138-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
139-
with:
140-
persist-credentials: false
141-
if: inputs.canary-run == 'true'
142-
- name: "Install Breeze"
143-
uses: ./.github/actions/breeze
144-
id: breeze
145-
if: inputs.canary-run == 'true'
146-
- name: "Install prek"
147-
uses: ./.github/actions/install-prek
148-
id: prek
149-
with:
150-
python-version: ${{steps.breeze.outputs.host-python-version}}
151-
platform: ${{ inputs.platform }}
152-
if: inputs.canary-run == 'true'
153-
- name: "Prepare .tar file from prek cache"
154-
run: |
155-
tar -C ~ -czf /tmp/cache-prek.tar.gz .cache/prek
156-
shell: bash
157-
if: inputs.canary-run == 'true'
158-
- name: "Save prek cache"
159-
uses: apache/infrastructure-actions/stash/save@1c35b5ccf8fba5d4c3fdf25a045ca91aa0cbc468
160-
with:
161-
# yamllint disable rule:line-length
162-
key: cache-prek-v6-${{ inputs.platform }}-${{ steps.breeze.outputs.host-python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
163-
path: /tmp/cache-prek.tar.gz
164-
if-no-files-found: 'error'
165-
retention-days: '2'
166-
if: inputs.canary-run == 'true'
167-
168125
static-checks:
169126
timeout-minutes: 45
170127
name: "Static checks"
171128
runs-on: ${{ fromJSON(inputs.runners) }}
172-
needs: install-prek
173129
env:
174130
PYTHON_MAJOR_MINOR_VERSION: "${{ inputs.default-python-version }}"
175131
UPGRADE_TO_NEWER_DEPENDENCIES: "${{ inputs.upgrade-to-newer-dependencies }}"
@@ -196,6 +152,7 @@ jobs:
196152
with:
197153
python-version: ${{steps.breeze.outputs.host-python-version}}
198154
platform: ${{ inputs.platform }}
155+
save-cache: false
199156
- name: "Static checks"
200157
run: prek --all-files --show-diff-on-failure --color always
201158
env:
@@ -210,7 +167,6 @@ jobs:
210167
timeout-minutes: 45
211168
name: "MyPy checks"
212169
runs-on: ${{ fromJSON(inputs.runners) }}
213-
needs: install-prek
214170
if: inputs.run-mypy == 'true'
215171
strategy:
216172
fail-fast: false
@@ -240,6 +196,7 @@ jobs:
240196
with:
241197
python-version: ${{steps.breeze.outputs.host-python-version}}
242198
platform: ${{ inputs.platform }}
199+
save-cache: false
243200
- name: "MyPy checks for ${{ matrix.mypy-check }}"
244201
run: prek --color always --verbose --hook-stage manual "$MYPY_CHECK" --all-files
245202
env:

0 commit comments

Comments
 (0)