blob: 9aae6fc40804e1a5d624e2c60f8a9e8ad0028c29 [file] [log] [blame]
# Copyright 2021 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 rolling submodule"""
from recipe_engine import post_process
from PB.recipes.fuchsia.submodule_update import InputProperties
from PB.recipe_engine import result
from PB.go.chromium.org.luci.buildbucket.proto import common
PYTHON_VERSION_COMPATIBILITY = "PY3"
DEPS = [
"fuchsia/buildbucket_util",
"fuchsia/checkout",
"fuchsia/git",
"fuchsia/jiri",
"recipe_engine/buildbucket",
"recipe_engine/context",
"recipe_engine/file",
"recipe_engine/path",
"recipe_engine/properties",
"recipe_engine/step",
]
PROPERTIES = InputProperties
def RunSteps(api, props):
checkout = api.checkout.fuchsia_with_options(
project=props.project,
manifest=props.manifest,
remote=props.remote,
# Skip for faster checkout.
fetch_packages=False,
)
with api.context(cwd=checkout.root_dir):
# jiri projects
api.jiri.project()
# cipd snapshot files
snapshot_file = api.path["cleanup"].join("jiri.snapshot")
api.jiri.snapshot(snapshot_file, cipd=True)
revision = str(api.buildbucket.build.input.gitiles_commit.id)
api.step("print commit id", ["echo", revision])
last_successful_build = api.buildbucket_util.last_build(status=common.SUCCESS)
if last_successful_build:
prev_revision = str(last_successful_build.input.gitiles_commit.id)
api.step("print previous commit id", ["echo", prev_revision])
with api.step.nest("checkout super project"):
super_project_path = api.path["start_dir"].join("super_project")
api.file.ensure_directory("make dirs", super_project_path)
api.git.checkout(
url=props.super_project,
path=super_project_path,
submodules=False,
)
with api.context(cwd=super_project_path):
api.git.update_submodule(paths=["integration"])
with api.context(cwd=super_project_path.join("integration")):
if api.git.is_ancestor(commit_1=revision):
return result.RawResult(
summary_markdown="commit already exists: %s" % revision,
status=common.SUCCESS,
)
api.git.raw_checkout(ref=revision)
message = api.git.get_commit_message(commit=revision)
with api.context(cwd=super_project_path):
api.git.commit(message=message, all_tracked=True)
api.git.push("HEAD:refs/heads/main")
def GenTests(api):
properties = {
"manifest": "flower",
"remote": "https://fuchsia.googlesource.com/integration",
"super_project": "https://fuchsia.googlesource.com/superproject",
}
yield (
api.buildbucket_util.test("basic", repo="fuchsia")
+ api.properties(**properties)
+ api.post_check(lambda check, steps: check("print commit id" in steps))
+ api.buildbucket.simulated_search_results([api.buildbucket.ci_build_message()])
)
yield (
api.buildbucket_util.test("commit_already_exists")
+ api.properties(**properties)
+ api.step_data("is ancestor", retcode=0)
+ api.post_check(post_process.StatusSuccess)
)
yield (
api.buildbucket_util.test("push_change")
+ api.properties(**properties)
+ api.step_data("is ancestor", retcode=1)
+ api.post_check(post_process.StatusSuccess)
)