Cleanup Caches #8
This file contains 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 Caches | |
on: | |
workflow_dispatch: # Keep manual trigger | |
workflow_run: | |
workflows: ['Build server', 'Playwright Tests', 'Prettier'] | |
types: | |
- completed | |
jobs: | |
cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cleanup old caches | |
shell: bash | |
run: | | |
# Define services array | |
services=("server" "stage-transcriptions" "session-transcriptions" "clips" "reel-creator") | |
function cleanup_buildx_cache() { | |
local service=$1 | |
echo "π Scanning buildx cache for service: $service" | |
# Get all cache keys for this specific service's buildx cache | |
cacheKeys=$(gh cache list --limit 100 --json key,createdAt \ | |
--jq '.[] | select(.key | contains("Linux-buildx-'$service'")) | [.key, .createdAt] | @tsv' \ | |
| sort -k2,2r) | |
# Keep count of caches for this service | |
count=0 | |
while IFS=$'\t' read -r key date; do | |
((count++)) | |
# Keep only the most recent cache for each service | |
if [ "$count" -gt 1 ]; then | |
echo "ποΈ Deleting old cache for $service: $key" | |
gh cache delete "$key" | |
else | |
echo "πΎ Keeping most recent cache for $service: $key" | |
fi | |
done <<< "$cacheKeys" | |
echo "β Finished cleaning $service caches" | |
} | |
# Clean up buildx caches for each service | |
echo "π Starting cache cleanup process..." | |
for service in "${services[@]}"; do | |
cleanup_buildx_cache "$service" | |
done | |
# Clean up other types of caches (playwright, yarn) | |
function cleanup_other_caches() { | |
local pattern=$1 | |
local keep=$2 | |
echo "π Scanning caches matching pattern: $pattern" | |
cacheKeys=$(gh cache list --limit 100 --json key,createdAt \ | |
--jq '.[] | select(.key | contains("'$pattern'")) | [.key, .createdAt] | @tsv' \ | |
| sort -k2,2r) | |
count=0 | |
while IFS=$'\t' read -r key date; do | |
((count++)) | |
if [ "$count" -gt "$keep" ]; then | |
echo "ποΈ Deleting old cache: $key" | |
gh cache delete "$key" | |
else | |
echo "πΎ Keeping recent cache: $key" | |
fi | |
done <<< "$cacheKeys" | |
echo "β Finished cleaning $pattern caches" | |
} | |
# Clean up other cache types | |
cleanup_other_caches "playwright" 2 | |
cleanup_other_caches "yarn" 2 | |
echo "π Cache cleanup completed successfully!" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} |