| # Copyright 2021 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| """Recipe for testing Pigweed with multiple swarming tasks.""" |
| |
| from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2 |
| from PB.recipes.pigweed.pigweed import Pigweed |
| |
| DEPS = [ |
| 'fuchsia/buildbucket_util', |
| 'fuchsia/subbuild', |
| 'pigweed/build', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| PROPERTIES = Pigweed |
| |
| |
| def RunSteps(api, props): |
| with api.step.nest('build') as pres: |
| child_build = run_build_steps(api, pres) |
| build_digest = api.subbuild.get_property( |
| child_build, api.build.CAS_DIGEST_PROPERTY_NAME, |
| ) |
| |
| if props.run_tests: |
| with api.step.nest('test') as pres: |
| run_test_steps(api, pres) |
| |
| |
| def run_build_steps(api, presentation): |
| builder_name = f'{api.buildbucket.build.builder.builder}-subbuild' |
| |
| extra_props = {'parent_id': api.buildbucket_util.id} |
| |
| builds = api.subbuild.launch( |
| [builder_name], presentation, extra_properties=extra_props, |
| ) |
| |
| build_id = builds[builder_name].build_id |
| build_url = builds[builder_name].url |
| builds = api.subbuild.collect([build_id]) |
| output_build = builds[build_id].build_proto |
| |
| if output_build.status != common_pb2.SUCCESS: |
| presentation.properties['failed_to_build'] = True |
| if output_build.status == common_pb2.INFRA_FAILURE: |
| exception_type = api.step.InfraFailure |
| description = 'raised infra failure' |
| else: |
| exception_type = api.step.StepFailure |
| description = 'failed' |
| |
| # Copy the child summary markdown into the parent summary markdown to |
| # better propagate error messages. If the child summary is multiple |
| # lines, start it on a new line. |
| subbuild_summary = output_build.summary_markdown.strip() |
| summary = f'[build]({build_url}) {description}' |
| if subbuild_summary: |
| summary += ':' |
| # If the subbuild summary is already multiple lines, start it on a |
| # new line. If it's one line, the final summary should also be one |
| # line. |
| summary += '\n\n' if '\n' in subbuild_summary else ' ' |
| summary += subbuild_summary |
| raise exception_type(summary) |
| |
| return output_build |
| |
| |
| def run_test_steps(api, presentation): |
| pass |
| |
| |
| def GenTests(api): |
| for status in ('SUCCESS', 'FAILURE', 'INFRA_FAILURE'): |
| build = api.subbuild.ci_build_message( |
| builder='-subbuild', |
| input_props={"parent_id": "123123"}, |
| output_props={'cas_build_digest': '123123/12'}, |
| status=status.upper(), |
| ) |
| build.summary_markdown = status |
| |
| yield ( |
| api.test(status.lower(), status=status) |
| + api.properties(run_tests=True) |
| + api.subbuild.child_build_steps(builds=[build]) |
| ) |