-
Notifications
You must be signed in to change notification settings - Fork 684
42 lines (35 loc) · 1.47 KB
/
delete-caches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Delete Caches
on:
schedule:
- cron: "0 */4 * * *" # Every 4th hour
concurrency:
# Only run once and cancel other (previous) runs.
group: delete-caches
cancel-in-progress: true
permissions:
actions: write # this permission is needed to delete cache
jobs:
delete-public-local-caches:
name: Delete unneeded caches
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
gh cache list --limit 500 --order asc --sort last_accessed_at | grep 'play-published-local' > caches.txt || true
echo "Found $(wc -l < caches.txt | xargs) published local cache entries"
current_time=$(date -u +%s)
expiration_time=$((current_time - 7200)) # 2 hour ago
echo "Current time is $(date -d @$current_time)"
echo "All entries hadn't been use from $(date -d @$expiration_time) will be delete"
while IFS=$'\t' read -r id name size created_at last_accessed_at; do
accessedTimestamp=$(date -u -d "$last_accessed_at" +%s)
# Uncomment to check on Mac OS
# accessedTimestamp=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$last_accessed_at" +%s)
if [ "$accessedTimestamp" -lt "$expiration_time" ]; then
echo "Delete $id $name ($last_accessed_at)"
gh cache delete $id
fi
done < caches.txt
rm -rf caches.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}