Skip to content

Commit ba89fed

Browse files
authored
CI: delete superseded ccache caches and fix shared ccache key in CI-unixish-docker (#9054)
1 parent f6a3db0 commit ba89fed

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

‎.github/workflows/CI-unixish-docker.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: ccache
6969
uses: hendrikmuhs/ccache-action@v1.2.24
7070
with:
71-
key: ${{ github.workflow }}-${{ matrix.image }}
71+
key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.image }}
7272
# only save cache in main/release branches, PRs restore the cache of the base branch
7373
save: ${{ github.event_name != 'pull_request' }}
7474

@@ -118,7 +118,7 @@ jobs:
118118
- name: ccache
119119
uses: hendrikmuhs/ccache-action@v1.2.24
120120
with:
121-
key: ${{ github.workflow }}-${{ matrix.image }}
121+
key: ${{ github.workflow }}-${{ github.job }}-${{ matrix.image }}
122122
# only save cache in main/release branches, PRs restore the cache of the base branch
123123
save: ${{ github.event_name != 'pull_request' }}
124124

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
3+
name: ccache-cleanup
4+
5+
# hendrikmuhs/ccache-action saves a new cache entry with a timestamp suffix on every run but never
6+
# deletes the previous ones. Only the newest entry is ever restored, so the superseded ones just take
7+
# up space and push the repository over the cache size limit, which causes other caches to be evicted.
8+
9+
on:
10+
workflow_run:
11+
workflows:
12+
- CI-mingw
13+
- CI-unixish
14+
- CI-unixish-docker
15+
- Coverage
16+
- corpus
17+
- sanitizers
18+
- scriptcheck
19+
- selfcheck
20+
- valgrind
21+
types:
22+
- completed
23+
schedule:
24+
- cron: '0 3 * * *'
25+
workflow_dispatch:
26+
27+
permissions:
28+
contents: read
29+
30+
concurrency:
31+
group: ccache-cleanup
32+
cancel-in-progress: false
33+
34+
jobs:
35+
cleanup:
36+
37+
# pull requests do not save ccache caches
38+
if: github.event_name != 'workflow_run' || github.event.workflow_run.event != 'pull_request'
39+
40+
runs-on: ubuntu-24.04
41+
42+
permissions:
43+
actions: write
44+
45+
steps:
46+
- name: Delete superseded ccache caches
47+
env:
48+
GH_TOKEN: ${{ github.token }}
49+
REPO: ${{ github.repository }}
50+
run: |
51+
# list all ccache entries, group them by ref and key without the timestamp suffix and keep only the newest of each group
52+
gh api --paginate "repos/$REPO/actions/caches?key=ccache-&per_page=100" --jq '.actions_caches[]' |
53+
jq -s -r '
54+
map(. + {prefix: (.key | sub("-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9:.]+Z$"; ""))})
55+
| group_by([.ref, .prefix])[]
56+
| sort_by(.created_at) | .[:-1][]
57+
| "\(.id) \(.size_in_bytes) \(.ref) \(.key)"' > superseded.txt
58+
echo "superseded ccache caches: $(wc -l < superseded.txt)"
59+
while read -r id size ref key; do
60+
echo "deleting $key ($ref, $((size / 1048576)) MiB)"
61+
# the cache might already have been deleted or evicted
62+
gh api -X DELETE "repos/$REPO/actions/caches/$id" || true
63+
done < superseded.txt

0 commit comments

Comments
 (0)