MCPcopy Create free account
hub / github.com/github/gh-aw / main

Function main

actions/setup/js/cleanup_cache_memory.cjs:172–302  ·  view source on GitHub ↗

* Main entry point: cleanup outdated cache-memory caches. * * Lists all caches with "memory-" prefix, groups them by key prefix, * keeps the latest run ID per group, and deletes the rest. * Includes timeouts to avoid GitHub API throttling and skips * if rate limiting is too high. * * @param {

(options = {})

Source from the content-addressed store, hash-verified

170 * @param {number} [options.listDelayMs] - Delay between list pages (default: LIST_DELAY_MS)
171 */
172async function main(options = {}) {
173 const deleteDelayMs = options.deleteDelayMs ?? DELETE_DELAY_MS;
174 const listDelayMs = options.listDelayMs ?? LIST_DELAY_MS;
175
176 const owner = context.repo.owner;
177 const repo = context.repo.repo;
178
179 core.info("🧹 Starting cache-memory cleanup");
180 core.info(` Repository: ${owner}/${repo}`);
181
182 // Log initial rate limit snapshot for observability
183 await fetchAndLogRateLimit(github, "cleanup_cache_memory_start");
184
185 // Check rate limit before starting
186 const { ok: rateLimitOk, remaining: initialRemaining } = await checkRateLimit(github, "cleanup_cache_memory_initial");
187 if (!rateLimitOk) {
188 core.warning(`⚠️ Rate limit too low (${initialRemaining} remaining, minimum: ${MIN_RATE_LIMIT_REMAINING}). Skipping cache cleanup.`);
189 core.summary.addRaw(`## Cache Memory Cleanup\n\n⚠️ Skipped: Rate limit too low (${initialRemaining} remaining, minimum required: ${MIN_RATE_LIMIT_REMAINING})\n`);
190 await core.summary.write();
191 return;
192 }
193
194 core.info(` Rate limit remaining: ${initialRemaining === -1 ? "unknown" : initialRemaining}`);
195
196 // List all memory caches
197 core.info("📋 Listing caches with 'memory-' prefix...");
198 let caches;
199 try {
200 caches = await listMemoryCaches(github, owner, repo, listDelayMs);
201 } catch (error) {
202 core.error(`❌ Failed to list caches: ${getErrorMessage(error)}`);
203 core.summary.addRaw(`## Cache Memory Cleanup\n\n❌ Failed to list caches: ${getErrorMessage(error)}\n`);
204 await core.summary.write();
205 return;
206 }
207
208 core.info(` Found ${caches.length} cache(s) with 'memory-' prefix`);
209
210 if (caches.length === 0) {
211 core.info("✅ No memory caches found. Nothing to clean up.");
212 core.summary.addRaw("## Cache Memory Cleanup\n\n✅ No memory caches found. Nothing to clean up.\n");
213 await core.summary.write();
214 return;
215 }
216
217 // Identify which caches to delete
218 const { toDelete, kept } = identifyCachesToDelete(caches);
219
220 core.info(` Groups with latest entries kept: ${kept.length}`);
221 for (const entry of kept) {
222 core.info(` ✓ Keeping: ${entry.key} (run ID: ${entry.runId})`);
223 }
224 core.info(` Outdated entries to delete: ${toDelete.length}`);
225
226 if (toDelete.length === 0) {
227 core.info("✅ No outdated caches to clean up. All entries are current.");
228 core.summary.addRaw(`## Cache Memory Cleanup\n\n✅ No outdated caches to clean up.\n- Total memory caches: ${caches.length}\n- Groups: ${kept.length}\n`);
229 await core.summary.write();

Callers

nothing calls this directly

Calls 7

fetchAndLogRateLimitFunction · 0.85
checkRateLimitFunction · 0.85
listMemoryCachesFunction · 0.85
identifyCachesToDeleteFunction · 0.85
errorMethod · 0.80
getErrorMessageFunction · 0.70
delayFunction · 0.70

Tested by

no test coverage detected