From efc95d6b9a8b53b8aa1d03ced4f2943894582b66 Mon Sep 17 00:00:00 2001 From: Nodir Turakulov Date: Fri, 31 Aug 2018 21:30:57 +0000 Subject: [PATCH] [bot_update] Untie revision and repository properties repository and revision have less to do with each other than it seems: revision is for checkout and the part of code that reads revision does not read repository. repository property is used to determine what to apply the patchset to. When initializing their values from buildbucket.build.input, do it separately. Also, initialize repository from Gerrit changes, not Gitiles commit. See also https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1199854 https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/1199856 Bug: 877161, 694348 Change-Id: I4907a31ce055a3526b15f1a3c8e8f15c2c831437 Reviewed-on: https://chromium-review.googlesource.com/1200065 Reviewed-by: Andrii Shyshkalov Commit-Queue: Nodir Turakulov --- recipes/README.recipes.md | 14 ++--- recipes/recipe_modules/bot_update/api.py | 14 +++-- .../examples/buildbucket.expected/try.json | 55 +++++++++++++++++++ .../bot_update/examples/buildbucket.py | 4 ++ 4 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 recipes/recipe_modules/bot_update/examples/buildbucket.expected/try.json diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index d27b67b52..42b42de97 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -45,18 +45,18 @@ Recipe module to ensure a checkout is consistent on a bot. -#### **class [BotUpdateApi](/recipes/recipe_modules/bot_update/api.py#10)([RecipeApi][recipe_engine/wkt/RecipeApi]):** +#### **class [BotUpdateApi](/recipes/recipe_modules/bot_update/api.py#12)([RecipeApi][recipe_engine/wkt/RecipeApi]):** -— **def [\_\_call\_\_](/recipes/recipe_modules/bot_update/api.py#39)(self, name, cmd, \*\*kwargs):** +— **def [\_\_call\_\_](/recipes/recipe_modules/bot_update/api.py#43)(self, name, cmd, \*\*kwargs):** Wrapper for easy calling of bot_update. -— **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#389)(self, bot_update_step):** +— **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#393)(self, bot_update_step):** Deapplies a patch, taking care of DEPS and solution revisions properly. -— **def [ensure\_checkout](/recipes/recipe_modules/bot_update/api.py#52)(self, gclient_config=None, suffix=None, patch=True, update_presentation=True, patch_root=None, with_branch_heads=False, with_tags=False, refs=None, patch_oauth2=None, oauth2_json=None, use_site_config_creds=None, clobber=False, root_solution_revision=None, rietveld=None, issue=None, patchset=None, gerrit_no_reset=False, gerrit_no_rebase_patch_ref=False, disable_syntax_validation=False, manifest_name=None, patch_refs=None, \*\*kwargs):** +— **def [ensure\_checkout](/recipes/recipe_modules/bot_update/api.py#56)(self, gclient_config=None, suffix=None, patch=True, update_presentation=True, patch_root=None, with_branch_heads=False, with_tags=False, refs=None, patch_oauth2=None, oauth2_json=None, use_site_config_creds=None, clobber=False, root_solution_revision=None, rietveld=None, issue=None, patchset=None, gerrit_no_reset=False, gerrit_no_rebase_patch_ref=False, disable_syntax_validation=False, manifest_name=None, patch_refs=None, \*\*kwargs):** Args: gclient_config: The gclient configuration to use when running bot_update. @@ -67,7 +67,7 @@ Args: manifest_name: The name of the manifest to upload to LogDog. This must be unique for the whole build. -— **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#366)(self, project_name, gclient_config=None):** +— **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#370)(self, project_name, gclient_config=None):** Returns all property names used for storing the checked-out revision of a given project. @@ -81,9 +81,9 @@ Args: Returns (list of str): All properties that'll hold the checked-out revision of the given project. An empty list if no such properties exist. -— **def [initialize](/recipes/recipe_modules/bot_update/api.py#31)(self):** +— **def [initialize](/recipes/recipe_modules/bot_update/api.py#33)(self):** -  **@property**
— **def [last\_returned\_properties](/recipes/recipe_modules/bot_update/api.py#48)(self):** +  **@property**
— **def [last\_returned\_properties](/recipes/recipe_modules/bot_update/api.py#52)(self):** ### *recipe_modules* / [cipd](/recipes/recipe_modules/cipd) [DEPS](/recipes/recipe_modules/cipd/__init__.py#1): [infra\_paths](#recipe_modules-infra_paths), [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step] diff --git a/recipes/recipe_modules/bot_update/api.py b/recipes/recipe_modules/bot_update/api.py index d202ee568..2622ca4fa 100644 --- a/recipes/recipe_modules/bot_update/api.py +++ b/recipes/recipe_modules/bot_update/api.py @@ -4,6 +4,8 @@ """Recipe module to ensure a checkout is consistent on a bot.""" +import re + from recipe_engine import recipe_api @@ -30,11 +32,13 @@ class BotUpdateApi(recipe_api.RecipeApi): def initialize(self): build_input = self.m.buildbucket.build.input - if (self._revision is None and self._repository is None - and build_input.HasField('gitiles_commit')): - gm = build_input.gitiles_commit - self._revision = gm.id - self._repository = 'https://%s/%s' % (gm.host, gm.project) + if (self._revision is None and build_input.HasField('gitiles_commit')): + self._revision = build_input.gitiles_commit.id + + if self._repository is None and len(build_input.gerrit_changes) == 1: + cl = build_input.gerrit_changes[0] + host = re.sub(r'([^\.]+)-review(\.googlesource\.com)', r'\1\2', cl.host) + self._repository = 'https://%s/%s' % (host, cl.project) def __call__(self, name, cmd, **kwargs): """Wrapper for easy calling of bot_update.""" diff --git a/recipes/recipe_modules/bot_update/examples/buildbucket.expected/try.json b/recipes/recipe_modules/bot_update/examples/buildbucket.expected/try.json new file mode 100644 index 000000000..ee57ed343 --- /dev/null +++ b/recipes/recipe_modules/bot_update/examples/buildbucket.expected/try.json @@ -0,0 +1,55 @@ +[ + { + "cmd": [ + "python", + "-u", + "RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py", + "--spec-path", + "cache_dir = '[GIT_CACHE]'\nsolutions = [{'deps_file': '.DEPS.git', 'managed': True, 'name': 'v8', 'url': 'https://chromium.googlesource.com/v8/v8'}]", + "--patch_root", + "v8", + "--revision_mapping_file", + "{}", + "--git-cache-dir", + "[GIT_CACHE]", + "--cleanup-dir", + "[CLEANUP]/bot_update", + "--output_json", + "/path/to/tmp/json", + "--revision", + "v8@HEAD" + ], + "env_prefixes": { + "PATH": [ + "RECIPE_PACKAGE_REPO[depot_tools]" + ] + }, + "infra_step": true, + "name": "bot_update", + "~followup_annotations": [ + "@@@STEP_TEXT@Some step text@@@", + "@@@STEP_LOG_LINE@json.output@{@@@", + "@@@STEP_LOG_LINE@json.output@ \"did_run\": true, @@@", + "@@@STEP_LOG_LINE@json.output@ \"fixed_revisions\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"v8\": \"HEAD\"@@@", + "@@@STEP_LOG_LINE@json.output@ }, @@@", + "@@@STEP_LOG_LINE@json.output@ \"manifest\": {}, @@@", + "@@@STEP_LOG_LINE@json.output@ \"patch_failure\": false, @@@", + "@@@STEP_LOG_LINE@json.output@ \"patch_root\": \"v8\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"properties\": {}, @@@", + "@@@STEP_LOG_LINE@json.output@ \"root\": \"v8\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"source_manifest\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"directories\": {}, @@@", + "@@@STEP_LOG_LINE@json.output@ \"version\": 0@@@", + "@@@STEP_LOG_LINE@json.output@ }, @@@", + "@@@STEP_LOG_LINE@json.output@ \"step_text\": \"Some step text\"@@@", + "@@@STEP_LOG_LINE@json.output@}@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "name": "$result", + "recipe_result": null, + "status_code": 0 + } +] \ No newline at end of file diff --git a/recipes/recipe_modules/bot_update/examples/buildbucket.py b/recipes/recipe_modules/bot_update/examples/buildbucket.py index 0c3184ea8..073391f63 100644 --- a/recipes/recipe_modules/bot_update/examples/buildbucket.py +++ b/recipes/recipe_modules/bot_update/examples/buildbucket.py @@ -22,3 +22,7 @@ def GenTests(api): 'v8', 'ci', 'builder', git_repo='https://chromium.googlesource.com/v8/v8', revision='2d72510e447ab60a9728aeea2362d8be2cbd7789') + + yield api.test('try') + api.buildbucket.try_build( + 'v8', 'try', 'builder', + gerrit_host='chromium-review.googlesource.com')