Debian Codegraph @

third_party/python/taskcluster_taskgraph/taskgraph/util/taskgraph.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 """
6 Tools for interacting with existing taskgraphs.
7 """
8
9 from taskgraph.util.taskcluster import find_task_id, get_artifact
10
11
12 def find_decision_task(parameters, graph_config):
13 """Given the parameters for this action, find the taskId of the decision
14 task"""
15 if parameters.get("repository_type", "hg") == "hg":
16 return find_task_id(
17 "{}.v2.{}.pushlog-id.{}.decision".format(
18 graph_config["trust-domain"],
19 parameters["project"],
20 parameters["pushlog_id"],
21 )
22 )
23 elif parameters["repository_type"] == "git":
24 return find_task_id(
25 "{}.v2.{}.revision.{}.taskgraph.decision".format(
26 graph_config["trust-domain"],
27 parameters["project"],
28 parameters["head_rev"],
29 )
30 )
31 else:
32 raise Exception(
33 "Unknown repository_type {}!".format(parameters["repository_type"])
34 )
35
36
37 def find_existing_tasks_from_previous_kinds(
38 full_task_graph, previous_graph_ids, rebuild_kinds
39 ):
40 """Given a list of previous decision/action taskIds and kinds to ignore
41 from the previous graphs, return a dictionary of labels-to-taskids to use
42 as ``existing_tasks`` in the optimization step."""
43 existing_tasks = {}
44 for previous_graph_id in previous_graph_ids:
45 label_to_taskid = get_artifact(previous_graph_id, "public/label-to-taskid.json")
46 kind_labels = {
47 t.label
48 for t in full_task_graph.tasks.values()
49 if t.attributes["kind"] not in rebuild_kinds
50 }
51 for label in set(label_to_taskid.keys()).intersection(kind_labels):
52 existing_tasks[label] = label_to_taskid[label]
53 return existing_tasks