Path: blob/trunk/scripts/github-actions/prune-codeql-caches.sh
10192 views
#!/usr/bin/env bash1#2# Delete ALL CodeQL Actions caches.3#4# CodeQL's default setup creates a new cache per commit and never reaps old5# ones. We reclaim the entire CodeQL slice of the 10 GiB per-repo budget.6# CodeQL continues to work without a cache — it just re-fetches on each run.7#8# Requires GH_TOKEN with `actions: write`. Default is dry-run; pass --delete9# to actually remove caches.1011set -euo pipefail1213DELETE=014if [[ "${1:-}" == "--delete" ]]; then15DELETE=116fi1718mapfile -t rows < <(19gh cache list --key "codeql" --limit 1000 \20--json id,key,createdAt \21--jq '.[] | [.id, .key, .createdAt] | @tsv'22)2324echo "CodeQL caches found: ${#rows[@]}"2526deleted=027for row in "${rows[@]}"; do28IFS=$'\t' read -r id key created <<<"$row"2930if (( DELETE )); then31if out=$(gh cache delete "$id" 2>&1); then32echo "deleted id=$id key=$key"33elif printf '%s' "$out" | grep -qi 'not found\|HTTP 404'; then34echo "already gone id=$id key=$key"35else36echo "::warning::failed to delete id=$id: $out"37continue38fi39else40echo "would delete id=$id key=$key ($created)"41fi42deleted=$((deleted + 1))43done4445echo46echo "Total $( (( DELETE )) && echo removed || echo to remove ): $deleted"47(( DELETE )) || echo "(dry run — re-run with --delete to apply)"484950