File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments