Skip to content

Cleanup Actions Storage #19

Cleanup Actions Storage

Cleanup Actions Storage #19

name: Cleanup Actions Storage
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
actions: write
contents: read
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete artifacts and caches older than 7 days
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
cutoff=$(date -u -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ)
gh api "repos/$REPO/actions/artifacts" --paginate \
--jq ".artifacts[] | select(.created_at < \"$cutoff\") | .id" |
while read -r id; do
[ -n "$id" ] && gh api -X DELETE "repos/$REPO/actions/artifacts/$id"
done
gh api "repos/$REPO/actions/caches" --paginate \
--jq ".actions_caches[] | select(.last_accessed_at < \"$cutoff\") | .id" |
while read -r id; do
[ -n "$id" ] && gh api -X DELETE "repos/$REPO/actions/caches/$id"
done