tor-browser

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

mar_signing.py (4861B)


      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 {partials,mar}-signing task into an actual task description.
      6 """
      7 
      8 import logging
      9 import os
     10 
     11 from taskgraph.transforms.base import TransformSequence
     12 from taskgraph.util.dependencies import get_primary_dependency
     13 from taskgraph.util.taskcluster import get_artifact_prefix
     14 from taskgraph.util.treeherder import inherit_treeherder_from_dep, join_symbol
     15 
     16 from gecko_taskgraph.util.attributes import (
     17    copy_attributes_from_dependent_job,
     18    sorted_unique_list,
     19 )
     20 from gecko_taskgraph.util.partials import get_partials_artifacts_from_params
     21 from gecko_taskgraph.util.scriptworker import get_signing_type_per_platform
     22 
     23 logger = logging.getLogger(__name__)
     24 
     25 SIGNING_FORMATS = {
     26    "mar-signing-autograph-stage": {
     27        "target.complete.mar": ["gcp_prod_autograph_stage_mar384"],
     28    },
     29    "default": {
     30        "target.complete.mar": ["gcp_prod_autograph_hash_only_mar384"],
     31    },
     32 }
     33 
     34 transforms = TransformSequence()
     35 
     36 
     37 def generate_partials_artifacts(job, release_history, platform, locale=None):
     38    artifact_prefix = get_artifact_prefix(job)
     39    if locale:
     40        artifact_prefix = f"{artifact_prefix}/{locale}"
     41    else:
     42        locale = "en-US"
     43 
     44    artifacts = get_partials_artifacts_from_params(release_history, platform, locale)
     45 
     46    upstream_artifacts = [
     47        {
     48            "taskId": {"task-reference": "<partials>"},
     49            "taskType": "partials",
     50            "paths": [f"{artifact_prefix}/{path}" for path, version in artifacts],
     51            "formats": ["gcp_prod_autograph_hash_only_mar384"],
     52        }
     53    ]
     54 
     55    return upstream_artifacts
     56 
     57 
     58 def generate_complete_artifacts(job, kind):
     59    upstream_artifacts = []
     60    if kind not in SIGNING_FORMATS:
     61        kind = "default"
     62    for artifact in job.attributes["release_artifacts"]:
     63        basename = os.path.basename(artifact)
     64        if basename in SIGNING_FORMATS[kind]:
     65            upstream_artifacts.append({
     66                "taskId": {"task-reference": f"<{job.kind}>"},
     67                "taskType": "build",
     68                "paths": [artifact],
     69                "formats": SIGNING_FORMATS[kind][basename],
     70            })
     71 
     72    return upstream_artifacts
     73 
     74 
     75 @transforms.add
     76 def make_task_description(config, jobs):
     77    for job in jobs:
     78        dep_job = get_primary_dependency(config, job)
     79        assert dep_job
     80 
     81        locale = dep_job.attributes.get("locale")
     82 
     83        treeherder = inherit_treeherder_from_dep(job, dep_job)
     84        treeherder.setdefault(
     85            "symbol", join_symbol(job.get("treeherder-group", "ms"), locale or "N")
     86        )
     87 
     88        label = job.get("label", f"{config.kind}-{dep_job.label}")
     89 
     90        dependencies = {dep_job.kind: dep_job.label}
     91        signing_dependencies = dep_job.dependencies
     92        # This is so we get the build task etc in our dependencies to
     93        # have better beetmover support.
     94        dependencies.update(signing_dependencies)
     95 
     96        attributes = copy_attributes_from_dependent_job(dep_job)
     97        attributes["required_signoffs"] = sorted_unique_list(
     98            attributes.get("required_signoffs", []), job.pop("required_signoffs")
     99        )
    100        attributes["shipping_phase"] = job["shipping-phase"]
    101        if locale:
    102            attributes["locale"] = locale
    103 
    104        build_platform = attributes.get("build_platform")
    105        if config.kind == "partials-signing":
    106            upstream_artifacts = generate_partials_artifacts(
    107                dep_job, config.params["release_history"], build_platform, locale
    108            )
    109        else:
    110            upstream_artifacts = generate_complete_artifacts(dep_job, config.kind)
    111 
    112        is_shippable = job.get(
    113            "shippable",
    114            dep_job.attributes.get("shippable"),  # First check current job
    115        )  # Then dep job for 'shippable'
    116        signing_type = get_signing_type_per_platform(
    117            build_platform, is_shippable, config
    118        )
    119 
    120        task = {
    121            "label": label,
    122            "description": "{} {}".format(
    123                dep_job.description, job["description-suffix"]
    124            ),
    125            "worker-type": job.get("worker-type", "linux-signing"),
    126            "worker": {
    127                "implementation": "scriptworker-signing",
    128                "signing-type": signing_type,
    129                "upstream-artifacts": upstream_artifacts,
    130            },
    131            "dependencies": dependencies,
    132            "attributes": attributes,
    133            "run-on-projects": job.get(
    134                "run-on-projects", dep_job.attributes.get("run_on_projects")
    135            ),
    136            "run-on-repo-type": job.get("run-on-repo-type", ["git", "hg"]),
    137            "treeherder": treeherder,
    138        }
    139 
    140        yield task