Skip to content

Commit 74bd68c

Browse files
committed
Actions: Keep most recent cache on cleanup
Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
1 parent 584d056 commit 74bd68c

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

.github/workflows/warmup.yml

+31-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,36 @@ jobs:
1515
uses: actions/github-script@v7
1616
with:
1717
script: |
18-
const retentionDays = 3; // Keep caches for 3 days
18+
const retentionDays = 2; // Keep caches for 2 days
1919
const caches = await github.rest.actions.getActionsCacheList({
2020
owner: context.repo.owner,
2121
repo: context.repo.repo
2222
});
2323
24-
const now = new Date();
24+
// Group caches by their prefix pattern (e.g., sccache-Windows-cuda-main)
25+
const cacheGroups = {};
2526
for (const cache of caches.data.actions_caches) {
2627
if (cache.key.startsWith('sccache-')) {
28+
// Extract the prefix pattern (everything before the last hyphen + timestamp)
29+
const prefixPattern = cache.key.replace(/-\d+$/, '');
30+
31+
if (!cacheGroups[prefixPattern]) {
32+
cacheGroups[prefixPattern] = [];
33+
}
34+
cacheGroups[prefixPattern].push(cache);
35+
}
36+
}
37+
38+
const now = new Date();
39+
// Process each group of caches
40+
for (const prefix in cacheGroups) {
41+
// Sort caches by creation date (newest first)
42+
const sortedCaches = cacheGroups[prefix].sort((a, b) =>
43+
new Date(b.created_at) - new Date(a.created_at));
44+
45+
// Skip the most recent cache
46+
for (let i = 1; i < sortedCaches.length; i++) {
47+
const cache = sortedCaches[i];
2748
const createdAt = new Date(cache.created_at);
2849
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
2950
@@ -38,6 +59,14 @@ jobs:
3859
console.log(`Keeping cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
3960
}
4061
}
62+
63+
// Always log the kept most recent cache
64+
if (sortedCaches.length > 0) {
65+
const newestCache = sortedCaches[0];
66+
const createdAt = new Date(newestCache.created_at);
67+
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
68+
console.log(`Keeping most recent cache: ${newestCache.key}, created ${ageInDays.toFixed(1)} days ago`);
69+
}
4170
}
4271
4372
warmup-unix:

0 commit comments

Comments
 (0)