blob: aa49f1d3955e42d1fa99a858426f750530f0b736 [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 validating that the triggering CL includes an appropriate
commit footer if it affects files that indicate it's an LSC (large-scale
change) that requires a soft transition with other repositories.
The recipe itself doesn't check which files are affected, so it's up to the
triggering policy to only trigger this build on changes that affect the
correct files.
"""
DEPS = [
"fuchsia/gerrit",
"fuchsia/git",
"fuchsia/status_check",
"recipe_engine/buildbucket",
"recipe_engine/context",
"recipe_engine/path",
"recipe_engine/python",
"recipe_engine/raw_io",
]
LSC_FOOTER = "LSC"
def RunSteps(api):
build_input = api.buildbucket.build.input
if not build_input.gerrit_changes:
api.python.failing_step("not a CQ build", "LSC checks are only available in CQ")
gerrit_change = build_input.gerrit_changes[0]
checkout_dir = api.path.mkdtemp()
api.git.checkout_cl(gerrit_change, checkout_dir)
with api.context(cwd=checkout_dir):
commit_msg = api.git.get_commit_message()
footer_value = api.git.read_commit_footer(commit_msg, LSC_FOOTER, sep=[": ", "="])
if not footer_value:
api.gerrit.set_review(
"comment on CL",
str(gerrit_change.change),
message=(
"This change requires the %r footer with a link to a bug. "
"If you don't believe this change is an LSC, please add the "
"%r footer with a description explaining why it is not. "
"See http://go/fuchsia-lsc for additional details."
)
% (LSC_FOOTER, LSC_FOOTER),
)
api.python.failing_step(
"no %r footer" % LSC_FOOTER,
"this change requires an LSC bug because of the files it touches",
)
def GenTests(api):
yield (
api.status_check.test("basic")
+ api.buildbucket.try_build()
+ api.step_data(
"get commit msg",
api.raw_io.stream_output("Foo\n\n%s=fxbug.dev/123" % LSC_FOOTER),
)
)
yield (
api.status_check.test("colon_separator")
+ api.buildbucket.try_build()
+ api.step_data(
"get commit msg",
api.raw_io.stream_output("Foo\n\n%s: fxbug.dev/123" % LSC_FOOTER),
)
)
yield (
api.status_check.test("missing_footer", status="failure")
+ api.buildbucket.try_build()
+ api.step_data(
"get commit msg", api.raw_io.stream_output("Foo\n\nChange-Id: Iabc")
)
)
yield api.status_check.test("ci", status="failure") + api.buildbucket.ci_build()