blob: a0f8edc08c039b174f33328184834708cc058ba5 [file] [log] [blame]
# 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',
),
'repo':
Property(
kind=str,
help='URL of the repo containing the script',
default=None,
),
'ref':
Property(
kind=str,
help='URL of the repo containing the script',
default=None,
),
}
def RunSteps(api, script, repo, ref):
bb_input = api.buildbucket.build.input
with api.step.nest('checkout'), api.context(infra_steps=True):
if repo:
checkout_dir = api.path['start_dir'].join(repo.split('/')[-1])
api.git.checkout(repo, ref=ref)
elif 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(
"'repo' is required if build input doesn't specify commit or cl")
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('with_repo_property')
+ api.properties(script='run-tests.sh', repo=repo, ref='deadbeef')
)
yield (
api.status_check.test('failed_tests', 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_repo_specified', status='infra_failure')
+ api.properties(script='run-tests.sh')
)
# yapf: enable