@@ -122,36 +122,42 @@ jobs:
122
122
}
123
123
*/
124
124
125
- const ref = "${{ github.event.pull_request.number || github.ref }}";
126
- const cacheKeysPattern = `tests-bin-${ref}-`;
127
-
128
- console.log(`Deleting caches matching pattern: ${cacheKeysPattern}`);
125
+ const sha = '${{ github.event.pull_request.head.sha || github.sha }}';
126
+ const pr = '${{ github.event.pull_request.number }}';
127
+ if (pr) {
128
+ ref = "refs/pull/" + pr + "/merge";
129
+ } else {
130
+ ref = '${{ github.ref }}';
131
+ }
129
132
130
133
// Fetch all cache entries for the repository
131
134
const caches = await github.paginate(github.rest.actions.getActionsCacheList, {
132
135
owner: context.repo.owner,
133
136
repo: context.repo.repo,
134
137
per_page: 100,
135
- key: cacheKeysPattern + '*'
138
+ ref: ref
136
139
});
137
140
141
+ console.log(caches);
142
+
138
143
if (caches.data) {
139
144
console.log(`Found ${caches.data.actions_caches.length} caches.`);
140
- console.log(caches.data.actions_caches.map(cache => cache.key));
141
- // Filter caches matching the specified pattern
142
- const matchingCaches = caches.data.actions_caches.filter(cache =>
143
- cache.key.startsWith(cacheKeysPattern)
144
- );
145
145
146
146
// Delete matching caches
147
147
for (const cache of matchingCaches) {
148
+ if (cache.key.endsWith(sha)) {
149
+ console.log(`Skipping cache with key: ${cache.key}`);
150
+ continue;
151
+ } else {
152
+ console.log(`Deleting cache with key: ${cache.key}`);
153
+ }
154
+
148
155
/*
149
156
await github.rest.actions.deleteActionsCacheById({
150
157
owner: context.repo.owner,
151
158
repo: context.repo.repo,
152
159
cache_id: cache.id
153
160
});
154
161
*/
155
- console.log(`Deleted cache with key: ${cache.key}`);
156
162
}
157
163
}
0 commit comments