File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Cache Cleanup
2+
3+ on :
4+ workflow_dispatch : # Manually trigger the workflow
5+ schedule :
6+ - cron : ' 0 0 * * 0' # Run every Sunday at midnight (UTC)
7+
8+ jobs :
9+ cleanup :
10+ name : Cleanup Old Caches
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Checkout the repository
14+ uses : actions/checkout@v4
15+
16+ - name : Install gh CLI
17+ run : |
18+ sudo apt-get update
19+ sudo apt-get install gh
20+
21+ - name : Install gh-actions-cache extension
22+ run : |
23+ gh extension install actions/gh-actions-cache
24+
25+ - name : List all caches
26+ run : |
27+ gh actions-cache list
28+
29+ - name : Delete caches older than 30 days
30+ env :
31+ MAX_CACHE_AGE_DAYS : 30
32+ run : |
33+ echo "Fetching list of caches..."
34+ # List caches
35+ caches=$(gh actions-cache list --json id,createdAt)
36+
37+ echo "Caches found: $(echo "$caches" | jq '. | length')"
38+
39+ # Get current time
40+ current_time=$(date +%s)
41+
42+ # Loop through all caches and delete those older than MAX_CACHE_AGE_DAYS
43+ for cache_id in $(echo "$caches" | jq -r '.[] | select((('"$current_time"' - (.createdAt | fromdateiso8601 | mktime)) / 86400) > '"$MAX_CACHE_AGE_DAYS"') | .id'); do
44+ echo "Deleting cache with ID: $cache_id"
45+ gh actions-cache delete $cache_id --confirm
46+ echo "Deleted cache $cache_id"
47+ done
You can’t perform that action at this time.
0 commit comments