| # Copyright 2020 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Recipe for testing recipes.""" |
| |
| import collections |
| |
| import attr |
| |
| from recipe_engine.recipe_api import Property |
| |
| PYTHON_VERSION_COMPATIBILITY = 'PY3' |
| |
| DEPS = [ |
| 'fuchsia/commit_queue', |
| 'fuchsia/git', |
| 'fuchsia/recipe_testing', |
| 'fuchsia/status_check', |
| 'fuchsia/gerrit', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/context', |
| 'recipe_engine/json', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| PROPERTIES = { |
| 'remote': |
| Property( |
| kind=str, |
| help='Remote repository', |
| default='https://flutter.googlesource.com/recipes', |
| ), |
| # Default of True until recipe testing actually works on Flutter. |
| 'unittest_only': |
| Property(kind=bool, help='Finish after unit tests', default=True), |
| } |
| # If this build is being triggered from a change to this recipe, we need |
| # to explicitly pass a CL. The most recent passing run of |
| # flutter.try/recipes could have any number of different subbuilds kicked |
| # off. In that case alter the recipes build to run on a specific CL that |
| # modifies the fuchsia_ctl recipe alone, because that recipe is used by |
| # relatively few CQ builders. |
| # |
| # If the self test CL triggers multiple builds then it may be possible that |
| # led recipes will call itself reaching the max recursion limit. In the |
| # flutter recipes the fuchsia_ctl recipe is the only one without too many |
| # dependencies. |
| SELFTEST_CL = ('https://flutter-review.googlesource.com/c/recipes/+/19645') |
| COMMIT_QUEUE_CFG = """ |
| submit_options: < |
| max_burst: 4 |
| burst_delay: < |
| seconds: 480 |
| > |
| > |
| config_groups: < |
| gerrit: < |
| url: "https://flutter-review.googlesource.com" |
| projects: < |
| name: "project" |
| ref_regexp: "refs/heads/.+" |
| > |
| > |
| verifiers: < |
| gerrit_cq_ability: < |
| committer_list: "project-flutter-committers" |
| dry_run_access_list: "project-flutter-tryjob-access" |
| > |
| tryjob: < |
| builders: < |
| name: "flutter/try/flutter-baz" |
| location_regexp: ".*" |
| location_regexp_exclude: ".+/[+]/.*\\.md" |
| > |
| > |
| > |
| > |
| config_groups: < |
| gerrit: < |
| url: "https://flutter-review.googlesource.com" |
| projects: < |
| name: "flutter/flutter" |
| ref_regexp: "refs/heads/.+" |
| > |
| > |
| verifiers: < |
| gerrit_cq_ability: < |
| committer_list: "project-flutter-committers" |
| dry_run_access_list: "project-flutter-tryjob-access" |
| > |
| tryjob: < |
| builders: < |
| name: "flutter/try/flutter-bar" |
| location_regexp: ".*" |
| location_regexp_exclude: ".+/[+]/.*\\.md" |
| location_regexp_exclude: ".+/[+].*/docs/.+" |
| > |
| builders: < |
| name: "flutter/try/flutter-foo" |
| location_regexp: ".*" |
| location_regexp_exclude: ".+/[+]/.*\\.md" |
| location_regexp_exclude: ".+/[+].*/docs/.+" |
| > |
| > |
| > |
| > |
| """ |
| |
| # TODO(fxbug.dev/88439): Convert this to a proto. |
| @attr.s |
| class Project(object): |
| name = attr.ib(type=str) |
| include_restricted = attr.ib(default=False) |
| include_unrestricted = attr.ib(default=False) |
| cq_config_name = attr.ib(default='') |
| |
| |
| # TODO(fxbug.dev/88439): Convert this to a proto. |
| @attr.s |
| class RecipeTestingOptions(object): |
| projects = attr.ib() |
| use_buildbucket = attr.ib(default=False) |
| |
| |
| def GetBranch(api, change): |
| details = api.gerrit.change_details( |
| 'details', |
| change_id=str(change.change), |
| host=change.host, |
| max_attempts=5, |
| query_params=['CURRENT_COMMIT', 'CURRENT_REVISION',], |
| timeout=30, |
| test_data=api.json.test_api.output( |
| { |
| 'branch': 'main', |
| 'current_revision': 'f' * 40, |
| 'revisions': {'f' * 40: {'commit': {'parents': [{}],},},}, |
| } |
| ), |
| ).json.output |
| return details['branch'] |
| |
| |
| def RunSteps(api, remote, unittest_only): |
| checkout_path = api.path['start_dir'].join('recipes') |
| bb_input = api.buildbucket.build.input |
| branch = GetBranch(api, bb_input.gerrit_changes[0]) |
| api.git.checkout_cl( |
| bb_input.gerrit_changes[0], checkout_path, |
| onto=branch |
| ) |
| with api.context(cwd=checkout_path): |
| api.git('log', 'log', '--oneline', '-n', '10') |
| api.recipe_testing.projects = ('flutter',) |
| with api.step.defer_results(): |
| api.recipe_testing.run_lint(checkout_path) |
| api.recipe_testing.run_unit_tests(checkout_path) |
| if not unittest_only: |
| opts = RecipeTestingOptions( |
| projects=[Project(name='flutter', include_unrestricted=True)], |
| ) |
| api.recipe_testing.run_tests(checkout_path, SELFTEST_CL, opts) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.status_check.test('ci') + api.properties(unittest_only=False) + |
| api.commit_queue.test_data('flutter', COMMIT_QUEUE_CFG) + |
| api.recipe_testing.affected_recipes_data(['none']) + api.recipe_testing |
| .build_data('flutter/try/flutter-foo', 'flutter', skip=True) + |
| api.recipe_testing |
| .build_data('flutter/try/flutter-bar', 'flutter', skip=True) + |
| api.recipe_testing |
| .build_data('flutter/try/flutter-baz', 'project', skip=True) + |
| api.buildbucket.try_build( |
| git_repo='https://flutter.googlesource.com/recipes' |
| ) |
| ) |
| yield ( |
| api.status_check.test('cq_try') + api.properties(unittest_only=False) + |
| api.commit_queue.test_data('flutter', COMMIT_QUEUE_CFG) + |
| api.recipe_testing.affected_recipes_data(['none']) + api.recipe_testing |
| .build_data('flutter/try/flutter-foo', 'flutter', skip=True) + |
| api.recipe_testing |
| .build_data('flutter/try/flutter-bar', 'flutter', skip=True) + |
| api.recipe_testing |
| .build_data('flutter/try/flutter-baz', 'project', skip=True) + |
| api.buildbucket.try_build( |
| git_repo='https://flutter.googlesource.com/recipes' |
| ) |
| ) |