-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[build] prune old codeql caches #17570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+111
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Prune CodeQL caches | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["CodeQL"] | ||
| types: [completed] | ||
| branches: [trunk] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: prune-codeql-caches | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: write | ||
|
|
||
| jobs: | ||
| prune: | ||
| name: Prune | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Prune stale CodeQL caches | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: ./scripts/github-actions/prune-codeql-caches.sh --delete | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Prune stale CodeQL Actions caches, keeping only the most recently created | ||
| # entry per cache "group". CodeQL's default setup creates a new | ||
| # overlay-base-database cache per commit and never reaps the old ones, which | ||
| # pushes the repo over the 10 GiB per-repo cache budget. | ||
| # | ||
| # Grouping: | ||
| # codeql-overlay-base-database-* -> strip trailing "-<sha>-<runid>-1" | ||
| # codeql-dependencies-* -> exact key (GH allows duplicate keys) | ||
| # | ||
| # Requires GH_TOKEN with `actions: write`. Default is dry-run; pass --delete | ||
| # to actually remove caches. Safe to run concurrently from multiple jobs: a | ||
| # delete that races with another job just returns "not found", which is | ||
| # treated as success. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| DELETE=0 | ||
| if [[ "${1:-}" == "--delete" ]]; then | ||
| DELETE=1 | ||
| fi | ||
|
|
||
| mapfile -t rows < <( | ||
| gh cache list --key "codeql" --limit 1000 \ | ||
| --json id,key,createdAt \ | ||
| --jq '.[] | [.id, .key, .createdAt] | @tsv' | ||
| ) | ||
|
|
||
| declare -A newest_id newest_time | ||
|
|
||
| for row in "${rows[@]}"; do | ||
| IFS=$'\t' read -r id key created <<<"$row" | ||
|
|
||
| if [[ "$key" == codeql-overlay-base-database-* ]]; then | ||
| group=$(printf '%s' "$key" | sed -E 's/-[0-9a-f]{40}-[0-9]+-1$//') | ||
| else | ||
| group="$key" | ||
| fi | ||
|
|
||
| # ISO8601 sorts lexicographically; keep the newest per group. | ||
| if [[ -z "${newest_time[$group]:-}" || "$created" > "${newest_time[$group]}" ]]; then | ||
| newest_time[$group]="$created" | ||
| newest_id[$group]="$id" | ||
| fi | ||
| done | ||
|
|
||
| echo "Groups found: ${#newest_id[@]}" | ||
| for g in "${!newest_id[@]}"; do | ||
| echo " keep id=${newest_id[$g]} @ ${newest_time[$g]} ($g)" | ||
| done | ||
| echo | ||
|
|
||
| deleted=0 | ||
| for row in "${rows[@]}"; do | ||
| IFS=$'\t' read -r id key created <<<"$row" | ||
|
|
||
| if [[ "$key" == codeql-overlay-base-database-* ]]; then | ||
| group=$(printf '%s' "$key" | sed -E 's/-[0-9a-f]{40}-[0-9]+-1$//') | ||
| else | ||
| group="$key" | ||
| fi | ||
|
|
||
| [[ "$id" == "${newest_id[$group]}" ]] && continue | ||
|
|
||
| if (( DELETE )); then | ||
| # Tolerate races: another concurrent job may have already deleted it. | ||
| if out=$(gh cache delete "$id" 2>&1); then | ||
| echo "deleted id=$id key=$key" | ||
| elif printf '%s' "$out" | grep -qi 'not found\|HTTP 404'; then | ||
| echo "already gone id=$id key=$key" | ||
| else | ||
| echo "::warning::failed to delete id=$id: $out" | ||
| continue | ||
| fi | ||
|
titusfortner marked this conversation as resolved.
|
||
| else | ||
| echo "would delete id=$id key=$key" | ||
| fi | ||
| deleted=$((deleted + 1)) | ||
| done | ||
|
|
||
| echo | ||
| echo "Total $( (( DELETE )) && echo removed || echo to remove ): $deleted" | ||
| (( DELETE )) || echo "(dry run — re-run with --delete to apply)" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.