File: partials_zucchini.py

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (122 lines) | stat: -rw-r--r-- 4,491 bytes parent folder | download
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
# 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 partials task into an actual task description.
"""

import json

from taskgraph.transforms.base import TransformSequence
from taskgraph.util.dependencies import get_primary_dependency
from taskgraph.util.treeherder import inherit_treeherder_from_dep

from gecko_taskgraph.util.attributes import release_level
from gecko_taskgraph.util.partials import get_builds
from gecko_taskgraph.util.platforms import architecture
from gecko_taskgraph.util.scriptworker import (
    get_devedition_signing_type,
    get_signing_type,
)

transforms = TransformSequence()


def identify_desired_signing_keys(config):
    """
    Determine the signing certificate type to use for MAR validation.
    It identifies the appropriate signing type based on the release product
    and configuration parameters, handling special logic for devedition releases.

    Args:
        config: The task graph configuration object containing:
    Returns:
        str: The signing type (defined in util/scriptworker.py)
    """
    if config.params["release_product"] == "devedition":
        return get_devedition_signing_type(config=config)
    return get_signing_type(config=config)


@transforms.add
def make_task_description(config, tasks):
    # If no balrog release history, then don't generate partials
    if not config.params.get("release_history"):
        return
    for task in tasks:
        dep_task = get_primary_dependency(config, task)
        assert dep_task

        locale = task["attributes"].get("locale")
        build_locale = locale or "en-US"

        build_platform = task["attributes"]["build_platform"]
        builds = get_builds(
            config.params["release_history"], build_platform, build_locale
        )

        # If the list is empty there's no available history for this platform
        # and locale combination, so we can't build any partials.
        if not builds:
            continue

        mar_channel_id = task["attributes"]["mar-channel-id"]

        locale_suffix = ""
        if locale:
            locale_suffix = f"{locale}/"
        artifact_path = f"{locale_suffix}target.complete.mar"

        # Fetches from upstream repackage task
        task["fetches"][dep_task.kind] = [artifact_path]

        cert_type = identify_desired_signing_keys(config).replace("-signing", "")

        from_data = []
        update_number = 1
        for build in sorted(builds):
            partial_info = {
                "url": builds[build]["mar_url"],
                "update_number": update_number,
                "dest_mar": build,
            }
            if "previousVersion" in builds[build]:
                partial_info["previousVersion"] = builds[build]["previousVersion"]
            from_data.append(partial_info)
        from_mars_json = json.dumps(from_data, separators=(",", ":"))

        extra_params = [
            f"--arch={architecture(build_platform)}",
            f"--locale={build_locale}",
            f"--target=/builds/worker/artifacts/{locale_suffix}",
            f"--from-mars-json='{from_mars_json}'",
            f"--mar-channel-id='{mar_channel_id}'",
            f"--branch={config.params['project']}",
            f"--cert-path=/builds/worker/workspace/keys/{cert_type}.pubkey",
        ]

        if release_level(config.params) == "staging":
            extra_params.append("--allow-staging-urls")

        for artifact in dep_task.attributes["release_artifacts"]:
            if artifact.endswith(".complete.mar"):
                extra_params.append(f"--to-mar-url=<{dep_task.kind}/{artifact}>")
                break

        full_cmd = (
            task["run"]["command"]["artifact-reference"] + "\n" + " ".join(extra_params)
        )
        # remove all whitespace from the command
        full_cmd = " ".join([line.strip() for line in full_cmd.splitlines()])
        task["run"]["command"]["artifact-reference"] = full_cmd

        task["description"] = (
            f"Partials task for locale '{build_locale}' for build '{build_platform}'"
        )

        task["treeherder"] = inherit_treeherder_from_dep(task, dep_task)
        # TODO: Reset this to tier 1 once D272679 is landed
        task["treeherder"]["tier"] = 3
        task["treeherder"]["symbol"] = f"pz({locale or 'N'})"

        yield task