From 1b8c9b06082546adfb95f61647d6113fb4bbd5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 20 Nov 2026 16:37:23 +0100 Subject: [PATCH] CI: delete superseded ccache caches and fix shared ccache key in CI-unixish-docker hendrikmuhs/ccache-action saves a new timestamped cache entry on every run without deleting the previous one. These superseded entries took up about half of the 10 GB cache limit, causing other caches (e.g. the cppcheck binary in scriptcheck) to be evicted before they were used. Add a workflow that keeps only the newest ccache entry per key. The build_cmake and build_make jobs in CI-unixish-docker used the same ccache key and overwrote each other's caches. Include the job name in the key. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI-unixish-docker.yml | 4 +- .github/workflows/ccache-cleanup.yml | 63 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ccache-cleanup.yml diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index a1c36fa9c72..944d4340ac0 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -68,7 +68,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1.2.24 with: - key: ${{ github.workflow }}-${{ matrix.image }} + key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.image }} # only save cache in main/release branches, PRs restore the cache of the base branch save: ${{ github.event_name != 'pull_request' }} @@ -118,7 +118,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1.2.24 with: - key: ${{ github.workflow }}-${{ matrix.image }} + key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.image }} # only save cache in main/release branches, PRs restore the cache of the base branch save: ${{ github.event_name != 'pull_request' }} diff --git a/.github/workflows/ccache-cleanup.yml b/.github/workflows/ccache-cleanup.yml new file mode 100644 index 00000000000..63a2f8eb322 --- /dev/null +++ b/.github/workflows/ccache-cleanup.yml @@ -0,0 +1,63 @@ +# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions +# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners +name: ccache-cleanup + +# hendrikmuhs/ccache-action saves a new cache entry with a timestamp suffix on every run but never +# deletes the previous ones. Only the newest entry is ever restored, so the superseded ones just take +# up space and push the repository over the cache size limit, which causes other caches to be evicted. + +on: + workflow_run: + workflows: + - CI-mingw + - CI-unixish + - CI-unixish-docker + - Coverage + - corpus + - sanitizers + - scriptcheck + - selfcheck + - valgrind + types: + - completed + schedule: + - cron: '0 3 * * *' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ccache-cleanup + cancel-in-progress: false + +jobs: + cleanup: + + # pull requests do not save ccache caches + if: github.event_name != 'workflow_run' || github.event.workflow_run.event != 'pull_request' + + runs-on: ubuntu-24.04 + + permissions: + actions: write + + steps: + - name: Delete superseded ccache caches + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + # list all ccache entries, group them by ref and key without the timestamp suffix and keep only the newest of each group + gh api --paginate "repos/$REPO/actions/caches?key=ccache-&per_page=100" --jq '.actions_caches[]' | + jq -s -r ' + map(. + {prefix: (.key | sub("-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:.]+Z$"; ""))}) + | group_by([.ref, .prefix])[] + | sort_by(.created_at) | .[:-1][] + | "\(.id) \(.size_in_bytes) \(.ref) \(.key)"' > superseded.txt + echo "superseded ccache caches: $(wc -l < superseded.txt)" + while read -r id size ref key; do + echo "deleting $key ($ref, $((size / 1048576)) MiB)" + # the cache might already have been deleted or evicted + gh api -X DELETE "repos/$REPO/actions/caches/$id" || true + done < superseded.txt