blob: 186b2ae0e7ca5fedb81cadae6004f08f4d6d8150 [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.
"""Create release branches of sub-projects of integration.git.
It's not possible to create cherry-pick CLs in a repo until that repo has a
branch corresponding to the integration.git branch that the CL is targetting.
This recipe solves the problem of creating a branch B in a repo R pinned in
integration.git, based on the revision of R that's pinned on branch B of
integration.git.
"""
from PB.go.chromium.org.luci.buildbucket.proto import build as build_pb2
from PB.go.chromium.org.luci.buildbucket.proto import common as common_pb2
from PB.recipe_engine.result import RawResult
from PB.recipes.fuchsia.release.init_project_branch import InputProperties
DEPS = [
"fuchsia/checkout",
"fuchsia/gerrit",
"fuchsia/jiri",
"fuchsia/release",
"fuchsia/status_check",
"recipe_engine/context",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = InputProperties
def RunSteps(api, props):
with api.step.nest("check inputs"):
if not api.release.validate_branch(props.target_branch):
return RawResult(
summary_markdown='`target_branch` must start with "releases/"',
status=common_pb2.FAILURE,
)
checkout = api.checkout.fuchsia_with_options(
build_input=build_pb2.Build.Input(
gitiles_commit=common_pb2.GitilesCommit(
ref="refs/heads/%s" % props.target_branch,
project=props.project,
),
),
project=props.project,
manifest=props.manifest,
remote=props.remote,
# Skip for faster checkout.
fetch_packages=False,
)
integration_root = api.release.get_project_path(checkout.root_dir, props.project)
with api.step.nest("initialize branches"), api.context(cwd=integration_root):
for project_info in api.jiri.project(
projects=props.projects,
test_data=[
{
"name": project,
"revision": "abc123",
"gerrithost": "https://fuchsia-review.googlesource.com",
}
for project in props.projects
],
).json.output:
project_name = project_info["name"]
step_name = "create branch %s in %s" % (props.target_branch, project_name)
if props.dryrun:
api.step.empty("(dry run) would %s" % step_name)
else:
api.gerrit.create_branch(
name=step_name,
host=project_info["gerrithost"],
project=project_name,
ref=props.target_branch,
revision=project_info["revision"],
)
def GenTests(api):
def properties(**kwargs):
props = dict(
target_branch="releases/f2",
remote="https://fuchsia.googlesource.com/integration",
project="integration",
manifest="minimal",
projects=["foo", "bar"],
)
props.update(kwargs)
return api.properties(**props)
yield api.status_check.test("success") + properties()
yield api.status_check.test("dry_run") + properties(dryrun=True)
yield (
api.status_check.test("invalid_branch_input", status="failure")
+ properties(target_branch="invalidbranch")
)