summaryrefslogtreecommitdiffstats
path: root/taskcluster/gecko_taskgraph/transforms/merge_automation.py
blob: ca5f3b6bde4867da4c9ffbd02a9cdbaf5f964ca7 (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
# 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/.
"""
Transform the update generation task into an actual task description.
"""

from taskgraph.transforms.base import TransformSequence
from taskgraph.util.schema import resolve_keyed_by

transforms = TransformSequence()


@transforms.add
def handle_keyed_by(config, tasks):
    """Resolve fields that can be keyed by platform, etc."""
    if "merge_config" not in config.params:
        return
    merge_config = config.params["merge_config"]
    fields = [
        "worker.push",
        "worker-type",
        "worker.l10n-bump-info",
        "worker.source-repo",
    ]
    for task in tasks:
        for field in fields:
            resolve_keyed_by(
                task,
                field,
                item_name=task["name"],
                **{
                    "project": config.params["project"],
                    "release-type": config.params["release_type"],
                    "behavior": merge_config["behavior"],
                }
            )
        yield task


@transforms.add
def update_labels(config, tasks):
    for task in tasks:
        merge_config = config.params["merge_config"]
        task["label"] = "merge-{}".format(merge_config["behavior"])
        treeherder = task.get("treeherder", {})
        treeherder["symbol"] = "Rel({})".format(merge_config["behavior"])
        task["treeherder"] = treeherder
        yield task


@transforms.add
def add_payload_config(config, tasks):
    for task in tasks:
        if "merge_config" not in config.params:
            break
        merge_config = config.params["merge_config"]
        worker = task["worker"]
        worker["merge-info"] = config.graph_config["merge-automation"]["behaviors"][
            merge_config["behavior"]
        ]

        if "l10n-bump-info" in worker and worker["l10n-bump-info"] is None:
            del worker["l10n-bump-info"]

        # Override defaults, useful for testing.
        for field in [
            "from-repo",
            "from-branch",
            "to-repo",
            "to-branch",
            "fetch-version-from",
        ]:
            if merge_config.get(field):
                worker["merge-info"][field] = merge_config[field]

        worker["force-dry-run"] = merge_config["force-dry-run"]
        worker["ssh-user"] = merge_config.get("ssh-user-alias", "merge_user")
        if merge_config.get("push"):
            worker["push"] = merge_config["push"]
        yield task