| 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): |
| # The code for the change will be checked out into a special folder that is |
| # cached between builds. |
| checkout_root = api.path['cache'].join('builder') |
| # This is the name of the subfolder under checkout_root where the change will |
| # be checked out at. |
| checkout_dir = 'src' |
| |
| _downloadGerritChange(api, checkout_root, checkout_dir) |
| env = _downloadChromeAndAddToPath(api) |
| |
| # Now run our verification in the checked out code directory. |
| with api.context(env=env, cwd=checkout_root.join(checkout_dir)): |
| # Current LTS for Node.js. Version must be in CIPD packages: |
| # https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/nodejs/linux-amd64/+/bfm5RWHxZDS1NBdMuNLvXZUq4ULnf_Ho5OzhI3jL_14C |
| with api.nodejs(version='18.11.0'): |
| # Named steps to test the change. |
| api.step('install yarn', ['npm', 'install', '-g', 'yarn']) |
| api.step('install deps', ['yarn', 'setup']) |
| api.step('run tests', ['yarn', 'test']) |
| |
| # Create `checkout_dir` inside the existing `checkout_root` and checks out the |
| # change there. |
| def _downloadGerritChange(api, checkout_root, checkout_dir): |
| # https://chromium.googlesource.com/chromium/tools/depot_tools/+/refs/heads/main/README.gclient.md |
| gclient_config = api.gclient.make_config() |
| gclient_config.got_revision_mapping[checkout_dir] = 'got_revision' |
| solution = gclient_config.solutions.add() |
| solution.url = 'https://gerrit.googlesource.com/gerrit' |
| solution.name = checkout_dir |
| |
| with api.context(cwd=checkout_root): |
| # https://chromium.googlesource.com/chromium/tools/depot_tools/+/refs/heads/main/recipes/recipe_modules/bot_update/api.py#81 |
| api.bot_update.ensure_checkout(gclient_config=gclient_config) |
| |
| # Download and unzip Chrome from a cloud storage bucket, then add it to the PATH |
| # and rename it for compatibility with our test runner: |
| # https://github.com/GoogleChrome/chrome-launcher#launch-options |
| # Adapted from: |
| # https://chromium.googlesource.com/infra/infra/+/refs/heads/main/recipes/recipes/gerrit_plugins.py |
| def _downloadChromeAndAddToPath(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')) |
| chrome_path = chrome.join('zip', 'chrome-linux') |
| |
| # The chrome-launcher package expects a binary named "google-chrome" rather |
| # than "chrome": |
| # https://github.com/GoogleChrome/chrome-launcher/blob/c753ba083c43a90d98b682bf9ffdfe21680e6208/src/chrome-finder.ts#L133 |
| chrome_bin = chrome_path.join('chrome') |
| google_chrome_bin = chrome_path.join('google-chrome') |
| api.step('rename to google-chrome', ['mv', chrome_bin, google_chrome_bin]) |
| env = { |
| 'PATH': api.path.pathsep.join([str(chrome_path), '%(PATH)s']), |
| } |
| return env |
| |
| # 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/gerrit", |
| ), |
| ) |