summaryrefslogtreecommitdiffstats
path: root/taskcluster/gecko_taskgraph/transforms/bouncer_submission.py
blob: fb5b17d3b365609def2cc182499527c49c840c34 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# 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/.
"""
Add from parameters.yml into bouncer submission tasks.
"""


import copy
import logging

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

from gecko_taskgraph.transforms.l10n import parse_locales_file
from gecko_taskgraph.util.attributes import release_level
from gecko_taskgraph.util.scriptworker import get_release_config

logger = logging.getLogger(__name__)


FTP_PLATFORMS_PER_BOUNCER_PLATFORM = {
    "linux": "linux-i686",
    "linux64": "linux-x86_64",
    "osx": "mac",
    "win": "win32",
    "win64": "win64",
    "win64-aarch64": "win64-aarch64",
}

# :lang is interpolated by bouncer at runtime
CANDIDATES_PATH_TEMPLATE = "/{ftp_product}/candidates/{version}-candidates/build{build_number}/\
{update_folder}{ftp_platform}/:lang/{file}"
RELEASES_PATH_TEMPLATE = "/{ftp_product}/releases/{version}/\
{update_folder}{ftp_platform}/:lang/{file}"


CONFIG_PER_BOUNCER_PRODUCT = {
    "complete-mar": {
        "name_postfix": "-Complete",
        "path_template": RELEASES_PATH_TEMPLATE,
        "file_names": {
            "default": "{product}-{version}.complete.mar",
        },
    },
    "complete-mar-candidates": {
        "name_postfix": "build{build_number}-Complete",
        "path_template": CANDIDATES_PATH_TEMPLATE,
        "file_names": {
            "default": "{product}-{version}.complete.mar",
        },
    },
    "installer": {
        "path_template": RELEASES_PATH_TEMPLATE,
        "file_names": {
            "linux": "{product}-{version}.tar.bz2",
            "linux64": "{product}-{version}.tar.bz2",
            "osx": "{pretty_product}%20{version}.dmg",
            "win": "{pretty_product}%20Setup%20{version}.exe",
            "win64": "{pretty_product}%20Setup%20{version}.exe",
            "win64-aarch64": "{pretty_product}%20Setup%20{version}.exe",
        },
    },
    "partial-mar": {
        "name_postfix": "-Partial-{previous_version}",
        "path_template": RELEASES_PATH_TEMPLATE,
        "file_names": {
            "default": "{product}-{previous_version}-{version}.partial.mar",
        },
    },
    "partial-mar-candidates": {
        "name_postfix": "build{build_number}-Partial-{previous_version}build{previous_build}",
        "path_template": CANDIDATES_PATH_TEMPLATE,
        "file_names": {
            "default": "{product}-{previous_version}-{version}.partial.mar",
        },
    },
    "stub-installer": {
        "name_postfix": "-stub",
        # We currently have a sole win32 stub installer that is to be used
        # in all windows platforms to toggle between full installers
        "path_template": RELEASES_PATH_TEMPLATE.replace("{ftp_platform}", "win32"),
        "file_names": {
            "win": "{pretty_product}%20Installer.exe",
            "win64": "{pretty_product}%20Installer.exe",
            "win64-aarch64": "{pretty_product}%20Installer.exe",
        },
    },
    "msi": {
        "name_postfix": "-msi-SSL",
        "path_template": RELEASES_PATH_TEMPLATE,
        "file_names": {
            "win": "{pretty_product}%20Setup%20{version}.msi",
            "win64": "{pretty_product}%20Setup%20{version}.msi",
        },
    },
    "msix": {
        "name_postfix": "-msix-SSL",
        "path_template": RELEASES_PATH_TEMPLATE.replace(":lang", "multi"),
        "file_names": {
            "win": "{pretty_product}%20Setup%20{version}.msix",
            "win64": "{pretty_product}%20Setup%20{version}.msix",
        },
    },
    "pkg": {
        "name_postfix": "-pkg-SSL",
        "path_template": RELEASES_PATH_TEMPLATE,
        "file_names": {
            "osx": "{pretty_product}%20{version}.pkg",
        },
    },
    "langpack": {
        "name_postfix": "-langpack-SSL",
        "path_template": RELEASES_PATH_TEMPLATE.replace(":lang", "xpi"),
        "file_names": {"default": ":lang.xpi"},
    },
}
CONFIG_PER_BOUNCER_PRODUCT["installer-ssl"] = copy.deepcopy(
    CONFIG_PER_BOUNCER_PRODUCT["installer"]
)
CONFIG_PER_BOUNCER_PRODUCT["installer-ssl"]["name_postfix"] = "-SSL"

transforms = TransformSequence()


