blob: 29824cfa32bcf4bd21ed49293cb4a9e0130c8024 [file] [edit]
# Copyright 2024 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.
from __future__ import annotations
import dataclasses
from collections.abc import Iterator
from recipe_engine import recipe_api, recipe_test_api
from PB.recipe_modules.pigweed.submodule_roll.tests.full import InputProperties
from RECIPE_MODULES.fuchsia import (
gitiles as gitiles_module,
roll_commit_message as roll_commit_message_module,
)
from RECIPE_MODULES.pigweed import (
checkout as checkout_module,
submodule_roll as submodule_roll_module,
)
from RECIPE_MODULES.recipe_engine import (
properties as properties_module,
step as step_module,
)
@dataclasses.dataclass
class DEPS(recipe_api.RecipeScriptApi):
checkout: checkout_module.API
roll_commit_message: roll_commit_message_module.API
step: step_module.API
submodule_roll: submodule_roll_module.API
@dataclasses.dataclass
class TEST_DEPS(recipe_test_api.RecipeTestApi):
gitiles: gitiles_module.TEST_API
properties: properties_module.TEST_API
submodule_roll: submodule_roll_module.TEST_API
INLINE_PROPERTIES_PROTO = """
import "recipe_modules/pigweed/submodule_roll/submodule.proto";
message InputProperties {
// Submodules to update.
recipe_modules.pigweed.submodule_roll.SubmoduleEntry submodule = 1;
}
"""
PROPERTIES = InputProperties
def RunSteps(
api: DEPS,
props: InputProperties,
):
checkout = api.checkout.fake_context()
rolls = api.submodule_roll.update(checkout, props.submodule)
if not rolls:
with api.step.nest('nothing to roll, exiting'):
return
message = api.step.empty('commit message').presentation
message.step_summary_text = api.roll_commit_message.format(
*rolls,
roll_prefix='roll:',
send_comment=True,
)
def GenTests(api: TEST_DEPS) -> Iterator[recipe_test_api.TestData]:
"""Create tests."""
def properties(*submodules, **kwargs):
props = InputProperties(**kwargs)
assert len(submodules) == 1
props.submodule.CopyFrom(submodules[0])
return api.properties(props)
yield api.test(
'success',
properties(api.submodule_roll.entry('a1')),
api.submodule_roll.gitmodules(
'a1',
a1='sso://foo/a1',
b2='sso://foo/b2',
),
api.gitiles.log('a1.log a1', 'A'),
)
yield api.test(
'noop',
properties(api.submodule_roll.entry('b2')),
api.submodule_roll.gitmodules('b2', b2='b2', b2_branch='branch'),
api.gitiles.log('b2.log b2', 'A', n=0),
)
yield api.test(
'missing',
properties(api.submodule_roll.entry('b2')),
api.submodule_roll.gitmodules('b2', a1='sso://foo/a1'),
status='FAILURE',
)