Skip to content

Commit c5e67aa

Browse files
[CI] Enable Build Failure Reporting
This patch finishes up the plumbing so that generate_test_report will dump build failures into the Github checks summary. Pull Request: llvm#152622
1 parent d8a5cc7 commit c5e67aa

File tree

4 files changed

+78
-7
lines changed

4 files changed

+78
-7
lines changed

.ci/generate_test_report_github.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
if __name__ == "__main__":
1717
parser = argparse.ArgumentParser()
1818
parser.add_argument("return_code", help="The build's return code.", type=int)
19-
parser.add_argument("junit_files", help="Paths to JUnit report files.", nargs="*")
19+
parser.add_argument(
20+
"build_test_logs", help="Paths to JUnit report files and ninja logs.", nargs="*"
21+
)
2022
args = parser.parse_args()
2123

2224
report = generate_test_report_lib.generate_report_from_files(
23-
PLATFORM_TITLES[platform.system()], args.return_code, args.junit_files
25+
PLATFORM_TITLES[platform.system()], args.return_code, args.build_test_logs
2426
)
2527

2628
print(report)

.ci/generate_test_report_lib.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,19 @@ def plural(num_tests):
245245
return report
246246

247247

248-
def generate_report_from_files(title, return_code, junit_files):
248+
def generate_report_from_files(title, return_code, build_log_files):
249+
junit_files = [
250+
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
251+
]
252+
ninja_log_files = [
253+
ninja_log for ninja_log in build_log_files if ninja_log.endswith(".log")
254+
]
255+
ninja_logs = []
256+
for ninja_log_file in ninja_log_files:
257+
with open(ninja_log_file, "r") as ninja_log_file_handle:
258+
ninja_logs.append(
259+
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
260+
)
249261
return generate_report(
250-
title,
251-
return_code,
252-
[JUnitXml.fromfile(p) for p in junit_files],
262+
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
253263
)

.ci/generate_test_report_lib_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import unittest
99
from io import StringIO
1010
from textwrap import dedent
11+
import tempfile
12+
import os
1113

1214
from junitparser import JUnitXml
1315

@@ -624,3 +626,59 @@ def test_report_size_limit(self):
624626
)
625627
),
626628
)
629+
630+
def test_generate_report_end_to_end(self):
631+
with tempfile.TemporaryDirectory() as temp_dir:
632+
junit_xml_file = os.path.join(temp_dir, "junit.xml")
633+
with open(junit_xml_file, "w") as junit_xml_handle:
634+
junit_xml_handle.write(
635+
dedent(
636+
"""\
637+
<?xml version="1.0" encoding="UTF-8"?>
638+
<testsuites time="0.00">
639+
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00">
640+
<testcase classname="Bar/test_1" name="test_1" time="0.00"/>
641+
</testsuite>
642+
</testsuites>"""
643+
)
644+
)
645+
ninja_log_file = os.path.join(temp_dir, "ninja.log")
646+
with open(ninja_log_file, "w") as ninja_log_handle:
647+
ninja_log_handle.write(
648+
dedent(
649+
"""\
650+
[1/5] test/1.stamp
651+
[2/5] test/2.stamp
652+
[3/5] test/3.stamp
653+
[4/5] test/4.stamp
654+
FAILED: test/4.stamp
655+
touch test/4.stamp
656+
Wow! That's so True!
657+
[5/5] test/5.stamp"""
658+
)
659+
)
660+
self.assertEqual(
661+
generate_test_report_lib.generate_report_from_files(
662+
"Foo", 1, [junit_xml_file, ninja_log_file]
663+
),
664+
dedent(
665+
"""\
666+
# Foo
667+
668+
* 1 test passed
669+
670+
All tests passed but another part of the build **failed**. Click on a failure below to see the details.
671+
672+
<details>
673+
<summary>test/4.stamp</summary>
674+
675+
```
676+
FAILED: test/4.stamp
677+
touch test/4.stamp
678+
Wow! That's so True!
679+
```
680+
</details>
681+
682+
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label."""
683+
),
684+
)

.ci/utils.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function at-exit {
3333

3434
if [[ "$GITHUB_STEP_SUMMARY" != "" ]]; then
3535
python "${MONOREPO_ROOT}"/.ci/generate_test_report_github.py \
36-
$retcode "${BUILD_DIR}"/test-results.*.xml >> $GITHUB_STEP_SUMMARY
36+
$retcode "${BUILD_DIR}"/test-results.*.xml "${BUILD_DIR}"/ninja*.log \
37+
>> $GITHUB_STEP_SUMMARY
3738
fi
3839
}
3940
trap at-exit EXIT

0 commit comments

Comments
 (0)