@transforms.add
def make_task_worker(config, jobs):
    for job in jobs:
        resolve_keyed_by(
            job,
            "worker-type",
            item_name=job["name"],
            **{"release-level": release_level(config.params["project"])}
        )
        resolve_keyed_by(
            job,
            "scopes",
            item_name=job["name"],
            **{"release-level": release_level(config.params["project"])}
        )
        resolve_keyed_by(
            job,
            "bouncer-products",
            item_name=job["name"],
            **{"release-type": config.params["release_type"]}
        )

        # No need to filter out ja-JP-mac, we need to upload both; but we do
        # need to filter out the platforms they come with
        all_locales = sorted(
            locale
            for locale in parse_locales_file(job["locales-file"]).keys()
            if locale not in ("linux", "win32", "osx")
        )

        job["worker"]["locales"] = all_locales
        job["worker"]["entries"] = craft_bouncer_entries(config, job)

        del job["locales-file"]
        del job["bouncer-platforms"]
        del job["bouncer-products"]

        if job["worker"]["entries"]:
            yield job
        else:
            logger.warning(
                'No bouncer entries defined in bouncer submission task for "{}". \
Job deleted.'.format(
                    job["name"]
                )
            )


def craft_bouncer_entries(config, job):
    release_config = get_release_config(config)

    product = job["shipping-product"]
    bouncer_platforms = job["bouncer-platforms"]

    current_version = release_config["version"]
    current_build_number = release_config["build_number"]

    bouncer_products = job["bouncer-products"]
    previous_versions_string = release_config.get("partial_versions", None)
    if previous_versions_string:
        previous_versions = previous_versions_string.split(", ")
    else:
        logger.warning(
            'No partials defined! Bouncer submission task won\'t send any \
partial-related entry for "{}"'.format(
                job["name"]
            )
        )
        bouncer_products = [
            bouncer_product
            for bouncer_product in bouncer_products
            if "partial" not in bouncer_product
        ]
        previous_versions = [None]

    project = config.params["project"]

    return {
        craft_bouncer_product_name(
            product,
            bouncer_product,
            current_version,
            current_build_number,
            previous_version,
        ): {
            "options": {
                "add_locales": False if "msix" in bouncer_product else True,
                "ssl_only": craft_ssl_only(bouncer_product, project),
            },
            "paths_per_bouncer_platform": craft_paths_per_bouncer_platform(
                product,
                bouncer_product,
                bouncer_platforms,
                current_version,
                current_build_number,
                previous_version,
            ),
        }
        for bouncer_product in bouncer_products
        for previous_version in previous_versions
    }


def craft_paths_per_bouncer_platform(
    product,
    bouncer_product,
    bouncer_platforms,
    current_version,
    current_build_number,
    previous_version=None,
):
    paths_per_bouncer_platform = {}
    for bouncer_platform in bouncer_platforms:
        file_names_per_platform = CONFIG_PER_BOUNCER_PRODUCT[bouncer_product][
            "file_names"
        ]
        file_name_template = file_names_per_platform.get(
            bouncer_platform, file_names_per_platform.get("default", None)
        )
        if not file_name_template:
            # Some bouncer product like stub-installer are only meant to be on Windows.
            # Thus no default value is defined there
            continue

        file_name_product = _craft_filename_product(product)
        file_name = file_name_template.format(
            product=file_name_product,
            pretty_product=file_name_product.capitalize(),
            version=current_version,
            previous_version=split_build_data(previous_version)[0],
        )

        path_template = CONFIG_PER_BOUNCER_PRODUCT[bouncer_product]["path_template"]
        file_relative_location = path_template.format(
            ftp_product=_craft_ftp_product(product),
            version=current_version,
            build_number=current_build_number,
            update_folder="update/" if "-mar" in bouncer_product else "",
            ftp_platform=FTP_PLATFORMS_PER_BOUNCER_PLATFORM[bouncer_platform],
            file=file_name,
        )

        paths_per_bouncer_platform[bouncer_platform] = file_relative_location

    return paths_per_bouncer_platform


def _craft_ftp_product(product):
    return product.lower()


def _craft_filename_product(product):
    return "firefox" if product == "devedition" else product


@attr.s
class InvalidSubstitution:
    error = attr.ib(type=str)

    def __str__(self):
        raise Exception("Partial is being processed, but no previous version defined.")


def craft_bouncer_product_name(
    product,
    bouncer_product,
    current_version,
    current_build_number=None,
    previous_version=None,
):
    if previous_version is None:
        previous_version = previous_build = InvalidSubstitution(
            "Partial is being processed, but no previous version defined."
        )
    else:
        previous_version, previous_build = split_build_data(previous_version)
    postfix = (
        CONFIG_PER_BOUNCER_PRODUCT[bouncer_product]
        .get("name_postfix", "")
        .format(
            build_number=current_build_number,
            previous_version=previous_version,
            previous_build=previous_build,
        )
    )

    return "{product}-{version}{postfix}".format(
        product=product.capitalize(), version=current_version, postfix=postfix
    )


def craft_ssl_only(bouncer_product, project):
    # XXX ESR is the only channel where we force serve the installer over SSL
    if "-esr" in project and bouncer_product == "installer":
        return True

    return bouncer_product not in (
        "complete-mar",
        "complete-mar-candidates",
        "installer",
        "partial-mar",
        "partial-mar-candidates",
    )


def split_build_data(version):
    if version and "build" in version:
        return version.split("build")
    return version, InvalidSubstitution("k")