worker_types.py 6.14 KB
Newer Older
Johan Lorenzo's avatar
Johan Lorenzo committed
1
2
3
4
5
6
7
8
# 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 __future__ import absolute_import, print_function, unicode_literals

from six import text_type

9
from voluptuous import Any, Required, Optional
Johan Lorenzo's avatar
Johan Lorenzo committed
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

from taskgraph.util.schema import taskref_or_string
from taskgraph.transforms.task import payload_builder


@payload_builder(
    "scriptworker-signing",
    schema={
        # the maximum time to run, in seconds
        Required("max-run-time"): int,
        Required("signing-type"): text_type,
        # list of artifact URLs for the artifacts that should be signed
        Required("upstream-artifacts"): [
            {
                # taskId of the task with the artifact
                Required("taskId"): taskref_or_string,
                # type of signing task (for CoT)
                Required("taskType"): text_type,
                # Paths to the artifacts to sign
                Required("paths"): [text_type],
                # Signing formats to use on each of the paths
                Required("formats"): [text_type],
            }
        ],
    },
)
def build_scriptworker_signing_payload(config, task, task_def):
    worker = task["worker"]

    task_def["tags"]["worker-implementation"] = "scriptworker"

    task_def["payload"] = {
        "maxRunTime": worker["max-run-time"],
        "upstreamArtifacts": worker["upstream-artifacts"],
    }

    formats = set()
    for artifacts in worker["upstream-artifacts"]:
        formats.update(artifacts["formats"])

    scope_prefix = config.graph_config["scriptworker"]["scope-prefix"]
    task_def["scopes"].append(
        "{}:signing:cert:{}".format(scope_prefix, worker["signing-type"])
    )
    task_def["scopes"].extend(
        [
            "{}:signing:format:{}".format(scope_prefix, format)
            for format in sorted(formats)
        ]
    )


@payload_builder(
    "scriptworker-pushapk",
    schema={
        Required("upstream-artifacts"): [
            {
                Required("taskId"): taskref_or_string,
                Required("taskType"): text_type,
                Required("paths"): [text_type],
            }
        ],
72
        Required("certificate-alias"): text_type,
Johan Lorenzo's avatar
Johan Lorenzo committed
73
74
75
76
77
78
79
80
81
82
83
84
        Required("channel"): text_type,
        Required("commit"): bool,
        Required("product"): text_type,
        Required("dep"): bool,
    },
)
def build_push_apk_payload(config, task, task_def):
    worker = task["worker"]

    task_def["tags"]["worker-implementation"] = "scriptworker"

    task_def["payload"] = {
85
86
        "certificate_alias": worker["certificate-alias"],
        "channel": worker["channel"],
Johan Lorenzo's avatar
Johan Lorenzo committed
87
88
89
90
91
92
93
94
95
96
        "commit": worker["commit"],
        "upstreamArtifacts": worker["upstream-artifacts"],
    }

    scope_prefix = config.graph_config["scriptworker"]["scope-prefix"]
    task_def["scopes"].append(
        "{}:googleplay:product:{}{}".format(
            scope_prefix, worker["product"], ":dep" if worker["dep"] else ""
        )
    )
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


@payload_builder(
    "scriptworker-shipit",
    schema={
        Required("upstream-artifacts"): [
            {
                Required("taskId"): taskref_or_string,
                Required("taskType"): text_type,
                Required("paths"): [text_type],
            }
        ],
        Required("release-name"): text_type,
    },
)
112
def build_shipit_payload(config, task, task_def):
113
114
115
116
117
118
119
    worker = task["worker"]

    task_def["tags"]["worker-implementation"] = "scriptworker"

    task_def['payload'] = {
        'release_name': worker['release-name']
    }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159


@payload_builder(
    "scriptworker-github",
    schema={
        Required("upstream-artifacts"): [
            {
                Required("taskId"): taskref_or_string,
                Required("taskType"): text_type,
                Required("paths"): [text_type],
            }
        ],
        Required("artifact-map"): [object],
        Required("action"): text_type,
        Required("git-tag"): text_type,
        Required("git-revision"): text_type,
        Required("github-project"): text_type,
        Required("is-prerelease"): bool,
        Required("release-name"): text_type,
    },
)
def build_github_release_payload(config, task, task_def):
    worker = task["worker"]

    task_def["tags"]["worker-implementation"] = "scriptworker"

    task_def["payload"] = {
        "artifactMap": worker["artifact-map"],
        "gitTag": worker["git-tag"],
        "gitRevision": worker["git-revision"],
        "isPrerelease": worker["is-prerelease"],
        "releaseName": worker["release-name"],
        "upstreamArtifacts": worker["upstream-artifacts"],
    }

    scope_prefix = config.graph_config["scriptworker"]["scope-prefix"]
    task_def["scopes"].extend([
        "{}:github:project:{}".format(scope_prefix, worker["github-project"]),
        "{}:github:action:{}".format(scope_prefix, worker["action"]),
    ])
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174


@payload_builder(
    "scriptworker-tree",
    schema={
        Optional("upstream-artifacts"): [
            {
                Optional("taskId"): taskref_or_string,
                Optional("taskType"): text_type,
                Optional("paths"): [text_type],
            }
        ],
        Required("bump"): bool,
        Optional("bump-files"): [text_type],
        Optional("push"): bool,
175
        Optional("branch"): text_type,
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    },
)
def build_version_bump_payload(config, task, task_def):
    worker = task["worker"]
    task_def["tags"]["worker-implementation"] = "scriptworker"

    task_def['payload'] = {'actions': []}
    actions = task_def['payload']['actions']

    if worker['bump']:
        if not worker['bump-files']:
            raise Exception("Version Bump requested without bump-files")

        bump_info = {}
        bump_info["next_version"] = config.params["next_version"]
        bump_info['files'] = worker['bump-files']
        task_def['payload']['version_bump_info'] = bump_info
        actions.append('version_bump')

    if worker["push"]:
        task_def['payload']['push'] = True

    if worker.get('force-dry-run'):
        task_def['payload']['dry_run'] = True
200
201
202

    if worker.get("branch"):
        task_def["payload"]["branch"] = worker["branch"]