blob: 6d38211818095fe6e7c9efacf91e037b9ea5863d [file] [log] [blame]
# Copyright 2020 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.
"""Recipe for updating the submodule super manifest project."""
from recipe_engine.recipe_api import Property
DEPS = [
"fuchsia/checkout",
"fuchsia/git",
"fuchsia/jiri",
"fuchsia/status_check",
"recipe_engine/context",
"recipe_engine/file",
"recipe_engine/path",
"recipe_engine/step",
]
PROPERTIES = {
"manifest": Property(kind=str, help="Jiri manifest to use.", default="flower"),
"remote": Property(
kind=str,
help="Remote manifest repository.",
default="https://fuchsia.googlesource.com/integration",
),
"super_manifest_project": Property(
kind=str,
help="Super manifest project to update.",
default="https://fuchsia.googlesource.com/sandbox/fuchsia",
),
"default_branch": Property(
kind=str,
help="Default remote branch name.",
default="main",
),
}
GENERATE_SCRIPT = "setup.sh"
LOCAL_BRANCH_NAME = "latest"
def RunSteps(api, manifest, remote, super_manifest_project, default_branch):
api.checkout.fuchsia_with_options(
manifest=manifest,
path=api.path["start_dir"],
remote=remote,
)
with api.context(cwd=api.path["start_dir"]):
api.git.raw_checkout(branch=LOCAL_BRANCH_NAME)
super_manifest_project_path = api.path["start_dir"].join("super")
api.file.ensure_directory("make dirs", super_manifest_project_path)
api.git.checkout(
url=super_manifest_project,
ref=default_branch,
path=super_manifest_project_path,
submodules=False,
)
generate_script_path = super_manifest_project_path.join(GENERATE_SCRIPT)
with api.context(cwd=super_manifest_project_path):
# See https://fuchsia.googlesource.com/jiri/+/main/cmd/jiri/generate-gitmodules.go
# for details.
api.git.remote_add("fuchsia", api.path["start_dir"])
api.git.fetch("fuchsia")
api.git(
"git merge",
"merge",
"-m",
"merge upstream changes",
"--allow-unrelated-histories",
"fuchsia/%s" % LOCAL_BRANCH_NAME,
)
api.jiri(
"generate-gitmodules",
"--generate-script",
generate_script_path,
".gitmodules",
)
api.step("run %s" % GENERATE_SCRIPT, [generate_script_path])
api.file.remove("remove %s" % GENERATE_SCRIPT, generate_script_path)
# Add & Push updated submodules.
api.git.add(pathspec=".gitmodules", force=True)
# Only commit and push if we have a diff, otherwise commit fails.
if api.git.diff(
ref_base=None, cached=True, exit_code=True, ok_ret="any"
).retcode:
api.git.commit(message="Update submodules based on jiri manifest")
api.git.push(
"HEAD:%s" % default_branch, options=("nokeycheck", "skip-validation")
)
def GenTests(api):
yield api.status_check.test("no_diff")
yield api.status_check.test("yes_diff") + api.step_data("git diff", retcode=1)