-
Notifications
You must be signed in to change notification settings - Fork 9.7k
68 lines (59 loc) · 2.09 KB
/
Copy pathcache-maintenance.yml
File metadata and controls
68 lines (59 loc) · 2.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: cache-maintenance
on:
push:
branches: [main]
paths:
- pnpm-lock.yaml
- .github/actions/setup-workspace/action.yml
- .github/workflows/cache-maintenance.yml
pull_request_target:
types: [closed]
workflow_dispatch:
permissions:
actions: write
contents: read
jobs:
seed-pnpm-windows:
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
runs-on: windows-latest
timeout-minutes: 15
steps:
- name: Checkout main
uses: actions/checkout@v6.0.2
- name: Seed Windows pnpm cache
uses: ./.github/actions/setup-workspace
with:
save-pnpm-cache: 'true'
clean-closed-pr-buildkit:
if: github.event_name == 'pull_request_target' && github.repository == 'nexu-io/open-design'
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Delete closed PR BuildKit caches
env:
CACHE_REF: refs/pull/${{ github.event.pull_request.number }}/merge
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
cache_rows="$(
gh cache list \
--repo "$GITHUB_REPOSITORY" \
--ref "$CACHE_REF" \
--limit 10000 \
--json id,key,sizeInBytes \
--jq '.[] | select((.key | startswith("buildkit-blob-")) or (.key | startswith("index-buildkit-"))) | [.id, .key, .sizeInBytes] | @tsv'
)"
if [ -z "$cache_rows" ]; then
echo "No closed-PR BuildKit caches found for $CACHE_REF"
exit 0
fi
count=0
bytes=0
while IFS=$'\t' read -r cache_id cache_key cache_size; do
[ -n "$cache_id" ] || continue
echo "Deleting cache id=$cache_id key=$cache_key bytes=$cache_size ref=$CACHE_REF"
gh cache delete "$cache_id" --repo "$GITHUB_REPOSITORY"
count=$((count + 1))
bytes=$((bytes + cache_size))
done <<< "$cache_rows"
echo "Deleted $count closed-PR BuildKit caches ($bytes bytes) for $CACHE_REF"