| # Copyright 2020 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. |
| """This recipe validates LUCI configuration files. |
| |
| This recipe is designed to validate Starlark files used for LUCI configuration. |
| It performs the following steps: |
| 1. Checks out the specified source code revision using the `checkout` module. |
| 2. Runs `lucicfg validate` on the checked-out repository to ensure that all |
| Starlark configuration files are valid. |
| |
| The behavior of this recipe is controlled by the `InputProperties` proto, which |
| includes options for both the `checkout` and `validate_lucicfg` modules. This |
| allows for customization of the checkout process and the validation command. |
| """ |
| |
| from __future__ import annotations |
| |
| from collections.abc import Iterator |
| |
| from recipe_engine import post_process, recipe_test_api |
| |
| from PB.recipes.pigweed.luci_config import InputProperties |
| |
| DEPS = [ |
| 'fuchsia/validate_lucicfg', |
| 'pigweed/checkout', |
| 'recipe_engine/properties', |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): |
| """Run lucicfg validate on changed starlark files.""" |
| |
| checkout = api.checkout(props.checkout_options) |
| api.validate_lucicfg(checkout.root, props.validate_lucicfg_options) |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| def properties(): |
| props = InputProperties() |
| props.checkout_options.CopyFrom(api.checkout.git_options()) |
| props.validate_lucicfg_options.CopyFrom(api.validate_lucicfg.options()) |
| return api.properties(props) |
| |
| yield api.test( |
| 'starlark', |
| properties(), |
| api.checkout.try_test_data(), |
| api.post_process(post_process.DropExpectation), |
| ) |