Skip to content

Commit 08d663f

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 6ed6c4c commit 08d663f

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-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
@@ -237,9 +237,19 @@ def plural(num_tests):
237237
return report
238238

239239

240-
def generate_report_from_files(title, return_code, junit_files):
240+
def generate_report_from_files(title, return_code, build_log_files):
241+
junit_files = [
242+
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
243+
]
244+
ninja_log_files = [
245+
ninja_log for ninja_log in build_log_files if ninja_log.endswith(".log")
246+
]
247+
ninja_logs = []
248+
for ninja_log_file in ninja_log_files:
249+
with open(ninja_log_file, "r") as ninja_log_file_handle:
250+
ninja_logs.append(
251+
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
252+
)
241253
return generate_report(
242-
title,
243-
return_code,
244-
[JUnitXml.fromfile(p) for p in junit_files],
254+
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
245255
)

.ci/generate_test_report_lib_test.py

Lines changed: 62 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

@@ -621,3 +623,63 @@ def test_report_size_limit(self):
621623
)
622624
),
623625
)
626+
627+
def test_generate_report_end_to_end(self):
628+
with tempfile.TemporaryDirectory() as temp_dir:
629+
junit_xml_file = os.path.join(temp_dir, "junit.xml")
630+
with open(junit_xml_file, "w") as junit_xml_handle:
631+
junit_xml_handle.write(
632+
dedent(
633+
"""\
634+
<?xml version="1.0" encoding="UTF-8"?>
635+
<testsuites time="0.00">
636+
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00">
637+
<testcase classname="Bar/test_1" name="test_1" time="0.00"/>
638+
</testsuite>
639+
</testsuites>"""
640+
)
641+
)
642+
ninja_log_file = os.path.join(temp_dir, "ninja.log")
643+
with open(ninja_log_file, "w") as ninja_log_handle:
644+
ninja_log_handle.write(
645+
dedent(
646+
"""\
647+
[1/5] test/1.stamp
648+
[2/5] test/2.stamp
649+
[3/5] test/3.stamp
650+
[4/5] test/4.stamp
651+
FAILED: test/4.stamp
652+
touch test/4.stamp
653+
Wow! That's so True!
654+
[5/5] test/5.stamp"""
655+
)
656+
)
657+
test = generate_test_report_lib.generate_report_from_files(
658+
"Foo", 1, [junit_xml_file, ninja_log_file]
659+
)
660+
661+
print(test)
662+
with open("/tmp/blah", "w") as handle2:
663+
handle2.write(test)
664+
self.assertEqual(
665+
generate_test_report_lib.generate_report_from_files(
666+
"Foo", 1, [junit_xml_file, ninja_log_file]
667+
),
668+
dedent(
669+
"""\
670+
# Foo
671+
672+
* 1 test passed
673+
<details>
674+
<summary>test/4.stamp</summary>
675+
676+
```
677+
FAILED: test/4.stamp
678+
touch test/4.stamp
679+
Wow! That's so True!
680+
```
681+
</details>
682+
683+
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."""
684+
),
685+
)

.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)