-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathtaskcluster.py
More file actions
169 lines (127 loc) · 4.69 KB
/
Copy pathtaskcluster.py
File metadata and controls
169 lines (127 loc) · 4.69 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
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
164
165
166
167
168
169
# -*- coding: utf-8 -*-
import os
import structlog
import taskcluster
from taskcluster.helper import TaskclusterConfig
from code_coverage_bot.utils import download_file
logger = structlog.getLogger(__name__)
taskcluster_config = TaskclusterConfig("https://firefox-ci-tc.services.mozilla.com")
FINISHED_STATUSES = ["completed", "failed", "exception"]
ALL_STATUSES = FINISHED_STATUSES + ["unscheduled", "pending", "running"]
NAME_PARTS_TO_SKIP = ("opt", "debug", "e10s", "1proc")
def get_decision_task(branch, revision):
route = f"gecko.v2.{branch}.revision.{revision}.taskgraph.decision"
index = taskcluster_config.get_service("index")
try:
return index.findTask(route)["taskId"]
except taskcluster.exceptions.TaskclusterRestFailure as e:
if e.status_code == 404:
return None
raise
def get_task_details(task_id):
queue = taskcluster_config.get_service("queue")
return queue.task(task_id)
def get_task_status(task_id):
queue = taskcluster_config.get_service("queue")
return queue.status(task_id)
def get_task_artifacts(task_id):
queue = taskcluster_config.get_service("queue")
return queue.listLatestArtifacts(task_id)["artifacts"]
def get_tasks_in_group(group_id):
queue = taskcluster_config.get_service("queue")
token = None
while True:
query = {"limit": 200}
if token is not None:
query["continuationToken"] = token
response = queue.listTaskGroup(group_id, query=query)
yield from response["tasks"]
token = response.get("continuationToken")
if token is None:
break
def download_artifact(artifact_path: str, task_id: str, artifact_name: str) -> None:
if os.path.exists(artifact_path):
return
# Build artifact public url
# Use un-authenticated Taskcluster client to avoid taskcluster-proxy rewrite issue
# https://github.com/taskcluster/taskcluster-proxy/issues/44
queue = taskcluster.Queue({"rootUrl": "https://firefox-ci-tc.services.mozilla.com"})
url = queue.buildUrl("getLatestArtifact", task_id, artifact_name)
logger.debug("Downloading artifact", url=url)
download_file(url, artifact_path)
def is_coverage_task(task):
return "ccov" in task["metadata"]["name"].split("/")[0].split("-")
def name_to_chunk(name: str):
"""
Helper to convert a task name to a chunk
Used by chunk mapping
"""
# Some tests are run on build machines, we define placeholder chunks for those.
if name.startswith("build-signing-"):
return "build-signing"
elif name.startswith("build-"):
return "build"
name = name.split("/")[1]
return "-".join(p for p in name.split("-") if p not in NAME_PARTS_TO_SKIP)
def chunk_to_suite(chunk: str):
"""
Helper to convert a chunk to a suite (no numbers)
Used by chunk mapping
"""
return "-".join(p for p in chunk.split("-") if not p.isdigit())
def get_chunk(task):
"""
Build clean chunk name from a Taskcluster task
"""
suite = get_suite(task)
chunks = task["extra"].get("chunks", {})
if "current" in chunks:
return f'{suite}-{chunks["current"]}'
return suite
def get_suite(task):
"""
Build clean suite name from a Taskcluster task
"""
assert isinstance(task, dict)
tags = task["tags"]
extra = task["extra"]
if tags.get("kind") == "build":
return "build"
elif tags.get("kind") == "build-signing":
return "build-signing"
elif tags.get("kind") == "source-test":
return "source-test"
elif tags.get("kind") == "fuzzing":
return "fuzzing"
elif "suite" in extra:
if isinstance(extra["suite"], dict):
return extra["suite"]["name"]
return extra["suite"]
else:
return tags.get("test-type")
raise Exception(f"Unknown chunk for {task}")
def get_platform(task):
"""
Build clean platform from a Taskcluster task
"""
assert isinstance(task, dict)
tags = task.get("tags", {})
platform = tags.get("os")
# Fallback on parsing the task name for signing tasks, as they don't have "os" in their tags.
name = task.get("metadata", {}).get("name", "")
if not platform and "signing" in name:
name = name.split("/")[0]
if "linux" in name:
platform = "linux"
if "win" in name:
assert platform is None
platform = "windows"
if "mac" in name:
assert platform is None
platform = "macosx"
if not platform:
raise Exception(f"Unknown platform for {task}")
# Weird case for android build on Linux docker
if platform == "linux" and tags.get("android-stuff"):
return "android"
return platform