Restrict TRAP cache cleanup to analyzed language
This commit is contained in:
parent
cc96c825ba
commit
087f0b04c6
5 changed files with 48 additions and 21 deletions
28
lib/trap-caching.js
generated
28
lib/trap-caching.js
generated
|
|
@ -132,19 +132,29 @@ async function uploadTrapCaches(codeql, config, logger) {
|
|||
return true;
|
||||
}
|
||||
exports.uploadTrapCaches = uploadTrapCaches;
|
||||
async function cleanupTrapCaches(logger) {
|
||||
const event = actionsUtil.getWorkflowEvent();
|
||||
const defaultBranch = event?.repository?.default_branch;
|
||||
if (!defaultBranch) {
|
||||
logger.info("Could not determine default branch, skipping TRAP cache cleanup");
|
||||
return;
|
||||
async function cleanupTrapCaches(language, logger) {
|
||||
try {
|
||||
const matchingCaches = await getTrapCachesForLanguage(language);
|
||||
for (const cache of matchingCaches) {
|
||||
logger.info(`Matched Actions cache ${JSON.stringify(cache)}`);
|
||||
}
|
||||
}
|
||||
const matchingCaches = await apiClient.listActionsCaches(CODEQL_TRAP_CACHE_PREFIX, defaultBranch);
|
||||
for (const cache of matchingCaches) {
|
||||
logger.info(`Matched Actions cache ${JSON.stringify(cache)}`);
|
||||
catch (e) {
|
||||
logger.info(`Failed to cleanup trap caches, continuing. Details: ${e}`);
|
||||
}
|
||||
}
|
||||
exports.cleanupTrapCaches = cleanupTrapCaches;
|
||||
async function getTrapCachesForLanguage(language) {
|
||||
const event = actionsUtil.getWorkflowEvent();
|
||||
const defaultBranch = event?.repository?.default_branch;
|
||||
if (!defaultBranch) {
|
||||
throw new Error("Could not determine default branch");
|
||||
}
|
||||
const allCaches = await apiClient.listActionsCaches(CODEQL_TRAP_CACHE_PREFIX, defaultBranch);
|
||||
return allCaches.filter((cache) => {
|
||||
return cache.key?.includes(`-${language}-`);
|
||||
});
|
||||
}
|
||||
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||
const result = [];
|
||||
const resolveResult = await codeql.betterResolveLanguages();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue