blob: 9746b9c20281bb834812453d5475576efab83adc [file] [log] [blame]
# Copyright 2018 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 LUCI configs."""
from recipe_engine import post_process
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/checkout",
"fuchsia/status_check",
"recipe_engine/context",
"recipe_engine/path",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = {
"config_project": Property(
kind=str, help="Jiri remote manifest project containing the luci configs"
),
"prebuilt_project": Property(
kind=str, help="Jiri remote manifest project containing the lucicfg executable",
),
"manifest": Property(kind=str, help="Jiri manifest to use"),
"remote": Property(kind=str, help="Remote manifest repository"),
"starlark_paths": Property(kind=list, help="Starlark file paths to validate"),
}
def RunSteps(api, config_project, prebuilt_project, manifest, remote, starlark_paths):
assert starlark_paths, "starlark_paths must not be empty"
checkout_root = api.path["start_dir"]
with api.context(infra_steps=True):
api.checkout.with_options(
path=checkout_root,
manifest=manifest,
remote=remote,
project=config_project,
)
prebuilt_path = api.checkout.project(prebuilt_project, checkout_root)["path"]
lucicfg_path = checkout_root.join(prebuilt_path, "tools", "lucicfg")
config_path = checkout_root.join(
api.checkout.project(config_project, checkout_root)["path"]
)
with api.step.nest("validate"), api.step.defer_results():
for relative_path in starlark_paths:
abs_path = config_path.join(relative_path)
api.step(
relative_path, [lucicfg_path, "validate", "-fail-on-warnings", abs_path]
)
def GenTests(api):
properties = api.properties(
config_project="integration",
prebuilt_project="fuchsia/prebuilt",
manifest="manifest/infra",
remote="https://fuchsia.googlesource.com/manifest",
starlark_paths=["main.star", "dev.star"],
)
yield (api.status_check.test("starlark") + properties)
# The second file should be validated even if the first one fails.
yield (
api.status_check.test("first_file_invalid", status="failure")
+ properties
+ api.step_data("validate.main.star", retcode=1)
+ api.post_process(post_process.MustRun, "validate.dev.star")
)