filter_tasks.py (3639B)
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 import re 6 7 from taskgraph.filter_tasks import filter_task 8 from taskgraph.parameters import Parameters 9 from taskgraph.target_tasks import get_method 10 11 from gecko_taskgraph.target_tasks import ( 12 filter_by_regex, 13 filter_by_uncommon_try_tasks, 14 filter_out_shippable, 15 filter_unsupported_artifact_builds, 16 target_tasks_default, 17 ) 18 19 20 @filter_task("try_auto") 21 def target_tasks_try_auto(full_task_graph, parameters, graph_config): 22 """Target the tasks which have indicated they should be run on autoland 23 (rather than try) via the `run_on_projects` attributes. 24 25 Should do the same thing as the `default` target tasks method. 26 """ 27 params = dict(parameters) 28 params["project"] = "autoland" 29 params["target_tasks_method"] = "default" 30 parameters = Parameters(**params) 31 32 regex_filters = parameters["try_task_config"].get("tasks-regex") 33 include_regexes = exclude_regexes = [] 34 if regex_filters: 35 include_regexes = [re.compile(r) for r in regex_filters.get("include", [])] 36 exclude_regexes = [re.compile(r) for r in regex_filters.get("exclude", [])] 37 38 filtered_for_default = target_tasks_default( 39 full_task_graph, parameters, graph_config 40 ) 41 filtered_for_try_auto = [ 42 l 43 for l, t in full_task_graph.tasks.items() 44 if filter_by_uncommon_try_tasks(t.label) 45 and filter_by_regex(t.label, include_regexes, mode="include") 46 and filter_by_regex(t.label, exclude_regexes, mode="exclude") 47 and filter_unsupported_artifact_builds(t, parameters) 48 and filter_out_shippable(t) 49 ] 50 return list(set(filtered_for_default) & set(filtered_for_try_auto)) 51 52 53 @filter_task("try_select_tasks") 54 def target_tasks_try_select(full_task_graph, parameters, graph_config): 55 tasks = target_tasks_try_select_uncommon(full_task_graph, parameters, graph_config) 56 return [l for l in tasks if filter_by_uncommon_try_tasks(l)] 57 58 59 @filter_task("try_select_tasks_uncommon") 60 def target_tasks_try_select_uncommon(full_task_graph, parameters, graph_config): 61 from gecko_taskgraph.decision import PER_PROJECT_PARAMETERS 62 63 if parameters["target_tasks_method"] != "default": 64 # A parameter set using a custom target_tasks_method was explicitly 65 # passed in to `./mach try` via `--parameters`. In this case, don't 66 # override it or do anything special. 67 tasks = get_method(parameters["target_tasks_method"])( 68 full_task_graph, parameters, graph_config 69 ) 70 else: 71 # Union the tasks between autoland and mozilla-central as a sensible 72 # default. This is likely the set of tasks that most users are 73 # attempting to select from. 74 projects = ("autoland", "mozilla-central") 75 if parameters["project"] not in projects: 76 projects = (parameters["project"],) 77 78 tasks = set() 79 for project in projects: 80 params = dict(parameters) 81 params["project"] = project 82 parameters = Parameters(**params) 83 84 try: 85 target_tasks_method = PER_PROJECT_PARAMETERS[project][ 86 "target_tasks_method" 87 ] 88 except KeyError: 89 target_tasks_method = "default" 90 91 tasks.update( 92 get_method(target_tasks_method)( 93 full_task_graph, parameters, graph_config 94 ) 95 ) 96 97 return sorted(tasks)