keep the last cache with this bash function (add it to your .bashrc file)
function gh_clear_old_caches(){ GH_REPO='your_github_user/your_repository' echo "deleting all caches, except the last" gh api --paginate -H "Accept: application/vnd.github+json" \"/repos/${GH_REPO}/actions/caches" \ | for ID in `jq '.actions_caches | sort_by(.id) | .[:-1][] | .id '`; \ do echo "Deleting cache id ${ID}"; \ gh api --method DELETE -H "Accept: application/vnd.github+json" "/repos/${GH_REPO}/actions/caches/${ID}" | echo; \ done }
name completion works with bash functions as well:
gh_<tab>
the addition in this one is that jq first sorts the result by id (assuming that the most recent one has the largest).
[:-1] means every id, except the last.