Skip to content

Commit 31ecb85

Browse files
authored
Add cache clearing job to workflow
Added a job to clear old caches, excluding TestData, in the GitHub Actions workflow.
1 parent bc2dd56 commit 31ecb85

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/cache.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ on:
33
workflow_dispatch:
44

55
jobs:
6+
clear_cache:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
actions: write
10+
steps:
11+
- name: Delete old caches (except TestData)
12+
env:
13+
GH_TOKEN: ${{ github.token }}
14+
run: |
15+
cutoff=$(date -d '14 days ago' +%s)
16+
17+
gh api \
18+
-H "Accept: application/vnd.github+json" \
19+
"/repos/${{ github.repository }}/actions/caches?per_page=100" \
20+
--paginate \
21+
--jq '.actions_caches[]' | \
22+
jq -r --arg cutoff "$cutoff" '
23+
select(.key | startswith("TestData-") | not) |
24+
select((.last_accessed_at | sub("\\..*Z$"; "Z") | fromdateiso8601) < ($cutoff | tonumber)) |
25+
"\(.id) \(.key)"
26+
' | while read cache_id cache_key; do
27+
if [ -n "$cache_id" ]; then
28+
echo "Deleting cache $cache_id ($cache_key)"
29+
gh api --method DELETE \
30+
-H "Accept: application/vnd.github+json" \
31+
"/repos/${{ github.repository }}/actions/caches/$cache_id" || true
32+
fi
33+
done
34+
635
cache:
736
runs-on: ubuntu-latest
837
outputs:

0 commit comments

Comments
 (0)