Skip to content

Instantly share code, notes, and snippets.

@julianitor
Created November 24, 2025 14:17
Show Gist options
  • Select an option

  • Save julianitor/8c5b7223d4dcdc2c48c8446d65958109 to your computer and use it in GitHub Desktop.

Select an option

Save julianitor/8c5b7223d4dcdc2c48c8446d65958109 to your computer and use it in GitHub Desktop.
Delete old GH repo artifacts
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