-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy-pipe.py
62 lines (51 loc) · 1.58 KB
/
py-pipe.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
54
55
56
57
58
59
60
61
62
from time import sleep
import subprocess
import shlex
project_repo = "CHANGE_ME"
project_dir = "/CHANGE/ME"
# def clone():
# subprocess.run(["git","clone",project_repo], cwd="/home/ubuntu/")
def pull():
subprocess.run(shlex.split("git pull"), cwd=project_dir)
def local_commit():
return (
subprocess.run(
shlex.split("git rev-parse main"), cwd=project_dir, capture_output=True
)
.stdout.decode("utf-8")
.rstrip()
)
def remote_commit():
ps = subprocess.Popen(
["git", "ls-remote", project_repo, "refs/heads/main"],
cwd=project_dir,
stdout=subprocess.PIPE,
)
output = (
subprocess.check_output(["cut", "-f", "1"], stdin=ps.stdout)
.decode("utf-8")
.rstrip()
)
ps.wait()
return output
# check remote repository for new changes every minute
while True:
print("job is runing")
if local_commit() != remote_commit():
try:
# TODO: kill started Popen processes
subprocess.run(
shlex.split("killall node"), cwd=project_dir, capture_output=True
)
print("current app killed")
except:
print("nothing for kill")
pull()
subprocess.run(shlex.split("yarn"), cwd=project_dir, capture_output=True)
print("installed")
subprocess.run(shlex.split("yarn build"), cwd=project_dir, capture_output=True)
print("builded")
subprocess.Popen(shlex.split("yarn start"), cwd=project_dir)
print("started")
print("nothing to do")
sleep(60)