| # Copyright 2022 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 simulating the impact of changes on builder configuration files.""" |
| |
| from PB.recipes.fuchsia.builder_oracle import InputProperties |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/builder_oracle", |
| "fuchsia/gerrit", |
| "fuchsia/git", |
| "fuchsia/git_checkout", |
| "recipe_engine/buildbucket", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): |
| checkout_dir, _ = api.git_checkout(props.remote) |
| proposed_dir = api.path.mkdtemp("proposed") |
| baseline_dir = api.path.mkdtemp("baseline") |
| |
| with api.step.nest("set up config directories"): |
| # Fetch proposed configs. |
| for configdir, path in props.luci_config_directories.items(): |
| api.file.copytree( |
| name="store proposed config directory %s" % configdir, |
| source=checkout_dir.join(path), |
| dest=proposed_dir.join(configdir), |
| ) |
| |
| # Update git checkout to previous revision. |
| with api.context(cwd=checkout_dir): |
| api.git.raw_checkout(ref="HEAD~1") |
| |
| # Fetch baseline configs. |
| for configdir, path in props.luci_config_directories.items(): |
| api.file.copytree( |
| name="store baseline config directory %s" % configdir, |
| source=checkout_dir.join(path), |
| dest=baseline_dir.join(configdir), |
| ) |
| |
| # Run the simulate command. |
| cfg_pairs = [ |
| (baseline_dir.join(configdir), proposed_dir.join(configdir)) |
| for configdir in props.luci_config_directories |
| ] |
| json_output = api.builder_oracle.simulate(config_pairs=cfg_pairs) |
| |
| # Comment on the CL. |
| if json_output and json_output["cl_comment"] != "": |
| with api.step.nest("comment on CL with recommendation"): |
| bb_input = api.buildbucket.build.input |
| gerrit_change = bb_input.gerrit_changes[0] |
| api.gerrit.set_review( |
| "add builder oracle comment to CL", |
| str(gerrit_change.change), |
| message=json_output["cl_comment"], |
| notify="OWNER", |
| host=gerrit_change.host, |
| ) |
| |
| |
| def GenTests(api): |
| luci_config_directories = { |
| "a": "a/b/c", |
| "b": "b/c/d", |
| } |
| |
| def properties(): |
| return api.properties( |
| remote="https://fuchsia.googlesource.com/integration", |
| luci_config_directories=luci_config_directories, |
| ) |
| |
| yield (api.buildbucket_util.test("basic", tryjob=True) + properties()) |