[ci] Fix error when no junit files are passed to report generator

This resulted in the style being None and despite the report being
empty as well, we tried to send it to the agent and Python can't
send None as an argument.

To fix this return "success" style and also check whether the
report has any content before calling the agent.
This commit is contained in:
David Spickett 2024-11-18 09:07:15 +00:00
parent 9a844a36eb
commit 6a12b43ac0

View File

@ -309,10 +309,8 @@ class TestReports(unittest.TestCase):
# If include failures is False, total number of test will be reported but their names
# and output will not be.
def _generate_report(title, junit_objects, size_limit=1024 * 1024, list_failures=True):
style = None
if not junit_objects:
return ("", style)
return ("", "success")
failures = {}
tests_run = 0
@ -403,22 +401,23 @@ if __name__ == "__main__":
report, style = generate_report(args.title, args.junit_files)
p = subprocess.Popen(
[
"buildkite-agent",
"annotate",
"--context",
args.context,
"--style",
style,
],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
if report:
p = subprocess.Popen(
[
"buildkite-agent",
"annotate",
"--context",
args.context,
"--style",
style,
],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
# The report can be larger than the buffer for command arguments so we send
# it over stdin instead.
_, err = p.communicate(input=report)
if p.returncode:
raise RuntimeError(f"Failed to send report to buildkite-agent:\n{err}")
# The report can be larger than the buffer for command arguments so we send
# it over stdin instead.
_, err = p.communicate(input=report)
if p.returncode:
raise RuntimeError(f"Failed to send report to buildkite-agent:\n{err}")