summaryrefslogtreecommitdiffstats
path: root/comm/taskcluster/comm_taskgraph/try_option_syntax.py
blob: b401bfa7a2b8b5c76e0fba0dd4b31920b6f37e66 (plain)
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 logging

from gecko_taskgraph.target_tasks import (
    filter_by_uncommon_try_tasks,
    filter_unsupported_artifact_builds,
)
from gecko_taskgraph.try_option_syntax import TryOptionSyntax

logger = logging.getLogger(__name__)


class TryCCOptionSyntax(TryOptionSyntax):
    """
    Override parse_platforms in the superclass. Removed the attempt to replace
    macosx64 jobs with macosx64-shippable.
    """

    def parse_platforms(self, options, full_task_graph):
        platform_arg = options["platforms"]
        if platform_arg == "all":
            return None

        results = []
        for build in platform_arg.split(","):
            results.append(build)

        test_platforms = {
            t.attributes["test_platform"]
            for t in full_task_graph.tasks.values()
            if "test_platform" in t.attributes
        }
        build_platforms = {
            t.attributes["build_platform"]
            for t in full_task_graph.tasks.values()
            if "build_platform" in t.attributes
        }
        all_platforms = test_platforms | build_platforms
        bad_platforms = set(results) - all_platforms
        if bad_platforms:
            raise Exception("Unknown platform(s) [%s] specified for try" % ",".join(bad_platforms))

        return results


def _try_cc_option_syntax(full_task_graph, parameters, graph_config):
    """Generate a list of target tasks based on try syntax in
    parameters['message'] and, for context, the full task graph.

    Based on gecko_taskgraph.target_tasks._try_option_syntax. Removed talos
    and raptor references and use TryCCOptionSyntax.
    """
    options = TryCCOptionSyntax(parameters, full_task_graph, graph_config)
    target_tasks_labels = [
        t.label
        for t in full_task_graph.tasks.values()
        if options.task_matches(t)
        and filter_by_uncommon_try_tasks(t.label)
        and filter_unsupported_artifact_builds(t, parameters)
    ]

    attributes = {
        k: getattr(options, k)
        for k in [
            "no_retry",
            "tag",
        ]
    }

    for l in target_tasks_labels:
        task = full_task_graph[l]
        if "unittest_suite" in task.attributes:
            task.attributes["task_duplicates"] = options.trigger_tests

    for l in target_tasks_labels:
        task = full_task_graph[l]
        # If the developer wants test jobs to be rebuilt N times we add that value here
        if options.trigger_tests > 1 and "unittest_suite" in task.attributes:
            task.attributes["task_duplicates"] = options.trigger_tests

        task.attributes.update(attributes)

    # Add notifications here as well
    if options.notifications:
        for task in full_task_graph:
            owner = parameters.get("owner")
            routes = task.task.setdefault("routes", [])
            if options.notifications == "all":
                routes.append(f"notify.email.{owner}.on-any")
            elif options.notifications == "failure":
                routes.append(f"notify.email.{owner}.on-failed")
                routes.append(f"notify.email.{owner}.on-exception")

    return target_tasks_labels