dot dot dotfiles
at main 49 lines 1.2 kB view raw
1#!/bin/bash 2 3# Script to delete all but the most recent 2 cache entries from GitHub for each 4# different kind of cache key. 5# 6NC='\033[0m' 7RED='\033[0;31m' 8GRN='\033[0;32m' # or 1;32m for light green 9ARRR='\u2192' # right arrow 10ARRL='\u2190' # left arrow 11DASH='\u2014' 12 13echo -e "${GRN}${DASH}${DASH}${DASH}${ARRR} Remove old cache entries from GitHub ${ARRL}${DASH}${DASH}${DASH}${NC}" 14echo -e "" 15 16out_file="junk.json" 17gh cache list --limit 100 --json id,key,createdAt,sizeInBytes > $out_file 18 19ntot="$(jq 'map({ 20 id: .id, 21 key: (.key | split("(") | first), 22 createdAt: .createdAt, 23}) | length' $out_file)" 24 25 26n_remove="$(jq 'map({ 27 id: .id, 28 key: (.key | split("(") | first) 29}) | 30 group_by(.key) | 31 map(map(.id)[2:]) | flatten | length' $out_file)" 32 33ids="$(jq 'map({ 34 id: .id, 35 key: (.key | split("(") | first) 36}) | 37 group_by(.key) | 38 map(map(.id)[2:]) | flatten | .[]' $out_file)" 39 40echo "Total cache entries = $ntot, of which $n_remove will be removed." 41 42read -p "Proceed(y/n)? " OPT 43if [ "$OPT" == "y" ]; then 44 for id in $ids; do 45 gh cache delete $id 46 echo "deleted cache id: $id" 47 done 48fi 49rm "$out_file"