summaryrefslogtreecommitdiffstats
path: root/taskcluster/gecko_taskgraph/actions/merge_automation.py
blob: 8b9455536b68d5deac27977f04a939f1becaba16 (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
98
99
# 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/.

from taskgraph.parameters import Parameters

from gecko_taskgraph.actions.registry import register_callback_action
from gecko_taskgraph.decision import taskgraph_decision
from gecko_taskgraph.util.attributes import RELEASE_PROMOTION_PROJECTS


def is_release_promotion_available(parameters):
    return parameters["project"] in RELEASE_PROMOTION_PROJECTS


@register_callback_action(
    name="merge-automation",
    title="Merge Day Automation",
    symbol="${input.behavior}",
    description="Merge repository branches.",
    permission="merge-automation",
    order=500,
    context=[],
    available=is_release_promotion_available,
    schema=lambda graph_config: {
        "type": "object",
        "properties": {
            "force-dry-run": {
                "type": "boolean",
                "description": "Override other options and do not push changes",
                "default": True,
            },
            "push": {
                "type": "boolean",
                "description": "Push changes using to_repo and to_branch",
                "default": False,
            },
            "behavior": {
                "type": "string",
                "description": "The type of release promotion to perform.",
                "enum": sorted(graph_config["merge-automation"]["behaviors"].keys()),
                "default": "central-to-beta",
            },
            "from-repo": {
                "type": "string",
                "description": "The URI of the source repository",
            },
            "to-repo": {
                "type": "string",
                "description": "The push URI of the target repository",
            },
            "from-branch": {
                "type": "string",
                "description": "The fx head of the source, such as central",
            },
            "to-branch": {
                "type": "string",
                "description": "The fx head of the target, such as beta",
            },
            "ssh-user-alias": {
                "type": "string",
                "description": "The alias of an ssh account to use when pushing changes.",
            },
            "fetch-version-from": {
                "type": "string",
                "description": "Path to file used when querying current version.",
            },
        },
        "required": ["behavior"],
    },
)
def merge_automation_action(parameters, graph_config, input, task_group_id, task_id):

    # make parameters read-write
    parameters = dict(parameters)

    parameters["target_tasks_method"] = "merge_automation"
    parameters["merge_config"] = {
        "force-dry-run": input.get("force-dry-run", False),
        "behavior": input["behavior"],
    }

    for field in [
        "from-repo",
        "from-branch",
        "to-repo",
        "to-branch",
        "ssh-user-alias",
        "push",
        "fetch-version-from",
    ]:
        if input.get(field):
            parameters["merge_config"][field] = input[field]
    parameters["tasks_for"] = "action"

    # make parameters read-only
    parameters = Parameters(**parameters)

    taskgraph_decision({"root": graph_config.root_dir}, parameters=parameters)