-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
name: Cache Cleanup | ||
|
||
on: | ||
workflow_dispatch: # Manually trigger the workflow | ||
schedule: | ||
- cron: '0 0 * * 0' # Run every Sunday at midnight (UTC) | ||
|
||
jobs: | ||
cleanup: | ||
name: Cleanup Old Caches | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install gh CLI | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install gh | ||
- name: Install gh-actions-cache extension | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
- name: List all caches | ||
run: | | ||
gh actions-cache list | ||
- name: Delete caches older than 30 days | ||
env: | ||
MAX_CACHE_AGE_DAYS: 30 | ||
run: | | ||
echo "Fetching list of caches..." | ||
# List caches | ||
caches=$(gh actions-cache list --json id,createdAt) | ||
echo "Caches found: $(echo "$caches" | jq '. | length')" | ||
# Get current time | ||
current_time=$(date +%s) | ||
# Loop through all caches and delete those older than MAX_CACHE_AGE_DAYS | ||
for cache_id in $(echo "$caches" | jq -r '.[] | select((('"$current_time"' - (.createdAt | fromdateiso8601 | mktime)) / 86400) > '"$MAX_CACHE_AGE_DAYS"') | .id'); do | ||
echo "Deleting cache with ID: $cache_id" | ||
gh actions-cache delete $cache_id --confirm | ||
echo "Deleted cache $cache_id" | ||
done |