blob: 86bb92e24000f5dd70f44839d8002124c6cf86c8 [file] [log] [blame]
# Copyright 2021 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Roll submodules of a git repository."""
from __future__ import annotations
from typing import TYPE_CHECKING
import attrs
from PB.recipes.pigweed.submodule_roller import InputProperties
from recipe_engine import post_process
if TYPE_CHECKING: # pragma: no cover
from typing import Generator
from recipe_engine import recipe_test_api
DEPS = [
'fuchsia/auto_roller',
'fuchsia/git_roll_util',
'fuchsia/gitiles',
'fuchsia/roll_commit_message',
'pigweed/checkout',
'pigweed/roll_util',
'pigweed/submodule_roll',
'recipe_engine/properties',
'recipe_engine/step',
]
PROPERTIES = InputProperties
def RunSteps( # pylint: disable=invalid-name
api: recipe_api.RecipeScriptApi,
props: InputProperties,
):
cc_authors_on_rolls = props.cc_authors_on_rolls
cc_reviewers_on_rolls = props.cc_reviewers_on_rolls
cc_domains = props.cc_domains
always_cc = props.always_cc
# 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(props.checkout_options)
rolls = []
for submodule in props.submodules:
rolls.extend(api.submodule_roll.update(checkout, submodule))
if not rolls:
with api.step.nest('nothing to roll, exiting'):
return
author_override: api.git_roll_util.Author | None = None
if props.forge_author:
author_override = api.git_roll_util.get_author_override(*rolls)
# merge auto_roller_options and override_auto_roller_options.
complete_auto_roller_options = api.roll_util.merge_auto_roller_overrides(
props.auto_roller_options, props.override_auto_roller_options
)
change = api.auto_roller.attempt_roll(
complete_auto_roller_options,
repo_dir=checkout.root,
commit_message=api.roll_commit_message.format(
*rolls,
roll_prefix='roll:',
send_comment=True,
commit_divider=props.commit_divider,
),
author_override=author_override,
)
return api.auto_roller.raw_result(change)
def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]:
"""Create tests."""
def properties(submodules, **kwargs):
props = InputProperties(**kwargs)
props.checkout_options.CopyFrom(api.checkout.git_options())
props.submodules.extend(submodules)
props.auto_roller_options.dry_run = True
props.auto_roller_options.remote = api.checkout.pigweed_repo
return api.properties(props)
yield api.test(
'success',
properties(
api.submodule_roll.submodules('a1', 'b2'),
cc_authors_on_rolls=True,
always_cc=True,
forge_author=True,
),
api.gitiles.log("a1.log a1", "A"),
api.gitiles.log("b2.log b2", "A"),
api.submodule_roll.gitmodules(a1='sso://foo/a1', b2='sso://foo/b2'),
api.auto_roller.dry_run_success(),
)
yield api.test(
'partial_noop',
properties(
api.submodule_roll.submodules('a1', 'b2'),
cc_reviewers_on_rolls=True,
),
api.gitiles.log("a1.log a1", "A"),
api.gitiles.log("b2.log b2", "A", n=0),
api.submodule_roll.gitmodules(a1='sso://foo/a1', b2='sso://foo/b2'),
api.auto_roller.dry_run_success(),
)
yield api.test(
'noop',
properties(api.submodule_roll.submodules('a1', {'path': 'b2'})),
api.submodule_roll.gitmodules(a1='a1', b2='b2', b2_branch='branch'),
api.gitiles.log("a1.log a1", "A", n=0),
api.gitiles.log("b2.log b2", "A", n=0),
)