blob: cc17a0f1a1aedf94178e5f007df7d03f1c8fe909 [file] [log] [blame]
PYTHON_VERSION_COMPATIBILITY = "PY3"
# Reference: https://chromium.googlesource.com/infra/luci/recipes-py/+/HEAD/doc/
# All the deps get combined into an `api` variable passed in to RunSteps and
# GenTests. Versions and urls are specified in `recipes.cfg`.
DEPS = [
'depot_tools/bot_update',
'depot_tools/gclient',
'depot_tools/gsutil',
'recipe_engine/buildbucket',
'recipe_engine/context',
'recipe_engine/file',
'recipe_engine/nodejs',
'recipe_engine/path',
'recipe_engine/step',
'recipe_engine/platform',
'zip',
]
# Check out the change and run the tests to verify the change as part of Change
# Verification (ie. CQ label).
def RunSteps(api):
cl = api.buildbucket.build.input.gerrit_changes[0]
# Remove "-review" part of host URL
host = cl.host
gs_suffix = '-review.googlesource.com'
if host.endswith(gs_suffix):
host = '%s.googlesource.com' % host[:-len(gs_suffix)]
gclient_config = api.gclient.make_config()
s = gclient_config.solutions.add()
s.url = 'https://%s/%s' % (host, cl.project)
# This is the name of the subfolder under api.path['cache'].join('builder')
# where the repo will be checked out at.
s.name = 'src'
gclient_config.got_revision_mapping[s.name] = 'got_revision'
# Check out the code for the change, this is by default cached between builds
# for the same builder.
with api.context(cwd=api.path['cache'].join('builder')):
update_result = api.bot_update.ensure_checkout(
gclient_config=gclient_config)
api.step.raise_on_failure(update_result)
# Download Chrome and add to the PATH so that the test runner can launch it
# See https://github.com/GoogleChrome/chrome-launcher#launch-options
chrome_path = _getChrome(api)
env = {
'PATH': api.path.pathsep.join([str(chrome_path), '%(PATH)s']),
}
# Now in the checked out code directory run our verification.
with api.context(env=env, cwd=api.path['cache'].join('builder').join(s.name)):
# Current LTS for Node.js
with api.nodejs(version='18.11.0'):
# Named steps to test the change
api.step('install deps', ['npm', 'install'])
api.step('run tests', ['npm', 'run', 'test'])
# Test the recipe and generate the expect json file.
def GenTests(api):
yield api.test(
'basic',
# Execute RunSteps with test data
api.buildbucket.try_build(
project="gerrit",
git_repo="https://gerrit.googlesource.com/luci-test",
),
)
# Download and unzip Chrome from a cloud storage bucket.
# Copied from https://chromium.googlesource.com/infra/infra/+/refs/heads/main/recipes/recipes/gerrit_plugins.py
def _getChrome(api):
with api.step.nest('get chrome'):
chrome = api.path.mkdtemp(prefix='chrome')
gs_bucket = 'chromium-browser-snapshots'
gs_path = 'Linux_x64'
version_file = 'LAST_CHANGE'
chrome_zip = 'chrome-linux.zip'
api.gsutil.download(gs_bucket, '%s/%s' % (gs_path, version_file), chrome)
version = api.file.read_text('read latest chrome version',
chrome.join(version_file))
api.gsutil.download(gs_bucket, '%s/%s/%s' % (gs_path, version, chrome_zip),
chrome)
api.zip.unzip('unzip chrome', chrome.join(chrome_zip), chrome.join('zip'))
return chrome.join('zip', 'chrome-linux')