mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-09-11 11:46:59 +03:00
ci: add schedule to clear PR caches (#973)
This commit is contained in:
parent
9a696122c7
commit
e112e1231e
6
.github/workflows/clear-workflow-cache.yml
vendored
6
.github/workflows/clear-workflow-cache.yml
vendored
@ -12,6 +12,8 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
types:
|
types:
|
||||||
- closed
|
- closed
|
||||||
|
schedule:
|
||||||
|
- cron: "0 11 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
clear-cache:
|
clear-cache:
|
||||||
@ -25,7 +27,9 @@ jobs:
|
|||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
if [[ -z "${{ github.event.inputs.id }}" ]]; then
|
if [[ -n "${{ github.event.schedule }}" ]]; then
|
||||||
|
python ./scripts/clear_cache.py keep-master
|
||||||
|
elif [[ -z "${{ github.event.inputs.id }}" ]]; then
|
||||||
python ./scripts/clear_cache.py ${{ github.event.pull_request.number }}
|
python ./scripts/clear_cache.py ${{ github.event.pull_request.number }}
|
||||||
else
|
else
|
||||||
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
|
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
|
||||||
|
@ -53,6 +53,23 @@ def main():
|
|||||||
print("URLError with delete.")
|
print("URLError with delete.")
|
||||||
else:
|
else:
|
||||||
print("Successfully deleted cache ID {}!".format(id))
|
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":
|
elif args[1] == "main" or args[1] == "master" or args[1] == "all":
|
||||||
print("Clearing all caches.")
|
print("Clearing all caches.")
|
||||||
with urlopen(cache_list_request(key)) as response:
|
with urlopen(cache_list_request(key)) as response:
|
||||||
|
Loading…
Reference in New Issue
Block a user