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 pathrestart_me.py
More file actions
50 lines (42 loc) · 1.3 KB
/
restart_me.py
File metadata and controls
50 lines (42 loc) · 1.3 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
import os
import sys
import tempfile
import subprocess
import contextlib
import requests
# 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)
with tempfile.TemporaryDirectory() as tmpdir, pushd(tmpdir):
subprocess.run(
["git", "clone", "--depth=1", "https://github.com/regro/circle_worker.git"],
check=True)
if os.path.exists(os.path.join("circle_worker", "please.go")):
go = True
else:
go = False
if not go:
print("I could not find the file 'please.go' on master! Stopping!")
else:
print("Starting the next worker...")
r = requests.post(
"https://circleci.com/api/v1.1/project/github/regro/circle_worker/tree/master",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
},
json={"build_parameters": {"CIRCLE_JOB": sys.argv[1]}},
auth=(os.environ["CIRCLE_TOKEN"], ""),
)
if r.status_code != 201:
print("the next worker could not be started!")
print("response:\n%s" % r.status_code)
r.raise_for_status()
else:
print("the next worker was started!")