Skip to content

Bump github/codeql-action from 3.28.17 to 3.29.7 #366

Bump github/codeql-action from 3.28.17 to 3.29.7

Bump github/codeql-action from 3.28.17 to 3.29.7 #366

Workflow file for this run

name: Cache Clean
on:
workflow_dispatch:
inputs:
all-branches:
type: boolean
description: "Delete caches for all branches (nuclear option)"
pull_request:
types:
- closed
permissions:
actions: write
jobs:
clear-cache:
runs-on: ubuntu-latest
steps:
- name: Delete caches
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
let totalDeleted = 0;
let totalBytes = 0;
let pageSize = 100;
let inputs = context.payload.inputs;
let ref = context.ref;
if (inputs && inputs["all-branches"] == "true") {
console.warn("Deleting caches for all branches");
ref = undefined;
}
function sizeInMb(size) {
return (size / 1024 / 1024).toFixed(2);
}
async function fetchCaches(params) {
return github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
...params
});
}
async function fetchAllCaches(ref) {
let currentPage = 1;
let currentCaches = await fetchCaches({ per_page: pageSize, page: currentPage, ref: ref });
let totalCount = currentCaches.data.total_count;
let allCaches = currentCaches.data.actions_caches;
console.log(`Found ${totalCount} caches for ref ${ref} (page ${currentPage} of ${Math.ceil(totalCount / pageSize)})`);
while (true) {
if (allCaches.length >= totalCount || currentPage > 100) {
break;
} else {
currentPage++;
currentCaches = await fetchCaches({ per_page: pageSize, page: currentPage, ref: ref });
allCaches = allCaches.concat(currentCaches.data.actions_caches);
}
}
return allCaches;
}
async function deleteCachesForRef(ref) {
let caches = await fetchAllCaches(ref);
for (let cache of caches) {
totalDeleted++;
totalBytes += cache.size_in_bytes;
try {
await github.rest.actions.deleteActionsCacheByKey({
owner: context.repo.owner,
repo: context.repo.repo,
key: cache.key,
ref: cache.ref
});
console.log(`Deleted cache ${cache.key} (${sizeInMb(cache.size_in_bytes)} MB) for ref ${cache.ref}`);
} catch (error) {
console.warn(`Error deleting cache by key: ${error.message}. Attempting alternative method...`);
try {
await github.rest.actions.deleteActionsCacheByKey({
owner: context.repo.owner,
repo: context.repo.repo,
key: cache.key
});
console.log(`Deleted cache ${cache.key} (${sizeInMb(cache.size_in_bytes)} MB) without ref parameter`);
} catch (secondError) {
console.error(`Failed to delete cache ${cache.key}: ${secondError.message}`);
}
}
}
}
await deleteCachesForRef(ref);
let totalMb = sizeInMb(totalBytes);
console.log(`Clear completed, deleted ${totalDeleted} caches (${totalMb} MB)`);