blob: 94e80632d4b3c5b2ffc8dde983fdd00ea5baee15 [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.
"""Recipe for computing test owners, for use by Flake Fetcher
Reads a test manifest from GCS that's expected to be a list of JSON objects,
each of which contains a test name and the test's GN label.
Then the recipe uses a Fuchsia checkout to compute test owners and Monorail
components based on the nearest OWNERS file to the GN label. Finally, the
recipe uploads the owners data to another JSON file in GCS that Flake Fetcher
uses to assign bugs for flaky tests to the tests' owners and put the bugs in
the appropriate components.
"""
import re
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/checkout",
"fuchsia/gsutil",
"fuchsia/status_check",
"recipe_engine/context",
"recipe_engine/path",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = {
"manifest": Property(kind=str, help="Jiri manifest to use"),
"remote": Property(kind=str, help="Remote manifest repository"),
"test_manifest_gcs_bucket": Property(
kind=str, help="GCS bucket to pull test manifest from"
),
"test_manifest_gcs_path": Property(
kind=str,
help="Path to within `test_manifest_gcs_bucket` to file mapping test names to GN labels",
),
"owners_gcs_bucket": Property(kind=str, help="GCS bucket to upload test owners to"),
"owners_gcs_path": Property(
kind=str,
help="Path within `owners_gcs_bucket` to upload the test owners manifest to",
),
}
# OWNERS file lines that match this regex (a very crude email matcher) will be
# considered to represent owners.
OWNER_REGEX = re.compile(r"^\S+@\S+$")
# OWNERS file lines that match this regex indicate Monorail bug components.
BUG_COMPONENT_REGEX = re.compile(r"^# COMPONENT: (\S+)$")
def RunSteps(
api,
manifest,
remote,
test_manifest_gcs_bucket,
test_manifest_gcs_path,
owners_gcs_bucket,
owners_gcs_path,
):
checkout_dir = api.path["start_dir"].join("checkout")
api.checkout.with_options(
path=checkout_dir,
manifest=manifest,
remote=remote,
# No need to fetch CIPD packages, we only need to look at OWNERS
# files and those are always checked into git.
fetch_packages=False,
run_hooks=False,
)
workdir = api.path.mkdtemp("workdir")
test_manifest_path = workdir.join("test_manifest.json")
api.gsutil.download(
name="download test manifest",
src_bucket=test_manifest_gcs_bucket,
src=test_manifest_gcs_path,
dest=test_manifest_path,
)
owners_path = workdir.join("test_owners.json")
with api.context(cwd=checkout_dir):
api.step(
"find owners",
[api.resource("find_owners.py"), test_manifest_path, owners_path],
)
api.gsutil.upload(
name="upload test owners",
src=owners_path,
bucket=owners_gcs_bucket,
dst=owners_gcs_path,
)
def GenTests(api):
yield (
api.status_check.test("basic")
+ api.properties(
manifest="fuchsia/flower",
remote="https://fuchsia.googlesource.com/integration",
test_manifest_gcs_bucket="tests",
test_manifest_gcs_path="test_manifest.json",
owners_gcs_bucket="owners",
owners_gcs_path="test_owners.json",
)
)