From a5548fbf8bdb162a292efca8003fa1e5d736a9c3 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Fri, 30 Oct 2026 06:12:31 +0100 Subject: [PATCH] ci: keep a single ccache entry per job The ccache was saved under a key with the commit sha, so every push to main added an entry per job and the caches filled the quota of the repository (10.4 GB used of 10), which gets the oldest ones evicted. Save under a stable key instead: the new save-ccache action deletes the previous entry and saves again. The old per-sha entries are still used as fallback by the restore, and they go away by themselves. Co-Authored-By: Claude Sonnet 5.5 --- .github/actions/save-ccache/action.yml | 29 ++++++++++++++++++++++++++ .github/workflows/build-deb.yml | 10 ++++----- .github/workflows/build-macos.yml | 10 ++++----- .github/workflows/build-windows.yml | 10 ++++----- .github/workflows/test.yml | 28 ++++++++++++------------- 5 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 .github/actions/save-ccache/action.yml diff --git a/.github/actions/save-ccache/action.yml b/.github/actions/save-ccache/action.yml new file mode 100644 index 0000000..c2f1c43 --- /dev/null +++ b/.github/actions/save-ccache/action.yml @@ -0,0 +1,29 @@ +name: Save ccache +description: > + Replaces the cache stored under the key instead of adding an entry per commit, so the + caches of the repository stay below its quota. The job needs the actions: write permission. + +inputs: + key: + description: Cache key, the same one given to actions/cache/restore + required: true + path: + description: Directory of the ccache + default: .ccache + +runs: + using: composite + steps: + - name: Delete the previous cache + shell: bash + env: + GH_TOKEN: ${{ github.token }} + CACHE_KEY: ${{ inputs.key }} + # cache keys are immutable, there is nothing to delete the first time + run: gh cache delete "$CACHE_KEY" --repo "$GITHUB_REPOSITORY" || true + + - name: Save the cache + uses: actions/cache/save@v4 + with: + path: ${{ inputs.path }} + key: ${{ inputs.key }} diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index 44ea14a..d4d29a8 100644 --- a/.github/workflows/build-deb.yml +++ b/.github/workflows/build-deb.yml @@ -21,6 +21,7 @@ concurrency: permissions: contents: read + actions: write # replace the ccache entries jobs: build: @@ -130,7 +131,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-deb-${{ matrix.name }}-${{ matrix.arch }}_${{ github.sha }} + key: ccache-deb-${{ matrix.name }}-${{ matrix.arch }} restore-keys: | ccache-deb-${{ matrix.name }}-${{ matrix.arch }}_ @@ -156,12 +157,11 @@ jobs: bash -euxc "./docker/build.sh" - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-deb-${{ matrix.name }}-${{ matrix.arch }}_${{ github.sha }} + key: ccache-deb-${{ matrix.name }}-${{ matrix.arch }} - name: Upload deb package uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index ffce175..002726a 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -18,6 +18,7 @@ concurrency: permissions: contents: read + actions: write # replace the ccache entries jobs: build: @@ -65,7 +66,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-${{ matrix.os }}_${{ github.sha }} + key: ccache-${{ matrix.os }} restore-keys: | ccache-${{ matrix.os }}_ @@ -105,12 +106,11 @@ jobs: run: ccache --show-stats - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-${{ matrix.os }}_${{ github.sha }} + key: ccache-${{ matrix.os }} - name: Repair wheel with delocate run: | diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 979baf7..3f6446e 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -18,6 +18,7 @@ concurrency: permissions: contents: read + actions: write # replace the ccache entries jobs: msys2-mingw64: @@ -149,7 +150,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-windows_${{ github.sha }} + key: ccache-windows restore-keys: | ccache-windows_ @@ -194,12 +195,11 @@ jobs: run: ccache --show-stats - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-windows_${{ github.sha }} + key: ccache-windows - name: Repair wheel with delvewheel run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 792dc67..ce7e72f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ concurrency: permissions: contents: read + actions: write # replace the ccache entries jobs: linux: @@ -79,7 +80,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-linux-test_${{ github.sha }} + key: ccache-linux-test restore-keys: | ccache-linux-test_ @@ -120,12 +121,11 @@ jobs: run: ccache --show-stats - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-linux-test_${{ github.sha }} + key: ccache-linux-test - name: Setup test environment run: | @@ -333,7 +333,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-windows_${{ github.sha }} + key: ccache-windows restore-keys: | ccache-windows_ @@ -386,12 +386,11 @@ jobs: run: ccache --show-stats - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-windows_${{ github.sha }} + key: ccache-windows - name: Run unit tests shell: bash @@ -443,7 +442,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .ccache - key: ccache-${{ matrix.os }}_${{ github.sha }} + key: ccache-${{ matrix.os }} restore-keys: | ccache-${{ matrix.os }}_ @@ -483,12 +482,11 @@ jobs: run: ccache --show-stats - name: Save ccache - # Pull requests only read the cache, pushes to main and manual runs populate it. + # Pull requests only read the cache, pushes to main and manual runs replace it. if: ${{ !cancelled() && github.event_name != 'pull_request' }} - uses: actions/cache/save@v4 + uses: ./.github/actions/save-ccache with: - path: .ccache - key: ccache-${{ matrix.os }}_${{ github.sha }} + key: ccache-${{ matrix.os }} - name: Run unit tests run: |