Created
December 14, 2025 16:11
-
-
Save JPBM135/fd8014e8ae56431c0a08772923531f1c to your computer and use it in GitHub Desktop.
Cleanup old caches
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
| #!/bin/bash | |
| set -e | |
| # Calculate the cutoff date (3 days ago) | |
| # Note: The date command syntax may vary slightly between Linux and macOS. | |
| # For Linux (GNU date): | |
| # CUTOFF_DATE=$(date -d "3 days ago" +%Y-%m-%dT%H:%M:%SZ) | |
| # For macOS/BSD (requires gdate if not using system date, or a different approach): | |
| CUTOFF_TIMESTAMP=$(date -v -3d +%s) | |
| # List caches as JSON, sort by creation time (newest first by default) | |
| # and use a limit to ensure you get all of them if you have many | |
| gh cache list --json id,createdAt --limit 100 --repo "$GITHUB_REPOSITORY" | jq -r ' | |
| .[] | |
| # Remove fractional seconds from createdAt (e.g., "2025-12-14T15:41:00.058211Z" -> "2025-12-14T15:41:00Z") | |
| | .createdAt |= (split(".")[0] + "Z") | |
| | select((now - (.createdAt | fromdateiso8601)) > (3 * 24 * 60 * 60)) | |
| | .id | |
| ' | while read CACHE_ID; do | |
| echo "Deleting cache ID $CACHE_ID..." | |
| gh cache delete "$CACHE_ID" --repo "$GITHUB_REPOSITORY" | |
| done | |
| echo "Deletion process complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment