full.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. # Copyright 2014 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. from recipe_engine import post_process
  5. from recipe_engine import recipe_api
  6. PYTHON_VERSION_COMPATIBILITY = 'PY3'
  7. DEPS = [
  8. 'bot_update',
  9. 'gclient',
  10. 'gerrit',
  11. 'tryserver',
  12. 'recipe_engine/buildbucket',
  13. 'recipe_engine/json',
  14. 'recipe_engine/path',
  15. 'recipe_engine/platform',
  16. 'recipe_engine/properties',
  17. 'recipe_engine/runtime',
  18. ]
  19. from recipe_engine import engine_types
  20. from RECIPE_MODULES.depot_tools import gclient
  21. from PB.go.chromium.org.luci.buildbucket.proto.build import Build
  22. # TODO: crbug.com/339472834 - Once all downstream uses of presentation and
  23. # json.output have been removed, this test can be updated to not reference them
  24. # and the decorator can be removed
  25. @recipe_api.ignore_warnings('^depot_tools/BOT_UPDATE_CUSTOM_RESULT_ATTRIBUTES$')
  26. def RunSteps(api):
  27. api.gclient.use_mirror = True
  28. commit = api.buildbucket.build.input.gitiles_commit
  29. src_cfg = api.gclient.make_config(CACHE_DIR=api.path.cache_dir / 'git')
  30. soln = src_cfg.solutions.add()
  31. soln.name = 'src'
  32. soln.url = 'https://chromium.googlesource.com/chromium/src.git'
  33. if api.properties.get('revision_fallback_chain'):
  34. soln.revision = gclient.api.RevisionFallbackChain()
  35. else:
  36. soln.revision = commit.id or commit.ref or None
  37. api.gclient.c = src_cfg
  38. api.gclient.c.revisions.update(api.properties.get('revisions', {}))
  39. if api.properties.get('deprecated_got_revision_mapping'):
  40. api.gclient.c.got_revision_mapping['src'] = 'got_cr_revision'
  41. else:
  42. api.gclient.c.got_revision_reverse_mapping['got_cr_revision'] = 'src'
  43. api.gclient.c.got_revision_reverse_mapping['got_revision'] = 'src'
  44. api.gclient.c.got_revision_reverse_mapping['got_v8_revision'] = 'src/v8'
  45. api.gclient.c.got_revision_reverse_mapping['got_angle_revision'] = (
  46. 'src/third_party/angle')
  47. api.gclient.c.repo_path_map.update({
  48. 'https://chromium.googlesource.com/angle/angle': (
  49. 'src/third_party/angle', 'HEAD'),
  50. 'https://chromium.googlesource.com/v8/v8': ('src/v8', 'HEAD'),
  51. 'https://webrtc.googlesource.com/src': ('src/third_party/webrtc', 'HEAD'),
  52. })
  53. patch = api.properties.get('patch', True)
  54. clobber = True if api.properties.get('clobber') else False
  55. with_branch_heads = api.properties.get('with_branch_heads', False)
  56. with_tags = api.properties.get('with_tags', False)
  57. refs = api.properties.get('refs', [])
  58. root_solution_revision = api.properties.get('root_solution_revision')
  59. suffix = api.properties.get('suffix')
  60. gerrit_no_reset = True if api.properties.get('gerrit_no_reset') else False
  61. gerrit_no_rebase_patch_ref = bool(
  62. api.properties.get('gerrit_no_rebase_patch_ref'))
  63. patch_refs = api.properties.get('patch_refs')
  64. add_blamelists = api.properties.get('add_blamelists', False)
  65. set_output_commit = api.properties.get('set_output_commit', True)
  66. rev_overrides = {'infra': 'HEAD'}
  67. bot_update_step = api.bot_update.ensure_checkout(
  68. patch=patch,
  69. with_branch_heads=with_branch_heads,
  70. with_tags=with_tags,
  71. refs=refs,
  72. clobber=clobber,
  73. root_solution_revision=root_solution_revision,
  74. suffix=suffix,
  75. gerrit_no_reset=gerrit_no_reset,
  76. gerrit_no_rebase_patch_ref=gerrit_no_rebase_patch_ref,
  77. patch_refs=patch_refs,
  78. add_blamelists=add_blamelists,
  79. set_output_commit=set_output_commit,
  80. recipe_revision_overrides=rev_overrides,
  81. )
  82. if patch:
  83. api.bot_update.deapply_patch(bot_update_step)
  84. if api.properties.get('resolve_chromium_fixed_version'):
  85. api.bot_update.resolve_fixed_revision(bot_update_step.json.output, 'src')
  86. def GenTests(api):
  87. def try_build(**kwargs):
  88. kwargs.setdefault(
  89. 'git_repo', 'https://chromium.googlesource.com/chromium/src')
  90. return api.buildbucket.try_build('chromium/src', 'try', 'linux', **kwargs)
  91. def ci_build(**kwargs):
  92. kwargs.setdefault(
  93. 'git_repo', 'https://chromium.googlesource.com/chromium/src')
  94. return (
  95. api.buildbucket.ci_build('chromium/src', 'ci', 'linux', **kwargs) +
  96. api.properties(patch=False)
  97. )
  98. yield (
  99. api.test('basic') +
  100. ci_build()
  101. )
  102. yield (
  103. api.test('input_commit_with_id_without_repo') +
  104. api.buildbucket.build(Build(
  105. input={
  106. 'gitiles_commit': {
  107. 'id': 'a' * 40,
  108. },
  109. },
  110. ))
  111. )
  112. yield (api.test('unrecognized_commit_repo', status="INFRA_FAILURE") +
  113. ci_build(git_repo='https://unrecognized/repo'))
  114. yield api.test(
  115. 'bot_update_failure',
  116. ci_build(),
  117. api.bot_update.fail_checkout(True),
  118. api.expect_status('INFRA_FAILURE'),
  119. )
  120. yield (
  121. api.test('resolve_chromium_fixed_version') +
  122. ci_build() +
  123. api.properties(resolve_chromium_fixed_version=True)
  124. )
  125. yield (
  126. api.test('basic_with_branch_heads') +
  127. ci_build() +
  128. api.properties(
  129. with_branch_heads=True,
  130. suffix='with branch heads'
  131. )
  132. )
  133. yield (
  134. api.test('with_tags') +
  135. api.properties(with_tags=True)
  136. )
  137. yield (
  138. api.test('with_experiments') +
  139. api.properties(bot_update_experiments=['no_sync','cool_experiment'])
  140. )
  141. yield (
  142. api.test('deprecated_got_revision_mapping') +
  143. try_build() +
  144. api.properties(
  145. deprecated_got_revision_mapping=True,
  146. set_output_commit=False,
  147. )
  148. )
  149. yield (
  150. api.test('refs') +
  151. api.properties(refs=['+refs/change/1/2/333'])
  152. )
  153. yield (api.test('tryjob_fail', status="INFRA_FAILURE") + try_build() +
  154. api.step_data('bot_update', api.json.invalid(None), retcode=1))
  155. yield api.test(
  156. 'tryjob_fail_patch',
  157. try_build(),
  158. api.bot_update.fail_patch(True),
  159. api.expect_status('FAILURE'),
  160. )
  161. yield api.test(
  162. 'tryjob_fail_patch_download',
  163. try_build(),
  164. api.bot_update.fail_patch('download'),
  165. api.expect_status('INFRA_FAILURE'),
  166. )
  167. yield (
  168. api.test('tryjob_fail_missing_bot_update_json', status="INFRA_FAILURE") +
  169. try_build() + api.override_step_data('bot_update', retcode=1) +
  170. api.post_process(post_process.ResultReasonRE, 'Infra Failure.*') +
  171. api.post_process(post_process.StatusException) +
  172. api.post_process(post_process.DropExpectation))
  173. yield (
  174. api.test('clobber') +
  175. api.properties(clobber=1)
  176. )
  177. yield (
  178. api.test('reset_root_solution_revision') +
  179. api.properties(root_solution_revision=api.bot_update.gen_revision('fake-revision'))
  180. )
  181. yield (
  182. api.test('gerrit_no_reset') +
  183. api.properties(gerrit_no_reset=1)
  184. )
  185. yield (
  186. api.test('gerrit_no_rebase_patch_ref') +
  187. api.properties(gerrit_no_rebase_patch_ref=True)
  188. )
  189. yield (
  190. api.test('tryjob_v8') +
  191. try_build(git_repo='https://chromium.googlesource.com/v8/v8') +
  192. api.properties(revisions={'src/v8': 'abc'})
  193. )
  194. yield (
  195. api.test('tryjob_v8_head_by_default') +
  196. try_build(git_repo='https://chromium.googlesource.com/v8/v8')
  197. )
  198. yield (
  199. api.test('tryjob_gerrit_angle') +
  200. try_build(git_repo='https://chromium.googlesource.com/angle/angle')
  201. )
  202. yield (
  203. api.test('tryjob_gerrit_v8_feature_branch') +
  204. try_build(git_repo='https://chromium.googlesource.com/v8/v8') +
  205. api.tryserver.gerrit_change_target_ref('refs/heads/experimental/feature')
  206. )
  207. yield (
  208. api.test('tryjob_gerrit_feature_branch') +
  209. try_build() +
  210. api.tryserver.gerrit_change_target_ref('refs/heads/experimental/feature')
  211. )
  212. yield (
  213. api.test('tryjob_gerrit_branch_heads') +
  214. try_build() +
  215. api.tryserver.gerrit_change_target_ref('refs/branch-heads/67')
  216. )
  217. yield (
  218. api.test('tryjob_gerrit_webrtc') +
  219. try_build(git_repo='https://webrtc.googlesource.com/src')
  220. )
  221. yield (
  222. api.test('multiple_patch_refs') +
  223. api.properties(
  224. patch_refs=[
  225. ('https://chromium.googlesource.com/chromium/src@'
  226. 'refs/changes/12/34/5'),
  227. 'https://chromium.googlesource.com/v8/v8@refs/changes/124/45/6',
  228. ],
  229. )
  230. )
  231. yield (
  232. api.test('origin_main') +
  233. ci_build(revision='origin/main')
  234. )
  235. yield (
  236. api.test('revision_fallback_chain_set_output_commit') + ci_build() +
  237. api.properties(
  238. set_output_commit=True,
  239. revision_fallback_chain=True,
  240. ) +
  241. # Don't set commit position properties so that the set_output_commit code
  242. # attempts to do comparisons on the revision value
  243. api.step_data(
  244. 'bot_update (without patch)',
  245. api.bot_update.output_json(patch_root='src',
  246. first_sln='src',
  247. revision_mapping={'got_revision': 'src'},
  248. commit_positions=False)))
  249. yield api.test(
  250. 'upload_traces',
  251. try_build(),
  252. api.bot_update.fail_patch(True),
  253. api.expect_status('FAILURE'),
  254. )
  255. yield api.test(
  256. 'upload_traces_fail',
  257. try_build(),
  258. api.bot_update.fail_patch(True),
  259. api.step_data(
  260. 'upload git traces.gsutil upload',
  261. retcode=1,
  262. ),
  263. api.expect_status('FAILURE'),
  264. )
  265. yield (
  266. api.test('revision_specifying_ref') +
  267. ci_build() +
  268. api.properties(
  269. revisions={'src': 'refs/branch-heads/4000'},
  270. )
  271. )
  272. yield (
  273. api.test('add_blamelists') +
  274. ci_build() +
  275. api.properties(
  276. add_blamelists=True,
  277. revisions={'src/v8': 'HEAD'},
  278. )
  279. )
  280. yield api.test(
  281. 'add_blamelists_bot_update_failure',
  282. ci_build(),
  283. api.properties(
  284. add_blamelists=True,
  285. revisions={'src/v8': 'HEAD'},
  286. ),
  287. api.bot_update.fail_checkout(True),
  288. api.expect_status('INFRA_FAILURE'),
  289. )
  290. yield api.test(
  291. 'no_cp_checkout_a_specific_commit',
  292. ci_build(revision='a' * 40),
  293. api.bot_update.commit_positions(False),
  294. )
  295. yield api.test(
  296. 'no_cp_checkout_main',
  297. ci_build(revision=''),
  298. api.bot_update.commit_positions(False),
  299. )
  300. yield api.test(
  301. 'no_cp_checkout_a_branch_head',
  302. ci_build(revision='', git_ref='refs/branch-heads/x'),
  303. api.bot_update.commit_positions(False),
  304. )
  305. yield api.test(
  306. 'no_cp_checkout_HEAD',
  307. ci_build(revision='HEAD'),
  308. api.bot_update.commit_positions(False),
  309. )