From a6d35b905248eed0941bb85a49f180eaa4e89afb Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Thu, 6 Aug 2026 20:14:12 +0200 Subject: [PATCH] Optimize cache for `pre-commit` workflow --- .github/workflows/pre-commit.yml | 5 ++++ .github/workflows/warm-cache.yml | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/warm-cache.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index e119bbb14..4aa780332 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -7,6 +7,7 @@ permissions: {} env: # Forks and Dependabot don't have access to secrets HAS_SECRETS: ${{ secrets.PRE_COMMIT != '' }} + UV_NO_SYNC: true jobs: pre-commit: @@ -48,6 +49,10 @@ jobs: # Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum. # See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837 version: "0.11.18" + cache-suffix: dev-all + # Cache written by workflow triggered by pull_request is PR-scoped and almost useless. + # Disable saving here, it will be populated by `warm-cache.yml`. + save-cache: false cache-dependency-glob: | pyproject.toml uv.lock diff --git a/.github/workflows/warm-cache.yml b/.github/workflows/warm-cache.yml new file mode 100644 index 000000000..bf3a38ba4 --- /dev/null +++ b/.github/workflows/warm-cache.yml @@ -0,0 +1,43 @@ +name: Warm Cache + +# Populates the `dev-all` uv cache at default-branch scope so that it could be used by +# `pre-commit.yml` (it has `pull_request` trigger and can't write cache available across PRs) +# and some others that use subset of dev dependencies. + +on: + push: + branches: + - master + schedule: + - cron: "0 4 * * *" + workflow_dispatch: + +permissions: {} + +jobs: + warm-cache: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version-file: ".python-version" + - name: Setup uv + id: setup-uv + uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0 + with: + # Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum. + # See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837 + version: "0.11.18" + enable-cache: true + cache-suffix: dev-all + cache-dependency-glob: | + pyproject.toml + uv.lock + - name: Populate the cache + if: steps.setup-uv.outputs.cache-hit != 'true' + run: uv sync --locked --extra all