Cleanup Actions Storage #19
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
| 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 |