mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 08:44:06 +02:00
listener redeploy
This commit is contained in:
parent
87daa07bd6
commit
7d5f5bba64
@ -1,26 +1,43 @@
|
|||||||
#!/bin/python3
|
#!/bin/python3 -u
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
INTERVAL_DELAY = 60
|
||||||
|
ERROR_DELAY = 60
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
dry_run = "--dry-run" in sys.argv
|
||||||
|
|
||||||
deployed_commit_hash = ""
|
deployed_commit_hash = ""
|
||||||
while True:
|
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()
|
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:
|
if not newest_commit_hash:
|
||||||
print("error fetching commit hash")
|
print("error: could not fetch commit hash", file=sys.stderr)
|
||||||
time.sleep(60)
|
print(f"trying again in {ERROR_DELAY} seconds...", file=sys.stderr)
|
||||||
|
time.sleep(ERROR_DELAY)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if newest_commit_hash != deployed_commit_hash:
|
if newest_commit_hash != deployed_commit_hash:
|
||||||
deployed_commit_hash = newest_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:
|
else:
|
||||||
print("should not redeploy")
|
print("no new commits")
|
||||||
|
|
||||||
|
print(f"sleeping for {INTERVAL_DELAY} seconds...")
|
||||||
time.sleep(60)
|
time.sleep(INTERVAL_DELAY)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user