| # 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 running a specified script from a given repo.""" |
| |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| 'fuchsia/git', |
| 'fuchsia/status_check', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/context', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| PROPERTIES = { |
| 'script': Property( |
| kind=str, |
| help='Relative path to the script to run', |
| ), |
| } |
| |
| |
| def RunSteps(api, script): |
| bb_input = api.buildbucket.build.input |
| |
| with api.step.nest('checkout'), api.context(infra_steps=True): |
| if bb_input.gerrit_changes: |
| cl = bb_input.gerrit_changes[0] |
| checkout_dir = api.path['start_dir'].join(cl.project) |
| api.git.checkout_cl(cl, path=checkout_dir) |
| elif bb_input.gitiles_commit.project: |
| checkout_dir = api.path['start_dir'].join(bb_input.gitiles_commit.project) |
| api.git.checkout_commit(bb_input.gitiles_commit, path=checkout_dir) |
| else: |
| raise api.step.InfraFailure( |
| 'gitiles_commit or gerrit_changes must be populated') |
| |
| with api.context(cwd=checkout_dir): |
| api.step('run %s' % script, [script]) |
| |
| |
| def GenTests(api): |
| repo = 'https://fuchsia.googlesource.com/foo' |
| |
| # yapf: disable |
| yield ( |
| api.status_check.test('ci') |
| + api.properties(script='run-tests.sh') |
| + api.buildbucket.ci_build(git_repo=repo) |
| ) |
| |
| yield ( |
| api.status_check.test('cq') |
| + api.properties(script='run-tests.sh') |
| + api.buildbucket.try_build(git_repo=repo) |
| ) |
| |
| yield ( |
| api.status_check.test('script_failed', status='failure') |
| + api.properties(script='run-tests.sh') |
| + api.buildbucket.ci_build(git_repo=repo) |
| + api.step_data('run run-tests.sh', retcode=1) |
| ) |
| |
| yield ( |
| api.status_check.test('no_buildbucket_input', status='infra_failure') |
| + api.properties(script='run-tests.sh') |
| ) |
| # yapf: enable |