Files
packages/anda/apps/openasar-canary/chkupdate.py
T
seth 7653e48da9 [openasar-canary] save commit on auto update
this was an L and i probably need sleep
2022-12-05 03:50:24 -05:00

31 lines
677 B
Python

import requests
import re
import os
NAME = "openasar-canary"
REPO = "GooseMod/OpenAsar"
REGEX_SHA = r"%define commit (.+)"
SPEC = f"{NAME}.spec"
LINK = f"https://api.github.com/repos/{REPO}/commits/HEAD"
token = os.getenv("GITHUB_TOKEN")
sha = requests.get(LINK, headers={"Authorization": f"Bearer {token}"}).json()["sha"]
f = open(SPEC, "r")
matches = re.findall(REGEX_SHA, txt := f.read())
if not len(matches):
exit(f"{NAME}: Failed to match regex!")
cur = matches[0]
if sha == cur:
exit(f"{NAME}: Up to date!")
print(f"{NAME}: {cur} -> {sha}")
newspec = re.sub(REGEX_SHA, f"%define commit {sha}", txt)
f.close()
f = open(SPEC, "w")
f.write(newspec)
f.close()