Skip to content

Commit 85aa56b

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 3094627 commit 85aa56b

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
@@ -240,9 +240,19 @@ def plural(num_tests):
240240
return report
241241

242242

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

.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

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

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