File: filter_tasks.py

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (97 lines) | stat: -rw-r--r-- 3,639 bytes parent folder | download | duplicates (10)
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import re

from taskgraph.filter_tasks import filter_task
from taskgraph.parameters import Parameters
from taskgraph.target_tasks import get_method

from gecko_taskgraph.target_tasks import (
    filter_by_regex,
    filter_by_uncommon_try_tasks,
    filter_out_shippable,
    filter_unsupported_artifact_builds,
    target_tasks_default,
)


@filter_task("try_auto")
def target_tasks_try_auto(full_task_graph, parameters, graph_config):
    """Target the tasks which have indicated they should be run on autoland
    (rather than try) via the `run_on_projects` attributes.

    Should do the same thing as the `default` target tasks method.
    """
    params = dict(parameters)
    params["project"] = "autoland"
    params["target_tasks_method"] = "default"
    parameters = Parameters(**params)

    regex_filters = parameters["try_task_config"].get("tasks-regex")
    include_regexes = exclude_regexes = []
    if regex_filters:
        include_regexes = [re.compile(r) for r in regex_filters.get("include", [])]
        exclude_regexes = [re.compile(r) for r in regex_filters.get("exclude", [])]

    filtered_for_default = target_tasks_default(
        full_task_graph, parameters, graph_config
    )
    filtered_for_try_auto = [
        l
        for l, t in full_task_graph.tasks.items()
        if filter_by_uncommon_try_tasks(t.label)
        and filter_by_regex(t.label, include_regexes, mode="include")
        and filter_by_regex(t.label, exclude_regexes, mode="exclude")
        and filter_unsupported_artifact_builds(t, parameters)
        and filter_out_shippable(t)
    ]
    return list(set(filtered_for_default) & set(filtered_for_try_auto))


@filter_task("try_select_tasks")
def target_tasks_try_select(full_task_graph, parameters, graph_config):
    tasks = target_tasks_try_select_uncommon(full_task_graph, parameters, graph_config)
    return [l for l in tasks if filter_by_uncommon_try_tasks(l)]


@filter_task("try_select_tasks_uncommon")
def target_tasks_try_select_uncommon(full_task_graph, parameters, graph_config):
    from gecko_taskgraph.decision import PER_PROJECT_PARAMETERS

    if parameters["target_tasks_method"] != "default":
        # A parameter set using a custom target_tasks_method was explicitly
        # passed in to `./mach try` via `--parameters`. In this case, don't
        # override it or do anything special.
        tasks = get_method(parameters["target_tasks_method"])(
            full_task_graph, parameters, graph_config
        )
    else:
        # Union the tasks between autoland and mozilla-central as a sensible
        # default. This is likely the set of tasks that most users are
        # attempting to select from.
        projects = ("autoland", "mozilla-central")
        if parameters["project"] not in projects:
            projects = (parameters["project"],)

        tasks = set()
        for project in projects:
            params = dict(parameters)
            params["project"] = project
            parameters = Parameters(**params)

            try:
                target_tasks_method = PER_PROJECT_PARAMETERS[project][
                    "target_tasks_method"
                ]
            except KeyError:
                target_tasks_method = "default"

            tasks.update(
                get_method(target_tasks_method)(
                    full_task_graph, parameters, graph_config
                )
            )

    return sorted(tasks)