|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +""" |
| 5 | +Transform release-beetmover-source-checksums into an actual task description. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import absolute_import, print_function, unicode_literals |
| 9 | + |
| 10 | +from taskgraph.transforms.base import TransformSequence |
| 11 | +from taskgraph.transforms.beetmover import craft_release_properties |
| 12 | +from taskgraph.util.attributes import copy_attributes_from_dependent_job |
| 13 | +from taskgraph.util.schema import validate_schema, Schema |
| 14 | +from taskgraph.transforms.task import task_description_schema |
| 15 | +from voluptuous import Any, Required, Optional |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +task_description_schema = {str(k): v for k, v in task_description_schema.schema.iteritems()} |
| 20 | + |
| 21 | +transforms = TransformSequence() |
| 22 | + |
| 23 | +taskref_or_string = Any( |
| 24 | + basestring, |
| 25 | + {Required('task-reference'): basestring}) |
| 26 | + |
| 27 | +beetmover_checksums_description_schema = Schema({ |
| 28 | + Required('dependent-task'): object, |
| 29 | + Required('depname', default='build'): basestring, |
| 30 | + Optional('label'): basestring, |
| 31 | + Optional('extra'): object, |
| 32 | + Optional('shipping-phase'): task_description_schema['shipping-phase'], |
| 33 | + Optional('shipping-product'): task_description_schema['shipping-product'], |
| 34 | +}) |
| 35 | + |
| 36 | + |
| 37 | +@transforms.add |
| 38 | +def validate(config, jobs): |
| 39 | + for job in jobs: |
| 40 | + label = job.get('dependent-task', object).__dict__.get('label', '?no-label?') |
| 41 | + validate_schema( |
| 42 | + beetmover_checksums_description_schema, job, |
| 43 | + "In checksums-signing ({!r} kind) task for {!r}:".format(config.kind, label)) |
| 44 | + yield job |
| 45 | + |
| 46 | + |
| 47 | +@transforms.add |
| 48 | +def make_beetmover_checksums_description(config, jobs): |
| 49 | + for job in jobs: |
| 50 | + dep_job = job['dependent-task'] |
| 51 | + attributes = dep_job.attributes |
| 52 | + build_platform = attributes.get("build_platform") |
| 53 | + if not build_platform: |
| 54 | + raise Exception("Cannot find build platform!") |
| 55 | + repack_id = dep_job.task.get('extra', {}).get('repack_id') |
| 56 | + if not repack_id: |
| 57 | + raise Exception("Cannot find repack id!") |
| 58 | + |
| 59 | + label = dep_job.label.replace("beetmover-", "beetmover-checksums-") |
| 60 | + description = ( |
| 61 | + "Beetmove checksums for repack_id '{repack_id}' for build '" |
| 62 | + "{build_platform}/{build_type}'".format( |
| 63 | + repack_id=repack_id, |
| 64 | + build_platform=build_platform, |
| 65 | + build_type=attributes.get('build_type') |
| 66 | + ) |
| 67 | + ) |
| 68 | + |
| 69 | + extra = {} |
| 70 | + extra['partner_path'] = dep_job.task['payload']['upstreamArtifacts'][0]['locale'] |
| 71 | + extra['repack_id'] = repack_id |
| 72 | + |
| 73 | + dependent_kind = str(dep_job.kind) |
| 74 | + dependencies = {dependent_kind: dep_job.label} |
| 75 | + for k, v in dep_job.dependencies.items(): |
| 76 | + if k.startswith('beetmover'): |
| 77 | + dependencies[k] = v |
| 78 | + |
| 79 | + attributes = copy_attributes_from_dependent_job(dep_job) |
| 80 | + |
| 81 | + task = { |
| 82 | + 'label': label, |
| 83 | + 'description': description, |
| 84 | + 'worker-type': '{}/{}'.format( |
| 85 | + dep_job.task['provisionerId'], |
| 86 | + dep_job.task['workerType'], |
| 87 | + ), |
| 88 | + 'scopes': dep_job.task['scopes'], |
| 89 | + 'dependencies': dependencies, |
| 90 | + 'attributes': attributes, |
| 91 | + 'run-on-projects': dep_job.attributes.get('run_on_projects'), |
| 92 | + 'extra': extra, |
| 93 | + } |
| 94 | + |
| 95 | + if 'shipping-phase' in job: |
| 96 | + task['shipping-phase'] = job['shipping-phase'] |
| 97 | + |
| 98 | + if 'shipping-product' in job: |
| 99 | + task['shipping-product'] = job['shipping-product'] |
| 100 | + |
| 101 | + yield task |
| 102 | + |
| 103 | + |
| 104 | +def generate_upstream_artifacts(refs, partner_path): |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + common_paths = [ |
| 110 | + "public/target.checksums", |
| 111 | + ] |
| 112 | + |
| 113 | + upstream_artifacts = [{ |
| 114 | + "taskId": {"task-reference": refs["beetmover"]}, |
| 115 | + "taskType": "signing", |
| 116 | + "paths": common_paths, |
| 117 | + "locale": "beetmover-checksums/{}".format(partner_path), |
| 118 | + }] |
| 119 | + |
| 120 | + return upstream_artifacts |
| 121 | + |
| 122 | + |
| 123 | +@transforms.add |
| 124 | +def make_beetmover_checksums_worker(config, jobs): |
| 125 | + for job in jobs: |
| 126 | + valid_beetmover_job = (len(job["dependencies"]) == 1) |
| 127 | + if not valid_beetmover_job: |
| 128 | + raise NotImplementedError("Beetmover checksums must have one dependency.") |
| 129 | + |
| 130 | + refs = { |
| 131 | + "beetmover": None, |
| 132 | + } |
| 133 | + for dependency in job["dependencies"].keys(): |
| 134 | + if dependency.endswith("beetmover"): |
| 135 | + refs['beetmover'] = "<{}>".format(dependency) |
| 136 | + if None in refs.values(): |
| 137 | + raise NotImplementedError( |
| 138 | + "Beetmover checksums must have a beetmover dependency!") |
| 139 | + |
| 140 | + worker = { |
| 141 | + 'implementation': 'beetmover', |
| 142 | + 'release-properties': craft_release_properties(config, job), |
| 143 | + 'upstream-artifacts': generate_upstream_artifacts( |
| 144 | + refs, job['extra']['partner_path'], |
| 145 | + ), |
| 146 | + 'partner-public': True, |
| 147 | + } |
| 148 | + |
| 149 | + job["worker"] = worker |
| 150 | + |
| 151 | + yield job |
0 commit comments