Skip to content

Commit 14d59e1

Browse files
committed
Add Actions storage cleanup workflow
1 parent eefa65b commit 14d59e1

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Cleanup Actions Storage
2+
3+
on:
4+
schedule:
5+
- cron: "17 3 * * *"
6+
workflow_dispatch:
7+
8+
permissions:
9+
actions: write
10+
contents: read
11+
12+
jobs:
13+
cleanup:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Delete artifacts and caches older than 7 days
17+
env:
18+
GH_TOKEN: ${{ github.token }}
19+
REPO: ${{ github.repository }}
20+
run: |
21+
cutoff=$(date -u -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ)
22+
23+
gh api "repos/$REPO/actions/artifacts" --paginate \
24+
--jq ".artifacts[] | select(.created_at < \"$cutoff\") | .id" |
25+
while read -r id; do
26+
[ -n "$id" ] && gh api -X DELETE "repos/$REPO/actions/artifacts/$id"
27+
done
28+
29+
gh api "repos/$REPO/actions/caches" --paginate \
30+
--jq ".actions_caches[] | select(.last_accessed_at < \"$cutoff\") | .id" |
31+
while read -r id; do
32+
[ -n "$id" ] && gh api -X DELETE "repos/$REPO/actions/caches/$id"
33+
done

0 commit comments

Comments
 (0)