tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

geckodriver_signing.py (5124B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 """
      5 Transform the repackage signing task into an actual task description.
      6 """
      7 
      8 from taskgraph.transforms.base import TransformSequence
      9 from taskgraph.util.dependencies import get_primary_dependency
     10 from taskgraph.util.schema import Schema
     11 from voluptuous import Optional
     12 
     13 from gecko_taskgraph.transforms.task import task_description_schema
     14 from gecko_taskgraph.util.attributes import copy_attributes_from_dependent_job
     15 from gecko_taskgraph.util.scriptworker import get_signing_type_per_platform
     16 
     17 repackage_signing_description_schema = Schema({
     18    Optional("label"): str,
     19    Optional("attributes"): task_description_schema["attributes"],
     20    Optional("dependencies"): task_description_schema["dependencies"],
     21    Optional("treeherder"): task_description_schema["treeherder"],
     22    Optional("shipping-phase"): task_description_schema["shipping-phase"],
     23    Optional("task-from"): task_description_schema["task-from"],
     24    Optional("run-on-repo-type"): task_description_schema["run-on-repo-type"],
     25 })
     26 
     27 transforms = TransformSequence()
     28 
     29 
     30 @transforms.add
     31 def remove_name(config, jobs):
     32    for job in jobs:
     33        if "name" in job:
     34            del job["name"]
     35        yield job
     36 
     37 
     38 transforms.add_validate(repackage_signing_description_schema)
     39 
     40 
     41 @transforms.add
     42 def make_signing_description(config, jobs):
     43    for job in jobs:
     44        dep_job = get_primary_dependency(config, job)
     45        assert dep_job
     46 
     47        attributes = copy_attributes_from_dependent_job(dep_job)
     48        attributes["repackage_type"] = "repackage-signing"
     49 
     50        treeherder = job.get("treeherder", {})
     51        dep_treeherder = dep_job.task.get("extra", {}).get("treeherder", {})
     52        treeherder.setdefault(
     53            "symbol", "{}(gd-s)".format(dep_treeherder["groupSymbol"])
     54        )
     55        treeherder.setdefault(
     56            "platform", dep_job.task.get("extra", {}).get("treeherder-platform")
     57        )
     58        treeherder.setdefault("tier", dep_treeherder.get("tier", 1))
     59        treeherder.setdefault("kind", "build")
     60 
     61        dependencies = {dep_job.kind: dep_job.label}
     62        signing_dependencies = dep_job.dependencies
     63        dependencies.update({
     64            k: v for k, v in signing_dependencies.items() if k != "docker-image"
     65        })
     66 
     67        description = "Signing Geckodriver for build '{}'".format(
     68            attributes.get("build_platform"),
     69        )
     70 
     71        build_platform = dep_job.attributes.get("build_platform")
     72        is_shippable = dep_job.attributes.get("shippable")
     73        signing_type = get_signing_type_per_platform(
     74            build_platform, is_shippable, config
     75        )
     76 
     77        upstream_artifacts = _craft_upstream_artifacts(
     78            dep_job, dep_job.kind, build_platform
     79        )
     80 
     81        platform = build_platform.rsplit("-", 1)[0]
     82 
     83        task = {
     84            "label": job["label"],
     85            "description": description,
     86            "worker-type": "linux-signing",
     87            "worker": {
     88                "implementation": "scriptworker-signing",
     89                "signing-type": signing_type,
     90                "upstream-artifacts": upstream_artifacts,
     91            },
     92            "dependencies": dependencies,
     93            "attributes": attributes,
     94            "treeherder": treeherder,
     95            "run-on-projects": ["mozilla-central"],
     96            "run-on-repo-type": job.get("run-on-repo-type", ["git", "hg"]),
     97            "index": {"product": "geckodriver", "job-name": platform},
     98        }
     99 
    100        if build_platform.startswith("macosx"):
    101            worker_type = task["worker-type"]
    102            worker_type_alias_map = {
    103                "linux-depsigning": "mac-depsigning",
    104                "linux-signing": "mac-signing",
    105            }
    106 
    107            assert worker_type in worker_type_alias_map, (
    108                "Make sure to adjust the below worker_type_alias logic for "
    109                "mac if you change the signing workerType aliases!"
    110                f" ({worker_type} not found in mapping)"
    111            )
    112            worker_type = worker_type_alias_map[worker_type]
    113 
    114            task["worker-type"] = worker_type_alias_map[task["worker-type"]]
    115            task["worker"]["implementation"] = "iscript"
    116            task["worker"]["mac-behavior"] = "mac_geckodriver"
    117 
    118        yield task
    119 
    120 
    121 def _craft_upstream_artifacts(dep_job, dependency_kind, build_platform):
    122    if build_platform.startswith("win"):
    123        signing_format = "gcp_prod_autograph_authenticode_202412"
    124    elif build_platform.startswith("linux"):
    125        signing_format = "gcp_prod_autograph_gpg"
    126    elif build_platform.startswith("macosx"):
    127        signing_format = "mac_geckodriver"
    128    else:
    129        raise ValueError(f'Unsupported build platform "{build_platform}"')
    130 
    131    return [
    132        {
    133            "taskId": {"task-reference": f"<{dependency_kind}>"},
    134            "taskType": "build",
    135            "paths": [dep_job.attributes["toolchain-artifact"]],
    136            "formats": [signing_format],
    137        }
    138    ]