| # Copyright 2020 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| from recipe_engine.config import List |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| "fuchsia/presubmit_util", |
| "fuchsia/status_check", |
| "recipe_engine/buildbucket", |
| "recipe_engine/properties", |
| ] |
| |
| |
| PROPERTIES = { |
| "trigger_tryjobs": Property( |
| kind=bool, |
| default=False, |
| help="Whether to trigger tryjobs explicitly.", |
| ), |
| "tryjobs": Property( |
| kind=List(str), |
| default=None, |
| help="Tryjobs to trigger.", |
| ), |
| "use_gclient_override": Property( |
| kind=bool, |
| default=False, |
| help="Whether to use gclient override.", |
| ), |
| "use_package_overrides": Property( |
| kind=bool, |
| default=False, |
| help="Whether to use package overrides.", |
| ), |
| } |
| |
| |
| def RunSteps( |
| api, |
| trigger_tryjobs, |
| tryjobs, |
| use_gclient_override, |
| use_package_overrides, |
| ): |
| options = api.presubmit_util.Options( |
| gerrit_host="fuchsia-review.googlesource.com", |
| gerrit_project="infra/test", |
| ref="refs/heads/main", |
| timeout_secs=1800, |
| tryjobs=tryjobs, |
| tryjobs_gerrit_host="alternate-review.googlesource.com", |
| trigger_tryjobs=trigger_tryjobs, |
| tryjobs_wait_secs=60, |
| ) |
| api.presubmit_util.orchestrate( |
| options=options, |
| cl_subject="[infra] Very good code", |
| file_edits=[("path/to/a.txt", "foo"), ("path/to/b.txt", "bar")], |
| package_overrides={"package": "abcdef"} if use_package_overrides else None, |
| gclient_variables={"override": "foobar"} if use_gclient_override else None, |
| ) |
| |
| |
| def GenTests(api): |
| create_cl_test_data = api.presubmit_util.create_cl( |
| "create CL", |
| test_data={ |
| "number": 123456, |
| "current_revision": "foo", |
| "revisions": {"foo": {"number": 1}}, |
| }, |
| ) |
| tryjobs = ["fuchsia/try/foo.x64-debug", "fuchsia/try/foo.arm64-debug"] |
| tryjob_msgs = [ |
| api.buildbucket.try_build_message( |
| project="fuchsia", |
| bucket="try", |
| builder="bar.x64-debug", |
| ), |
| ] |
| yield ( |
| api.status_check.test("gclient_override_with_explicit_tryjobs") |
| + api.properties( |
| use_gclient_override=True, tryjobs=tryjobs, trigger_tryjobs=True |
| ) |
| + api.presubmit_util.trigger_tryjobs( |
| "trigger tryjobs", |
| tryjob_msgs=tryjob_msgs, |
| ) |
| + api.presubmit_util.collect_tryjobs( |
| "collect tryjobs", |
| tryjob_msgs=tryjob_msgs, |
| ) |
| ) |
| yield ( |
| api.status_check.test("package_overrides") |
| + create_cl_test_data |
| + api.presubmit_util.wait_for_cq() |
| + api.properties(use_package_overrides=True) |
| ) |
| yield ( |
| api.status_check.test("failed_cq", status="failure") |
| + create_cl_test_data |
| + api.presubmit_util.wait_for_cq(success=False) |
| ) |
| yield ( |
| api.status_check.test("failed_tryjobs", status="failure") |
| + create_cl_test_data |
| + api.properties(tryjobs=tryjobs) |
| + api.presubmit_util.collect_tryjobs( |
| "collect tryjobs", builders=tryjobs, status="FAILURE" |
| ) |
| ) |
| yield ( |
| api.status_check.test("missing_tryjob", status="infra_failure") |
| + create_cl_test_data |
| + api.properties(tryjobs=tryjobs) |
| ) |