This repository was archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwrite_heartbeat.py
More file actions
68 lines (57 loc) · 1.67 KB
/
write_heartbeat.py
File metadata and controls
68 lines (57 loc) · 1.67 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys
import tempfile
import subprocess
import contextlib
import json
import time
# https://stackoverflow.com/questions/6194499/pushd-through-os-system
@contextlib.contextmanager
def pushd(new_dir):
previous_dir = os.getcwd()
os.chdir(new_dir)
try:
yield
finally:
os.chdir(previous_dir)
heartbeat_file = sys.argv[1] + ".json"
with tempfile.TemporaryDirectory() as tmpdir, pushd(tmpdir):
subprocess.run(
["git", "clone", "https://github.com/regro/circle_worker.git"],
check=True,
)
with pushd("circle_worker"):
subprocess.run("git checkout heartbeats", check=True, shell=True)
heartbeat = int(time.time())
with open(heartbeat_file, "w") as fp:
json.dump({"heartbeat": heartbeat}, fp)
subprocess.run(
["git", "add", heartbeat_file],
check=True,
)
subprocess.run(
"git commit --allow-empty -am '[ci skip] heartbeat %s'" % sys.argv[1],
check=True,
shell=True,
)
subprocess.run(
"git remote set-url --push origin "
"https://${PASSWORD}@github.com/regro/circle_worker.git",
shell=True,
check=True,
)
i = 0
pushed = False
while not pushed and i < 10:
try:
subprocess.run(
"git push",
check=True,
shell=True,
)
pushed = True
except subprocess.CalledProcessError:
subprocess.run("git pull --rebase", shell=True)
i += 1
if not pushed:
sys.exit(1)