forked from rayonlabs/vision-workers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_autoupdates_validator.py
53 lines (38 loc) · 1.62 KB
/
run_autoupdates_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import subprocess
import time
import argparse
def should_update_local(local_commit, remote_commit):
return local_commit != remote_commit
def run_auto_updater():
print("Starting auto-updater...")
print("First i'll launch the orchestrator...")
launch_command = "./launch_orchestrator.sh"
os.system(launch_command)
time.sleep(60)
while True:
print("Checking for updates...")
current_branch = subprocess.getoutput("git rev-parse --abbrev-ref HEAD")
local_commit = subprocess.getoutput("git rev-parse HEAD")
os.system("git fetch")
remote_commit = subprocess.getoutput(f"git rev-parse origin/{current_branch}")
if should_update_local(local_commit, remote_commit):
print("Local repo is not up-to-date. Updating...")
reset_cmd = f"git reset --hard {remote_commit}"
process = subprocess.Popen(reset_cmd.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
if error:
print("Error in updating:", error)
else:
print("Updated local repo to latest version:", remote_commit)
print("Running the autoupdate steps...")
os.system("./autoupdates_validator_steps.sh")
time.sleep(20)
print("Finished running the autoupdate steps! Ready to go 😎")
else:
print("Repo is up-to-date.")
time.sleep(60)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run auto updates for a validator")
args = parser.parse_args()
run_auto_updater()