blob: 081d903872f680a270930fe5a476ca6e6f237218 [file] [log] [blame]
# Copyright 2022 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.
"""Update submodules in a Git repository."""
from PB.recipes.fuchsia.submodule_roller import InputProperties
DEPS = [
"fuchsia/auto_roller",
"fuchsia/buildbucket_util",
"fuchsia/git",
"fuchsia/git_checkout",
"recipe_engine/context",
"recipe_engine/properties",
]
PROPERTIES = InputProperties
def RunSteps(api, props):
checkout_dir, _ = api.git_checkout(
props.remote,
# No need to actually check out all the submodules, we're just going to
# update their pinned versions.
submodules=False,
)
with api.context(cwd=checkout_dir):
api.git.update_submodule(
paths=props.submodule_paths,
# We don't initializing submodules during the checkout. `git
# submodule update` doesn't work on uninitialized submodules, so we
# have to initialize the submodules that we're rolling.
init=True,
remote=True,
# Don't bother fetching objects.
fetch=False,
)
if len(props.submodule_paths) == 1:
commit_message = f"[roll] Update {props.submodule_paths[0]}"
else:
commit_message = "[roll] Update submodules"
change = api.auto_roller.attempt_roll(
props.roll_options, repo_dir=checkout_dir, commit_message=commit_message
)
return api.auto_roller.raw_result(change)
def GenTests(api):
def properties(**kwargs):
props = {
"submodule_paths": ["a", "b", "c/d", "e"],
"remote": "https://fuchsia.googlesource.com/integration",
"roll_options": {
"remote": "https://fuchsia.googlesource.com/integration",
},
}
props.update(kwargs)
return api.properties(**props)
yield api.buildbucket_util.test(
"roll", builder="submodule-roller"
) + api.auto_roller.success() + properties()
yield api.buildbucket_util.test(
"one_submodule", builder="submodule-roller"
) + api.auto_roller.success() + properties(submodule_paths=["foo/bar"])