blob: 94bf615929fc26c2be06c6187dd402c550693a8c [file] [log] [blame]
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Reruns tests using previously produced build artifacts.
Outline:
* Find the last green build of `source_builder`.
* Fetch that green build's output property `child_build_id`.
* Use api.buildbucket to trigger a run of `source_builder`, but with the modifications:
* Change the bucket to <my bucket>.
* Set the Gitiles input to the same as that of the last green build.
* Set `child_build_id` to the `child_build_id` from the last green build.
"""
from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
from PB.recipes.fuchsia.fuchsia.rerun import InputProperties
DEPS = [
"fuchsia/buildbucket_util",
"recipe_engine/buildbucket",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = InputProperties
def RunSteps(api, props):
num_builds = props.num_builds or 1
my_build = api.buildbucket.build
last_build_status = common_pb2.SUCCESS
# Flaky builders are rarely successful, so we take any build.
if props.source_builder.endswith("-flaky"):
last_build_status = common_pb2.ENDED_MASK
source_build = api.buildbucket_util.last_build(
my_build.builder.project,
props.source_bucket,
props.source_builder,
status=last_build_status,
)
if not source_build:
raise api.step.InfraFailure(
"Failed to find source_build for builder %s/%s/%s"
% (my_build.builder.project, props.source_bucket, props.source_builder)
)
rerun_properties = {
"child_build_id": source_build.output.properties["child_build_id"]
}
schedule_rerun_request = api.buildbucket.schedule_request(
props.target_builder,
project=my_build.builder.project,
bucket=my_build.builder.bucket,
properties=rerun_properties,
gitiles_commit=source_build.input.gitiles_commit,
)
api.buildbucket.schedule([schedule_rerun_request] * num_builds)
def GenTests(api):
properties = {
"source_bucket": "source-bucket",
"source_builder": "source-builder-flaky",
"target_builder": "source-builder-flaky-some-suffix",
}
yield (
api.buildbucket_util.test("no_search_results", status="infra_failure")
+ api.properties(**properties)
)
source_build = api.buildbucket.ci_build_message()
source_build.output.properties["child_build_id"] = 123
yield (
api.buildbucket_util.test("success", bucket="rerun")
+ api.properties(num_builds=2, **properties)
+ api.buildbucket.simulated_search_results([source_build])
)