taskgraph.py (1691B)
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 head_rev_param = "{}head_rev".format(graph_config["project-repo-param-prefix"]) 16 return find_task_id( 17 "{}.v2.{}.revision.{}.taskgraph.decision".format( 18 graph_config["trust-domain"], 19 parameters["project"], 20 parameters[head_rev_param], 21 ) 22 ) 23 24 25 def find_existing_tasks(previous_graph_ids): 26 existing_tasks = {} 27 for previous_graph_id in previous_graph_ids: 28 label_to_taskid = get_artifact(previous_graph_id, "public/label-to-taskid.json") 29 existing_tasks.update(label_to_taskid) 30 return existing_tasks 31 32 33 def find_existing_tasks_from_previous_kinds( 34 full_task_graph, previous_graph_ids, rebuild_kinds 35 ): 36 """Given a list of previous decision/action taskIds and kinds to ignore 37 from the previous graphs, return a dictionary of labels-to-taskids to use 38 as ``existing_tasks`` in the optimization step.""" 39 existing_tasks = find_existing_tasks(previous_graph_ids) 40 kind_labels = { 41 t.label 42 for t in full_task_graph.tasks.values() 43 if t.attributes["kind"] not in rebuild_kinds 44 } 45 return { 46 label: taskid 47 for (label, taskid) in existing_tasks.items() 48 if label in kind_labels 49 }