-
Notifications
You must be signed in to change notification settings - Fork 21
/
buildhub.py
163 lines (136 loc) · 5.22 KB
/
buildhub.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import json
from pollbot.exceptions import TaskError
from pollbot.utils import (
Channel, Status, build_version_id, get_version_channel, yesterday, strip_candidate_info
)
from . import get_session, build_task_response, heartbeat_factory
BUILDHUB_SERVER = "https://buildhub.prod.mozaws.net/v1"
async def get_releases(product):
RELEASE_CHANNEL = {
'devedition': 'aurora',
'firefox': 'release',
}
query = {
"aggs": {
"by_version": {
"terms": {
"field": "target.version",
"size": 1000,
"order": {
"_term": "desc"
}
}
}
},
"query": {
"bool": {
"filter": [
{
"term": {
"source.product": product
}
}, {
"term": {
"target.channel": RELEASE_CHANNEL[product]
}
}
]
}
},
"size": 0
}
async with get_session() as session:
url = '{}/buckets/build-hub/collections/releases/search'
url = url.format(BUILDHUB_SERVER)
async with session.post(url, data=json.dumps(query)) as response:
if response.status != 200:
message = "Buildhub is not available ({})".format(response.status)
url = "https://mozilla-services.github.io/buildhub/?products[0]={}".format(product)
raise TaskError(message, url=url)
data = await response.json()
versions = sorted([r['key'] for r in data['aggregations']['by_version']['buckets']
if strip_candidate_info(r['key']) == r['key']],
key=lambda version: build_version_id(version))
if not versions:
message = "Couldn't find any version matching."
url = "https://mozilla-services.github.io/buildhub/?products[0]={}".format(product)
raise TaskError(message, url=url)
return versions
def get_buildhub_url(product, version, channel):
channel_value = channel.value.lower()
if product == "devedition":
channel_value = "aurora"
url = ("https://mozilla-services.github.io/buildhub/"
"?versions[0]={}&products[0]={}&channel[0]={}")
return url.format(version, product, channel_value)
async def get_build_ids_for_version(product, version, *, size=10):
channel = get_version_channel(product, strip_candidate_info(version))
channel_value = channel.value.lower()
if product == "devedition":
channel_value = "aurora"
query = {
"aggs": {
"by_version": {
"terms": {
"field": "build.id",
"size": size,
"order": {
"_term": "desc"
}
}
}
},
"query": {
"bool": {
"filter": [
{
"term": {
"target.channel": channel_value
}
}, {
"term": {
"source.product": product
}
}, {
"term": {
"target.version": version
}
}
]
}
},
"size": 0
}
async with get_session() as session:
url = '{}/buckets/build-hub/collections/releases/search'
url = url.format(BUILDHUB_SERVER)
async with session.post(url, data=json.dumps(query)) as response:
data = await response.json()
build_ids = [r['key'] for r in data['aggregations']['by_version']['buckets']]
if not build_ids:
message = "Couldn't find any build matching."
raise TaskError(message, url=get_buildhub_url(product, version, channel))
return build_ids
async def buildhub(product, version):
if 'build' in version:
version = version.replace('build', 'rc')
try:
build_ids = await get_build_ids_for_version(product, version)
status = True
except TaskError:
status = False
channel = get_version_channel(product, strip_candidate_info(version))
exists_message = 'Build IDs for this release: {}'
missing_message = 'Buildhub does not contain any information about this release yet.'
if status:
if channel is Channel.NIGHTLY:
last_expected_nightly = yesterday(formating='%Y%m%d')
if build_ids[0][:8] < last_expected_nightly:
status = Status.INCOMPLETE
build_ids = build_ids[:3]
else:
build_ids = [bid for bid in build_ids if bid > last_expected_nightly]
exists_message = exists_message.format(', '.join(build_ids))
url = get_buildhub_url(product, version, channel)
return build_task_response(status, url, exists_message, missing_message)
heartbeat = heartbeat_factory('{}/__heartbeat__'.format(BUILDHUB_SERVER))