From 1a0daf728cae33e170699a0e372c808736d08862 Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Wed, 29 Jan 2020 22:36:25 +0000 Subject: [PATCH] Let the presubmit recipe module skip owners checks when necessary The circumstances under which this might happen are left up to the invoking recipe, which in most cases is the chromium presubmit.py. Bug: 1034114 Change-Id: Ia8db6ab0da04750d6753e6281ef859e19aea4039 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2018224 Commit-Queue: Aaron Gable Reviewed-by: Anthony Polito --- recipes/README.recipes.md | 5 +++-- recipes/recipe_modules/presubmit/api.py | 8 ++++++- .../recipe_modules/presubmit/tests/execute.py | 22 ++++++++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 0e9f747da..f3b974644 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -763,12 +763,13 @@ Raises: Return a presubmit step. -— **def [execute](/recipes/recipe_modules/presubmit/api.py#77)(self, bot_update_step):** +— **def [execute](/recipes/recipe_modules/presubmit/api.py#77)(self, bot_update_step, skip_owners):** Runs presubmit and sets summary markdown if applicable. Args: bot_update_step: the StepResult from a previously executed bot_update step. + skip_owners: a boolean indicating whether Owners checks should be skipped. Returns: a RawResult object, suitable for being returned from RunSteps. @@ -1050,7 +1051,7 @@ Move things around in a loop! [DEPS](/recipes/recipe_modules/presubmit/tests/execute.py#10): [gclient](#recipe_modules-gclient), [presubmit](#recipe_modules-presubmit), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/cq][recipe_engine/recipe_modules/cq], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime] -— **def [RunSteps](/recipes/recipe_modules/presubmit/tests/execute.py#29)(api, patch_project, patch_repository_url):** +— **def [RunSteps](/recipes/recipe_modules/presubmit/tests/execute.py#23)(api):** ### *recipes* / [presubmit:tests/prepare](/recipes/recipe_modules/presubmit/tests/prepare.py) [DEPS](/recipes/recipe_modules/presubmit/tests/prepare.py#9): [gclient](#recipe_modules-gclient), [presubmit](#recipe_modules-presubmit), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime] diff --git a/recipes/recipe_modules/presubmit/api.py b/recipes/recipe_modules/presubmit/api.py index 2a0b7dea6..ec7b16c3c 100644 --- a/recipes/recipe_modules/presubmit/api.py +++ b/recipes/recipe_modules/presubmit/api.py @@ -74,11 +74,12 @@ class PresubmitApi(recipe_api.RecipeApi): return bot_update_step - def execute(self, bot_update_step): + def execute(self, bot_update_step, skip_owners=False): """Runs presubmit and sets summary markdown if applicable. Args: bot_update_step: the StepResult from a previously executed bot_update step. + skip_owners: a boolean indicating whether Owners checks should be skipped. Returns: a RawResult object, suitable for being returned from RunSteps. """ @@ -109,6 +110,11 @@ class PresubmitApi(recipe_api.RecipeApi): '--upstream', upstream, # '' if not in bot_update mode. ]) + if skip_owners: + presubmit_args.extend([ + '--skip_canned', 'CheckOwners' + ]) + raw_result = result_pb2.RawResult() step_json = self( *presubmit_args, diff --git a/recipes/recipe_modules/presubmit/tests/execute.py b/recipes/recipe_modules/presubmit/tests/execute.py index 3d0cbb4f9..6508c65ef 100644 --- a/recipes/recipe_modules/presubmit/tests/execute.py +++ b/recipes/recipe_modules/presubmit/tests/execute.py @@ -20,17 +20,12 @@ DEPS = [ ] -PROPERTIES = { - 'patch_project': recipe_api.Property(None), - 'patch_repository_url': recipe_api.Property(None), -} - - -def RunSteps(api, patch_project, patch_repository_url): +def RunSteps(api): api.gclient.set_config('infra') with api.context(cwd=api.path['cache'].join('builder')): bot_update_step = api.presubmit.prepare() - return api.presubmit.execute(bot_update_step) + skip_owners = api.properties.get('skip_owners', False) + return api.presubmit.execute(bot_update_step, skip_owners) def GenTests(api): @@ -56,6 +51,17 @@ def GenTests(api): api.post_process(post_process.DropExpectation) ) + yield ( + api.test('skip_owners') + + api.runtime(is_experimental=False, is_luci=True) + + api.buildbucket.try_build(project='infra') + + api.properties(skip_owners=True) + + api.post_process(post_process.StatusSuccess) + + api.post_process( + post_process.StepCommandContains, 'presubmit', ['--skip_canned', 'CheckOwners']) + + api.post_process(post_process.DropExpectation) + ) + yield ( api.test('timeout') + api.runtime(is_experimental=False, is_luci=True) +