Created
July 29, 2022 08:32
-
-
Save bluele/8d2d87bc1061f6e4fd39856cb691fe20 to your computer and use it in GitHub Desktop.
A script invalidates all github action's caches for a specified repository
This file contains hidden or 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
#!/bin/bash | |
set -eu | |
# A script invalidates all github action's caches for a specified repository | |
# API documents: https://docs.github.com/rest/actions/cache | |
# | |
# Prerequisites: Install Github CLI and authenticate with your github account. | |
# For the details, you can see here: https://cli.github.com/manual/ | |
# | |
# # example: | |
# $ ./gh_invalidate_cache.sh <target-owner> <target-repo> | |
owner=$1 # target repository belong to owner/organization | |
repo=$2 # target repository name | |
delete_cache() { | |
gh api \ | |
--method DELETE \ | |
-H "Accept: application/vnd.github+json" \ | |
/repos/${owner}/${repo}/actions/caches/$1 \ | |
--silent | |
} | |
main() { | |
id_list=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
/repos/${owner}/${repo}/actions/caches -q '.actions_caches[].id') | |
IFS=$'\n' | |
for id in $id_list | |
do | |
echo "delete->$id" | |
delete_cache $id | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment