Add script to deploy
All checks were successful
/ deploy (push) Successful in 12s

This commit is contained in:
Minecon724 2025-01-19 11:31:45 +01:00
parent 9065887617
commit e0faa48810
Signed by untrusted user who does not match committer: Minecon724
GPG key ID: 3CCC4D267742C8E8

55
sync.py Executable file
View file

@ -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])