@@ -15,15 +15,36 @@ jobs:
15
15
uses : actions/github-script@v7
16
16
with :
17
17
script : |
18
- const retentionDays = 3 ; // Keep caches for 3 days
18
+ const retentionDays = 2 ; // Keep caches for 2 days
19
19
const caches = await github.rest.actions.getActionsCacheList({
20
20
owner: context.repo.owner,
21
21
repo: context.repo.repo
22
22
});
23
23
24
- const now = new Date();
24
+ // Group caches by their prefix pattern (e.g., sccache-Windows-cuda-main)
25
+ const cacheGroups = {};
25
26
for (const cache of caches.data.actions_caches) {
26
27
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];
27
48
const createdAt = new Date(cache.created_at);
28
49
const ageInDays = (now - createdAt) / (1000 * 60 * 60 * 24);
29
50
38
59
console.log(`Keeping cache: ${cache.key}, created ${ageInDays.toFixed(1)} days ago`);
39
60
}
40
61
}
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
+ }
41
70
}
42
71
43
72
warmup-unix :
0 commit comments