From e0faa48810bae1914afbc81adfcbdbc607521620 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 19 Jan 2025 11:31:45 +0100 Subject: [PATCH] Add script to deploy --- sync.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 sync.py diff --git a/sync.py b/sync.py new file mode 100755 index 0000000..9be7ad9 --- /dev/null +++ b/sync.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +from json import loads +from urllib.request import urlopen +from zipfile import ZipFile +from io import BytesIO +from sys import argv +from shutil import rmtree + +def main(destination: str): + print("Destination: " + destination) + + try: + with open(destination + '/site_revision.txt', 'r') as rev_file: + saved_run = int(rev_file.read()) + except: + saved_run = -1 + + print(f"Saved run: {saved_run}") + + with urlopen("https://git.m724.eu/api/v1/repos/Minecon724/m724.eu/actions/tasks") as resp: + latest_run = loads(resp.read().decode())['workflow_runs'][0] + + run_number = int(latest_run["run_number"]) + run_status = latest_run["status"] + + print(f'Latest run: {run_number} "{latest_run["display_title"]}" ({run_status})') + + if saved_run == run_number: + print("Already at latest") + return + + if latest_run["status"] != 'success': + print("Not syncing, because not success") + return + + print("Downloading") + with urlopen(f"https://git.m724.eu/Minecon724/m724.eu/actions/runs/{run_number}/artifacts/generated_out") as resp: + zip_file_content = resp.read() + + + rmtree(destination) + + print("Extracting") + with ZipFile(BytesIO(zip_file_content)) as zip_file: + zip_file.extractall(destination) + + with open(destination + '/site_revision.txt', 'w') as rev_file: + rev_file.write(str(run_number)) + + print("Done") + + +if __name__ == "__main__": + main(argv[1])