| # 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 recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| 'fuchsia/checkout', |
| 'fuchsia/git', |
| 'fuchsia/jiri', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/cipd', |
| 'recipe_engine/context', |
| 'recipe_engine/file', |
| 'recipe_engine/json', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| 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'), |
| 'lockfile_script': |
| Property( |
| kind=str, |
| help='Script file that updates the lockfiles', |
| default='update-lockfiles.sh'), |
| } |
| |
| |
| def RunSteps(api, project, manifest, remote, lockfile_script): |
| build_input = api.buildbucket.build.input |
| with api.context(infra_steps=True): |
| api.checkout.with_options( |
| path=api.path['start_dir'], |
| manifest=manifest, |
| remote=remote, |
| project=project, |
| build_input=build_input, |
| ) |
| |
| project_dir = api.path['start_dir'].join(*project.split('/')) |
| lockfile_script_path = project_dir.join(lockfile_script) |
| with api.context(cwd=project_dir): |
| diff_before_script = api.git.diff() |
| api.step('run %s' % lockfile_script, |
| [lockfile_script_path, '--jiri', api.jiri.jiri]) |
| diff_after_script = api.git.diff() |
| if diff_before_script != diff_after_script: # pragma: no cover |
| raise api.step.StepFailure( |
| 'lockfiles are not properly updated, please run {} and resubmit your change\nBefore:{}\nAfter:{}' |
| .format(lockfile_script, diff_before_script, diff_after_script)) |
| |
| |
| def GenTests(api): |
| default_properties = api.properties( |
| project='integration', |
| manifest='minimal', |
| remote='https://fuchsia.googlesource.com', |
| lockfile_script='update-lockfiles.sh') |
| |
| yield api.test('default') + default_properties + api.buildbucket.try_build( |
| git_repo='https://fuchsia.googlesource.com/integration') |