listener redeploy

This commit is contained in:
SimonFJ20 2025-03-07 12:16:34 +01:00
parent 87daa07bd6
commit 7d5f5bba64

View File

@ -1,26 +1,43 @@
#!/bin/python3
#!/bin/python3 -u
import time
import os
import subprocess
import sys
INTERVAL_DELAY = 60
ERROR_DELAY = 60
def main():
dry_run = "--dry-run" in sys.argv
deployed_commit_hash = ""
while True:
print("fetching newest commit...")
newest_commit_hash = os.popen("curl -s https://api.github.com/repos/Mercantec-GHC/h4-projekt-gruppe-0-sm/commits/main | jq -r .sha").read()
if not newest_commit_hash:
print("error fetching commit hash")
time.sleep(60)
print("error: could not fetch commit hash", file=sys.stderr)
print(f"trying again in {ERROR_DELAY} seconds...", file=sys.stderr)
time.sleep(ERROR_DELAY)
continue
if newest_commit_hash != deployed_commit_hash:
deployed_commit_hash = newest_commit_hash
print("should redeploy")
print("new commit found. redeploying...")
if not dry_run:
rcode = subprocess.call(["sh", "./deploy/redeploy.sh"])
if rcode == 0:
print("redeployed successfully")
else:
print("error: could not redeploy", file=sys.stderr)
else:
print("should not redeploy")
print("no new commits")
time.sleep(60)
print(f"sleeping for {INTERVAL_DELAY} seconds...")
time.sleep(INTERVAL_DELAY)
if __name__ == "__main__":
main()