From 21a21b86c0bbfd02ae21e0602a02d1c30cb264fb Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 30 Dec 2022 00:56:27 -0500 Subject: [PATCH] ci: clean all workflow caches to script (#936) --- ...-pr-cache.yml => clear-workflow-cache.yml} | 7 ++-- .github/workflows/nightly.yml | 2 +- scripts/clear_cache.py | 35 ++++++++++++++----- src/bin/main.rs | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) rename .github/workflows/{clear-pr-cache.yml => clear-workflow-cache.yml} (69%) diff --git a/.github/workflows/clear-pr-cache.yml b/.github/workflows/clear-workflow-cache.yml similarity index 69% rename from .github/workflows/clear-pr-cache.yml rename to .github/workflows/clear-workflow-cache.yml index 237b7fe5..b4d1a4c2 100644 --- a/.github/workflows/clear-pr-cache.yml +++ b/.github/workflows/clear-workflow-cache.yml @@ -1,12 +1,13 @@ -# Simple job to clear the cache used by a PR when it is closed/merged. +# Simple job to clear the cache used by a workflow. This automatically runs when a PR is closed/merged +# to clean up the corresponding PR's cache. -name: "clear PR cache" +name: "clear workflow cache" on: workflow_dispatch: inputs: id: - description: "Which id to clear:" + description: "Which id to clear. Type 'main'/'master'/'all' to clean all." required: false pull_request: types: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d025e546..3c5a1ec5 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: inputs: isMock: - description: "Replace to trigger a non-mock run." + description: "Replace with any word other than 'mock' to trigger a non-mock run." default: "mock" required: false diff --git a/scripts/clear_cache.py b/scripts/clear_cache.py index c2af1359..ac1c99b1 100644 --- a/scripts/clear_cache.py +++ b/scripts/clear_cache.py @@ -33,15 +33,32 @@ def main(): env = os.environ key = env["GITHUB_TOKEN"] - pr_id = int(args[1]) - ref = "refs/pull/{}/merge".format(pr_id) + if args[1].isnumeric(): + pr_id = int(args[1]) + ref = "refs/pull/{}/merge".format(pr_id) - print("Clearing any caches generated by PR {}".format(pr_id)) - with urlopen(cache_list_request(key)) as response: - response = json.load(response) - caches = response["actions_caches"] - for cache in caches: - if cache["ref"] == ref: + print("Clearing any caches generated by PR {}".format(pr_id)) + with urlopen(cache_list_request(key)) as response: + response = json.load(response) + caches = response["actions_caches"] + for cache in caches: + if cache["ref"] == 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: + response = json.load(response) + caches = response["actions_caches"] + for cache in caches: id = cache["id"] try: print("Deleting ID {}...".format(id)) @@ -52,6 +69,8 @@ def main(): print("URLError with delete.") else: print("Successfully deleted cache ID {}!".format(id)) + else: + print(f"Skipping, given argument {args[1]}.") if __name__ == "__main__": diff --git a/src/bin/main.rs b/src/bin/main.rs index bbad61b3..806efe3b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -158,7 +158,7 @@ fn main() -> Result<()> { if let Ok(recv) = receiver.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) { match recv { BottomEvent::Resize => { - try_drawing(&mut terminal, &mut app, &mut painter)?; + try_drawing(&mut terminal, &mut app, &mut painter)?; // FIXME: This is bugged with frozen? } BottomEvent::KeyInput(event) => { if handle_key_event_or_break(event, &mut app, &collection_thread_ctrl_sender) {