blob: d9e0f417d9b2e4a6118af432372f3191f2a8537c [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 urllib.parse import urlparse
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/git",
"fuchsia/jiri",
"fuchsia/release",
"fuchsia/sso",
"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,
)
https_remote = api.sso.sso_to_https(props.remote)
revision = api.git.get_remote_branch_head(
step_name="get target branch HEAD",
url=https_remote,
branch=props.target_branch,
)
checkout = api.checkout.fuchsia_with_options(
build_input=build_pb2.Build.Input(
gitiles_commit=common_pb2.GitilesCommit(
id=revision,
project=props.project,
host=urlparse(https_remote).hostname,
),
),
project=props.project,
manifest=props.manifest,
remote=props.remote,
# Skip for faster checkout.
fetch_packages=False,
)
integration_root = checkout.project_path(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 = f"create branch {props.target_branch} in {project_name}"
if props.dryrun:
api.step.empty(f"(dry run) would {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.test("success") + properties()
yield api.test("dry_run") + properties(dryrun=True)
yield (
api.test("invalid_branch_input", status="FAILURE")
+ properties(target_branch="invalidbranch")
)