| # Copyright 2019 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 checking lockfile integrity.""" |
| |
| from PB.recipes.fuchsia.lockfile import InputProperties |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/checkout", |
| "fuchsia/git", |
| "fuchsia/jiri", |
| "recipe_engine/context", |
| "recipe_engine/properties", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): |
| checkout_dir = api.checkout.with_options( |
| manifest=props.manifest, |
| remote=props.remote, |
| project=props.project, |
| ) |
| |
| project_dir = checkout_dir.join(*props.project.split("/")) |
| lockfile_script = props.lockfile_script or "update-lockfiles.sh" |
| |
| lockfile_script_path = project_dir.join(lockfile_script) |
| with api.context(cwd=project_dir): |
| api.step( |
| f"run {lockfile_script}", [lockfile_script_path, "--jiri", api.jiri.jiri] |
| ) |
| diff = api.git.diff().stdout.strip() |
| if diff: |
| raise api.step.StepFailure( |
| f"Lockfiles are not properly updated. Please run {lockfile_script} and resubmit your change. Diff:\n\n```\n{diff}\n```" |
| ) |
| |
| |
| def GenTests(api): |
| default_properties = api.properties( |
| project="integration", |
| manifest="minimal", |
| remote="https://fuchsia.googlesource.com", |
| lockfile_script="update-lockfiles.sh", |
| ) |
| |
| yield ( |
| api.buildbucket_util.test("diff", status="FAILURE", tryjob=True) |
| + default_properties |
| ) |
| |
| yield ( |
| api.buildbucket_util.test("no_diff", tryjob=True) |
| + default_properties |
| + api.step_data( |
| "git diff", |
| api.raw_io.stream_output_text(""), |
| ) |
| ) |