bazel_roller: Move bazel-specific parts to func
Bug: b/341756093
Change-Id: I49090cbbff0ae823cd86eed4a3b94ec717db1b83
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/230292
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
Reviewed-by: Danielle Kay <danikay@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/recipes/bazel_roller.py b/recipes/bazel_roller.py
index 96d05c1..c4d6ed8 100644
--- a/recipes/bazel_roller.py
+++ b/recipes/bazel_roller.py
@@ -48,6 +48,7 @@
if TYPE_CHECKING: # pragma: no cover
from typing import Generator, Sequence, TypeVar
from recipe_engine import recipe_api, recipe_test_api
+ from RECIPE_MODULES.pigweed.checkout import api as checkout_api
DEPS = [
'fuchsia/auto_roller',
@@ -122,21 +123,15 @@
)
-def RunSteps( # pylint: disable=invalid-name
+def _update_git_repository(
api: recipe_api.RecipeScriptApi,
- props: InputProperties,
-):
- project_branch: str = props.project_branch or 'main'
-
- # The checkout module will try to use trigger data to pull in a specific
- # patch. Since the triggering commit is in a different repository that
- # needs to be disabled.
- props.checkout_options.use_trigger = False
- checkout: api.checkout.CheckoutContext = api.checkout(
- props.checkout_options
- )
-
- workspace_path = _workspace_path(api, checkout.root, props.workspace_path)
+ checkout: checkout_api.CheckoutContext,
+ workspace: str | None,
+ project_name: str | None,
+ project_remote: str,
+ project_branch: str,
+) -> dict[str, api.roll_util.Roll]:
+ workspace_path = _workspace_path(api, checkout.root, workspace)
new_revision: Optional[str] = None
@@ -157,29 +152,26 @@
new_revision = project_branch
# If this was triggered by a gitiles poller, check that the triggering
- # repository matches props.project_remote. Exception: allow a trigger to
- # be for the top-level project instead.
+ # repository matches project_remote. Exception: allow a trigger to be for
+ # the top-level project instead.
use_trigger_for_project = True
if bb_remote:
- if checkout.remotes_equivalent(
- props.checkout_options.remote,
- bb_remote,
- ):
+ if checkout.remotes_equivalent(checkout.options.remote, bb_remote):
use_trigger_for_project = False
- elif not checkout.remotes_equivalent(props.project_remote, bb_remote):
+ elif not checkout.remotes_equivalent(project_remote, bb_remote):
api.step.empty(
'triggering repository ({}) does not match project remote '
- '({})'.format(bb_remote, props.project_remote),
+ '({})'.format(bb_remote, project_remote),
status='FAILURE',
)
- project_dir: config_types.Path = api.path.start_dir / 'project'
+ project_dir = api.path.start_dir / 'project'
- project_checkout: api.checkout.CheckoutContext = api.checkout(
+ project_checkout = api.checkout(
CheckoutOptions(
- remote=props.project_remote,
+ remote=project_remote,
branch=project_branch,
use_trigger=use_trigger_for_project,
),
@@ -197,7 +189,7 @@
update_result = api.bazel.update_commit_hash(
checkout=checkout,
- project_remote=props.project_remote,
+ project_remote=project_remote,
new_revision=new_revision,
path=full_workspace_path,
)
@@ -212,11 +204,11 @@
# immediately.
if not api.roll_util.can_roll(direction):
api.roll_util.skip_roll_step(
- props.project_remote, update_result.old_revision, new_revision
+ project_remote, update_result.old_revision, new_revision
)
return
- project_name = props.project_name or update_result.project_name
+ project_name = project_name or update_result.project_name
if not project_name:
api.step.empty(
f'could not find name line in {full_workspace_path}',
@@ -233,6 +225,32 @@
),
}
+ return rolls
+
+
+def RunSteps( # pylint: disable=invalid-name
+ api: recipe_api.RecipeScriptApi,
+ props: InputProperties,
+):
+ # The checkout module will try to use trigger data to pull in a specific
+ # patch. Since the triggering commit is in a different repository that
+ # needs to be disabled.
+ props.checkout_options.use_trigger = False
+ checkout: api.checkout.CheckoutContext = api.checkout(
+ props.checkout_options
+ )
+
+ rolls = _update_git_repository(
+ api,
+ checkout=checkout,
+ workspace=props.workspace_path,
+ project_name=props.project_name,
+ project_remote=props.project_remote,
+ project_branch=props.project_branch or 'main',
+ )
+ if not rolls:
+ return
+
authors: Sequence[api.roll_util.Account] = api.roll_util.authors(
*rolls.values()
)