summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-01-13 01:45:11 -0500
committerGitHub <noreply@github.com>2023-01-13 01:45:11 -0500
commite112e1231e1127f36104c538c687ec3f3206f575 (patch)
treedd4ba691f6d5e8238f79c1a90c521db063a94cea /scripts
parent9a696122c70948addd99c33b5b229741de15ae14 (diff)
ci: add schedule to clear PR caches (#973)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/clear_cache.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/clear_cache.py b/scripts/clear_cache.py
index ac1c99b1..2c40f76c 100644
--- a/scripts/clear_cache.py
+++ b/scripts/clear_cache.py
@@ -53,6 +53,23 @@ def main():
print("URLError with delete.")
else:
print("Successfully deleted cache ID {}!".format(id))
+ elif args[1] == "keep-main" or args[1] == "keep-master":
+ print("Clearing all but default branch cache.")
+ with urlopen(cache_list_request(key)) as response:
+ response = json.load(response)
+ caches = response["actions_caches"]
+ for cache in caches:
+ if not ("master" in cache["ref"] or "main" in cache["ref"]):
+ id = cache["id"]
+ try:
+ print("Deleting ID {}...".format(id))
+ urlopen(delete_cache_request(key, id))
+ except HTTPError as e:
+ print("HTTPError with delete, error code {}.".format(e.code))
+ except URLError as _:
+ print("URLError with delete.")
+ else:
+ print("Successfully deleted cache ID {}!".format(id))
elif args[1] == "main" or args[1] == "master" or args[1] == "all":
print("Clearing all caches.")
with urlopen(cache_list_request(key)) as response: