blob: b48e04c855ed5a841b7e72bd38293ebba3f084e2 [file] [log] [blame]
# 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.
"""Roll a CIPD package."""
from __future__ import annotations
import collections
import dataclasses
import re
from typing import TYPE_CHECKING
from PB.recipe_engine import result as result_pb2
from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
from PB.recipes.pigweed.cipd_roller import InputProperties
if TYPE_CHECKING: # pragma: no cover
from typing import Generator, List
from recipe_engine import recipe_test_api
DEPS = [
'fuchsia/auto_roller',
'pigweed/checkout',
'pigweed/cipd_roll',
'recipe_engine/properties',
'recipe_engine/step',
]
PROPERTIES = InputProperties
def RunSteps(api, props):
props.checkout_options.use_trigger = False
checkout = api.checkout(props.checkout_options)
commit = api.cipd_roll.Commit()
for pkg in props.packages:
with api.step.nest(pkg.spec):
roll = api.cipd_roll.update_package(checkout.root, pkg)
if roll:
commit.rolls.append(roll)
if not commit:
return result_pb2.RawResult( # pragma: no cover
summary_markdown='nothing to roll',
status=common_pb2.SUCCESS,
)
change = api.auto_roller.attempt_roll(
props.auto_roller_options,
repo_dir=checkout.root,
commit_message=commit.message(name=props.roll_name),
)
return api.auto_roller.raw_result(change)
def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]:
"""Create tests."""
prefix = 'pigweed/host_tools/cp38'
spec = f'{prefix}/${{platform}}'
def properties(packages, dry_run=True, **kwargs):
props = InputProperties(**kwargs)
props.packages.extend(packages)
props.checkout_options.CopyFrom(api.checkout.git_options())
props.auto_roller_options.CopyFrom(
api.auto_roller.Options(
dry_run=dry_run,
remote=props.checkout_options.remote,
)
)
return api.properties(props)
yield api.test(
'success',
properties([api.cipd_roll.package_props(spec=spec)]),
api.checkout.ci_test_data(),
api.cipd_roll.read_file_step_data(
spec,
'pigweed.json',
api.cipd_roll.package(
spec,
'git_revision:123',
platforms=['linux-amd64', 'windows-amd64'],
),
),
api.auto_roller.dry_run_success(),
)