char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
985b14912
char/aliceai-t5-moe
1#!/bin/bash 2# Delete GitHub Actions caches matching a key prefix, oldest first. 3# 4# Usage: ccache-clear.sh --key KEY [--older DURATION] [--min N] [--dry-run] 5# --key: cache key prefix to match and delete (without the ccache- prefix) 6# --older: only delete caches created more than DURATION ago (e.g. 5m, 1h, 1d); 7# by default all matching caches are deleted 8# --min: stop deleting if fewer than N caches would remain (default: 0) 9# --dry-run: only print the caches that would be deleted, without deleting them 10# 11# Env (when running in GitHub Actions): 12# GH_TOKEN: token for the gh CLI 13# GITHUB_REPOSITORY: owner/repo of the caches to manage 14set -euo pipefail 15 16KEY ="" 17OLDER ="" 18MIN =0 19DRY_RUN =false 20while [[$ # -gt 0 ]];do 21case " $ 1 " in 22 --key) [[$ # -ge 2 ]] || {echo "Missing value for $ 1 " >&2;exit 1; };KEY =" $ 2 " ;shift 2 ;; 23 --older) [[$ # -ge 2 ]] || {echo "Missing value for $ 1 " >&2;exit 1; };OLDER =" $ 2 " ;shift 2 ;; 24 --min) [[$ # -ge 2 ]] || {echo "Missing value for $ 1 " >&2;exit 1; };MIN =" $ 2 " ;shift 2 ;; 25 --dry-run)DRY_RUN =true;shift ;; 26 *)echo "Unknown argument: $ 1 " ;exit 1 ;; 27esac 28done 29 30command -v gh> /dev/null2 >&1 || {echo "Error: GitHub CLI (gh) is required" >&2;exit 1; } 31[[ -n" ${ GITHUB_REPOSITORY :-} " ]] || {echo "Error: GITHUB_REPOSITORY not set" >&2;exit 1; } 32[[ -n" $ KEY " ]] || {echo "Error: --key is required" >&2;exit 1; } 33[[" $ MIN " =~ ^[0-9]+$ ]] || {echo "Invalid min value: $ MIN " >&2;exit 1; } 34 35# Convert a duration (e.g. 90m, 1h, 1d, plain seconds) to seconds 36to_seconds () { 37 localval =" $ 1 " 38 [[" $ val " =~ ^[0-9]+$ ]]&& {echo " $ val " ;return 0; } 39 localnum =" ${ val %?} " unit =" ${ val : -1} " mult 40 [[" $ num " =~ ^[0-9]+$ ]] ||return 1 41case " $ unit " in 42 s)mult =1 ;; 43 m)mult =60 ;; 44 h)mult =3600 ;; 45 d)mult =86400 ;; 46 *)return 1 ;; 47esac 48echo $((num *mult )) 49} 50 51# Convert an ISO-8601 UTC timestamp (e.g. 2026-08-23T16:51:23.313693Z) to epoch seconds 52to_epoch () { 53 localval =" $ 1 " out 54# GNU date (e.g. Linux) 55if out =$( date -d " $ val " +%s 2 > /dev/null) && [[" $ out " =~ ^[0-9]+$ ]];then 56echo " $ out " 57return 0 58fi 59# BSD date (e.g. macOS); fractional seconds are not needed, TZ forces UTC 60out =$( TZ =UTC date -j -f "%Y-%m-%dT%H:%M:%S" " ${ val :0:19} " +%s 2 > /dev/null) ||return 1 61 [[" $ out " =~ ^[0-9]+$ ]] ||return 1 62echo " $ out " 63} 64 65CACHES =$( gh cache list --repo " $ GITHUB_REPOSITORY " --key "ccache- $ KEY " --json id,key,createdAt --jq '.[] | [.createdAt, .id, .key] | @tsv' | LC_ALL =C sort ) 66if [[ -z" $ CACHES " ]];then 67echo "No caches found with key prefix: $ KEY " 68exit 0 69fi 70 71TOTAL =$(($( wc -l <<< " $ CACHES " ) )) 72 73echo "Found $ TOTAL cache(s) with key prefix: $ KEY (oldest first):" 74while IFS =$'\t'read -r CREATED ID CACHE_KEY;do 75printf ' %s %s %s\n' " $ CREATED " " $ ID " " $ CACHE_KEY " 76done <<<" $ CACHES " 77 78CUTOFF ="" 79if [[ -n" $ OLDER " ]];then 80OLDER_SECONDS =$( to_seconds " $ OLDER " ) || {echo "Invalid older value: $ OLDER (expected e.g. 90m, 1h, 1d)" >&2;exit 1; } 81CUTOFF =$(($( date +%s) -OLDER_SECONDS )) 82fi 83 84# Caches are sorted oldest first 85DELETED =0 86while IFS =$'\t'read -r CREATED ID CACHE_KEY;do 87if [[ -n" $ CUTOFF " ]];then 88CREATED_SECONDS =$( to_epoch " $ CREATED " ) || {echo "Failed to parse date: $ CREATED " >&2;exit 1; } 89if [[" $ CREATED_SECONDS " -ge" $ CUTOFF " ]];then 90echo "Rest are not older than $ OLDER , stopping" 91break 92fi 93fi 94if (( TOTAL - DELETED - 1 < MIN )) ;then 95echo "Keeping at least $ MIN cache(s), stopping" 96break 97fi 98if [[" $ DRY_RUN " =="true" ]];then 99echo "Would delete cache: $ ID ( $ CACHE_KEY )" 100else 101echo "Deleting cache: $ ID ( $ CACHE_KEY )" 102gh cache delete--repo " $ GITHUB_REPOSITORY " " $ ID " 103fi 104DELETED =$((DELETED + 1)) 105done <<<" $ CACHES "