blob: e3ac2d5b871f680484400cc7b433c719d0061b03 [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 testing Recipes."""
from google.protobuf import text_format as textpb
from PB.go.chromium.org.luci.cq.api.config.v2 import cq as config_pb2
from recipe_engine.recipe_api import Property
from RECIPE_MODULES.fuchsia.commit_queue.test_api import DEFAULT_COMMIT_QUEUE_CFGS
DEPS = [
'fuchsia/build_input_resolver',
'fuchsia/checkout',
'fuchsia/commit_queue',
'fuchsia/gitiles',
'fuchsia/recipe_testing',
'fuchsia/status_check',
'recipe_engine/buildbucket',
'recipe_engine/context',
'recipe_engine/file',
'recipe_engine/path',
'recipe_engine/properties',
]
PROPERTIES = {
'project':
Property(kind=str, help='Jiri remote manifest project', default=None),
'manifest':
Property(kind=str, help='Jiri manifest to use'),
'remote':
Property(kind=str, help='Remote manifest repository'),
'unittest_only':
Property(kind=bool, help='Finish after unit tests', default=False),
}
# If this build is being triggered from a change to this recipe, we need
# to explicitly pass a CL. The most recent passing run of
# fuchsia.try/recipes could take anywhere from about three to 200 minutes,
# and the three minute version does not test much of what this recipe
# actually does. In that case alter the recipes build to run on a specific
# CL that modifies the cobalt recipe alone. (The cobalt build usually
# takes less than 10 minutes.)
SELFTEST_CL = 'https://fuchsia-review.googlesource.com/c/303171'
def RunSteps(api, project, manifest, remote, unittest_only):
"""Run tests for recipes."""
# Resolve the build input to always contain a Gitiles commit.
api.build_input_resolver.resolve()
with api.context(infra_steps=True):
api.checkout.with_options(
path=api.path['start_dir'],
manifest=manifest,
remote=remote,
project=project,
build_input=api.buildbucket.build.input,
)
recipes_path = api.path['start_dir'].join('infra', 'recipes')
# TODO(olivernewman): Stop whitelisting pipes after it's no longer used by
# gcc_toolchain.
api.recipe_testing.run_lint(recipes_path, whitelist=r'^pipes$')
api.recipe_testing.run_unit_tests(recipes_path)
if not unittest_only:
# TODO(olivernewman): This is an awful hack to get recipes CQ working while
# commit-queue.cfg is private. Eventually we'd like to have a guarantee
# that every public builder has a corresponding internal builder. Then we
# can make the recipes builder private so it can read the internal configs,
# and have it launch the internal versions of public builders.
# <hack>
config_text = api.file.read_text(
'read commit-queue.cfg',
api.resource('commit-queue.cfg'),
test_data=DEFAULT_COMMIT_QUEUE_CFGS['default'])
config = config_pb2.Config()
textpb.Parse(config_text, config)
api.commit_queue._cfg = config
# </hack>
api.recipe_testing.run_led_tests(recipes_path, SELFTEST_CL)
def GenTests(api): # pylint: disable=invalid-name
yield (
api.status_check.test('cq_try') +
api.build_input_resolver.set_gerrit_branch() +
api.gitiles.refs('refs', ['refs/heads/master', 'c' * 40]) +
# TODO(fxb/48998): Uncomment this line.
# api.commit_queue.test_data() +
api.recipe_testing.affected_recipes_data(['none']) +
api.recipe_testing.build_data(
'fuchsia/try/fuchsia-x64-debug', 'fuchsia', skip=True) +
api.recipe_testing.build_data(
'fuchsia/try/fuchsia-arm64-debug', 'fuchsia', skip=True) +
api.recipe_testing.build_data(
'fuchsia/try/cobalt-x64-linux', 'cobalt', skip=True) +
api.buildbucket.try_build(
git_repo='https://fuchsia.googlesource.com/infra/recipes') +
api.properties(
manifest='manifest/minimal',
remote='https://fuchsia.googlesource.com/infra/recipes',
))