beetmover_integration.py (3534B)
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 beetmover 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.keyed_by import evaluate_keyed_by 11 from taskgraph.util.schema import Schema, optionally_keyed_by 12 from voluptuous import Optional, Required 13 14 from gecko_taskgraph.transforms.beetmover import craft_release_properties 15 from gecko_taskgraph.transforms.task import task_description_schema 16 from gecko_taskgraph.util.attributes import copy_attributes_from_dependent_job 17 from gecko_taskgraph.util.scriptworker import ( 18 generate_beetmover_artifact_map, 19 generate_beetmover_upstream_artifacts, 20 ) 21 22 beetmover_description_schema = Schema({ 23 Required("label"): str, 24 Required("description"): str, 25 Required("dependencies"): task_description_schema["dependencies"], 26 Required("if-dependencies"): task_description_schema["if-dependencies"], 27 Optional("treeherder"): task_description_schema["treeherder"], 28 Required("run-on-projects"): task_description_schema["run-on-projects"], 29 Optional("attributes"): task_description_schema["attributes"], 30 Optional("task-from"): task_description_schema["task-from"], 31 Required("worker-type"): task_description_schema["worker-type"], 32 Required("scopes"): optionally_keyed_by("project", [str]), 33 Optional("run-on-repo-type"): task_description_schema["run-on-repo-type"], 34 }) 35 36 transforms = TransformSequence() 37 38 39 @transforms.add 40 def remove_name(config, tasks): 41 for job in tasks: 42 if "name" in job: 43 del job["name"] 44 yield job 45 46 47 transforms.add_validate(beetmover_description_schema) 48 49 50 @transforms.add 51 def make_task_description(config, tasks): 52 for task in tasks: 53 dep_task = get_primary_dependency(config, task) 54 assert dep_task 55 56 attributes = copy_attributes_from_dependent_job(dep_task) 57 attributes.update(task.get("attributes", {})) 58 59 treeherder = task.get("treeherder", {}) 60 dep_th_platform = ( 61 dep_task.task.get("extra", {}) 62 .get("treeherder", {}) 63 .get("machine", {}) 64 .get("platform", "") 65 ) 66 treeherder.setdefault("platform", f"{dep_th_platform}/opt") 67 68 task["description"] = task["description"].format( 69 build_platform=attributes.get("build_platform"), 70 build_type=attributes.get("build_type"), 71 ) 72 73 task["scopes"] = evaluate_keyed_by( 74 task["scopes"], 75 "beetmover-integration", 76 {"project": config.params.get("project")}, 77 ) 78 79 if task.get("locale"): 80 attributes["locale"] = task["locale"] 81 task["attributes"] = attributes 82 83 yield task 84 85 86 @transforms.add 87 def make_task_worker(config, jobs): 88 for job in jobs: 89 locale = job["attributes"].get("locale") 90 platform = job["attributes"]["build_platform"] 91 job["worker"] = { 92 "release-properties": craft_release_properties(config, job), 93 "upstream-artifacts": generate_beetmover_upstream_artifacts( 94 config, job, platform, locale 95 ), 96 "artifact-map": generate_beetmover_artifact_map( 97 config, job, platform=platform, locale=locale 98 ), 99 } 100 yield job