Skip to content

Commit e2c6a80

Browse files
✨ feat: Add script to purge the GHA cache of a repository.
1 parent ce3a0a0 commit e2c6a80

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.bin/github.gha.cache.purge

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Delete all GitHub Actions caches for a repository.
5+
"""
6+
7+
import json
8+
import github
9+
10+
def list_caches(token, repo):
11+
first_page = github.api(f'/repos/{repo}/actions/caches?per_page=100')
12+
for page in github.pages(first_page, token=token):
13+
caches = json.loads(page)
14+
if caches:
15+
yield from caches['actions_caches']
16+
17+
def delete_cache(token, repo, cache_key):
18+
assert isinstance(cache_key, int)
19+
url = github.api(f'/repos/{repo}/actions/caches/{cache_key}')
20+
print(f'DELETE {url}')
21+
github.delete(url, token=token)
22+
23+
def delete_all_caches(token, repo):
24+
for cache in list_caches(token, repo):
25+
delete_cache(token, repo, cache['id'])
26+
27+
if __name__ == '__main__':
28+
import argparse
29+
parser = argparse.ArgumentParser(description='Delete all GitHub Actions caches for a repository.')
30+
parser.add_argument('repo', type=str, help='Owner and repository name in the format owner/repo')
31+
args = parser.parse_args()
32+
33+
token = github.token()
34+
35+
delete_all_caches(token, args.repo)

0 commit comments

Comments
 (0)