ci: run wf cache clear script twice with delays (#1093)

* ci: run wf cache clear script twice with delays

* reduce
This commit is contained in:
Clement Tsang 2023-04-11 04:39:28 -04:00 committed by GitHub
parent 62474be52a
commit 016fa1e19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -26,11 +26,19 @@ jobs:
with: with:
fetch-depth: 1 fetch-depth: 1
- run: | # We run each script twice with a small delay in between to try and catch everything.
- name: Clear cache
run: |
if [[ -n "${{ github.event.schedule }}" ]]; then if [[ -n "${{ github.event.schedule }}" ]]; then
python ./scripts/clear_cache.py keep-master python ./scripts/clear_cache.py keep-master
sleep 5
python ./scripts/clear_cache.py keep-master
elif [[ -z "${{ github.event.inputs.id }}" ]]; then 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 }}
sleep 5
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 }}
sleep 5
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
fi fi

View File

@ -4,9 +4,10 @@
# #
# Expects a GitHub token in the environment variables as GITHUB_TOKEN. # Expects a GitHub token in the environment variables as GITHUB_TOKEN.
import os
import json import json
import os
import sys import sys
import time
from urllib.error import HTTPError, URLError from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen from urllib.request import Request, urlopen
@ -53,6 +54,7 @@ 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))
time.sleep(0.1)
elif args[1] == "keep-main" or args[1] == "keep-master": elif args[1] == "keep-main" or args[1] == "keep-master":
print("Clearing all but default branch cache.") print("Clearing all but default branch cache.")
with urlopen(cache_list_request(key)) as response: with urlopen(cache_list_request(key)) as response:
@ -70,6 +72,7 @@ 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))
time.sleep(0.1)
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:
@ -86,6 +89,7 @@ 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))
time.sleep(0.1)
else: else:
print(f"Skipping, given argument {args[1]}.") print(f"Skipping, given argument {args[1]}.")