forked from HypothesisWorks/hypothesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
72 lines (59 loc) · 2.14 KB
/
deploy.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
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import os
import sys
from time import time, sleep
import random
sys.path.append(os.path.dirname(__file__)) # noqa
import hypothesistooling as tools
if __name__ == '__main__':
last_release = tools.latest_version()
print("Current version: %s. Latest released version: %s" % (
tools.__version__, last_release
))
start_time = time()
prev_pending = None
while time() <= start_time + 60 * 60:
jobs = tools.build_jobs()
failed_jobs = [
v for k, vs in jobs.items() if k not in ('started', 'passed')
for v in vs
]
if failed_jobs:
print("Failing this due to failure of jobs %s" % (
', '.join(failed_jobs),
))
sys.exit(1)
else:
pending = jobs["started"]
pending.remove("deploy")
if pending:
still_pending = set(pending)
if prev_pending is None:
print("Waiting for the following jobs to complete:")
for p in sorted(still_pending):
print(" * %s" % (p,))
print()
else:
completed = prev_pending - still_pending
if completed:
print("%s completed since last check." % (
', '.join(sorted(completed)),))
prev_pending = still_pending
naptime = 10.0 * (2 + random.random())
print("Waiting %.2fs for %d more job%s to complete" % (
naptime, len(pending), "s" if len(pending) > 1 else "",))
sleep(naptime)
else:
break
else:
print("We've been waiting for an hour. That seems bad. Failing now")
sys.exit(1)
if not tools.on_master():
print("Not deploying due to not being on master")
sys.exit(0)
if not tools.has_source_changes(last_release):
print("Not deploying due to no source changes")
sys.exit(0)
print("Looks good to release! Pushing the tag now.")
tools.create_tag()
sys.exit(0)