Created
November 24, 2025 14:17
-
-
Save julianitor/8c5b7223d4dcdc2c48c8446d65958109 to your computer and use it in GitHub Desktop.
Delete old GH repo artifacts
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
| REPO="owner/repo" | |
| DAYS=30 | |
| # macOS/BSD date: use -v for offsets | |
| cutoff=$(date -u -v -"${DAYS}"d +"%Y-%m-%dT%H:%M:%SZ") | |
| gh api --paginate "repos/$REPO/actions/artifacts" \ | |
| -q '.artifacts[] | select(.expired==false) | {id: .id, name: .name, created_at: .created_at}' \ | |
| | jq -c --arg cutoff "$cutoff" '. | select(.created_at < $cutoff)' \ | |
| | jq -r '.id' \ | |
| | while read id; do | |
| echo "Deleting artifact $id" | |
| gh api -X DELETE "repos/$REPO/actions/artifacts/$id" --silent | |
| sleep 0.2 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment