Skip to content

Commit bbb0a9a

Browse files
committed
Actions: Fix caching by busting
If a cache with a key exists, it does not get overwritten. Instead, implement a cache eviction strategy to keep entries for 3 days. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
1 parent 7447231 commit bbb0a9a

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

.github/workflows/build.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ jobs:
5555
uses: actions/cache@v4
5656
with:
5757
path: ${{ env.SCCACHE_DIR }}
58-
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}
58+
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
5959
restore-keys: |
60+
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
6061
sccache-${{ runner.os }}-${{ matrix.device }}-
6162
- name: Get short SHA
6263
id: sha
@@ -162,8 +163,9 @@ jobs:
162163
uses: actions/cache@v4
163164
with:
164165
path: ${{ env.SCCACHE_DIR }}
165-
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}
166+
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
166167
restore-keys: |
168+
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
167169
sccache-${{ runner.os }}-${{ matrix.device }}-
168170
- name: Get short SHA
169171
id: sha

.github/workflows/warmup.yml

+41-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,42 @@ on:
66
workflow_dispatch:
77

88
jobs:
9+
cleanup-cache:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
actions: write
13+
steps:
14+
- name: Cleanup old caches
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const retentionDays = 3; // Keep caches for 3 days
19+
const caches = await github.rest.actions.getActionsCacheList({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo
22+
});
23+
24+
const now = new Date();
25+
for (const cache of caches.data.actions_caches) {
26+
if (cache.key.startsWith('sccache-')) {
27+
const createdAt = new Date(cache.created_at);
28+
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
29+
30+
if (ageInDays > retentionDays) {
31+
console.log(`Deleting old cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
32+
await github.rest.actions.deleteActionsCacheByKey({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
key: cache.key
36+
});
37+
} else {
38+
console.log(`Keeping cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
39+
}
40+
}
41+
}
42+
943
warmup-unix:
44+
needs: cleanup-cache
1045
runs-on: ${{ matrix.os }}
1146
strategy:
1247
matrix:
@@ -38,11 +73,13 @@ jobs:
3873
uses: actions/cache@v4
3974
with:
4075
path: ${{ env.SCCACHE_DIR }}
41-
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}
76+
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
4277
restore-keys: |
43-
sccache-${{ runner.os }}-${{ matrix.device }}-
78+
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
79+
sccache-${{ runner.os }}-${{ matrix.device }}-
4480
4581
warmup-win:
82+
needs: cleanup-cache
4683
runs-on: ${{ matrix.os }}
4784
strategy:
4885
matrix:
@@ -62,6 +99,7 @@ jobs:
6299
uses: actions/cache@v4
63100
with:
64101
path: ${{ env.SCCACHE_DIR }}
65-
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}
102+
key: sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-${{ github.run_id }}
66103
restore-keys: |
104+
sccache-${{ runner.os }}-${{ matrix.device }}-${{ github.ref_name }}-
67105
sccache-${{ runner.os }}-${{ matrix.device }}-

0 commit comments

Comments
 (0)