Skip to content

Commit 7d5af16

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. Reviewers: Keenuts, lnihlen, dschuff, gburgessiv, cmtice, DavidSpickett Reviewed By: cmtice, DavidSpickett Pull Request: #152622
1 parent 869bce2 commit 7d5af16

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,19 @@ def plural(num_tests):
251251
return report
252252

253253

254-
def generate_report_from_files(title, return_code, junit_files):
254+
def generate_report_from_files(title, return_code, build_log_files):
255+
junit_files = [
256+
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
257+
]
258+
ninja_log_files = [
259+
ninja_log for ninja_log in build_log_files if ninja_log.endswith(".log")
260+
]
261+
ninja_logs = []
262+
for ninja_log_file in ninja_log_files:
263+
with open(ninja_log_file, "r") as ninja_log_file_handle:
264+
ninja_logs.append(
265+
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
266+
)
255267
return generate_report(
256-
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], []
268+
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
257269
)

.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

@@ -718,3 +720,59 @@ def test_report_size_limit(self):
718720
)
719721
),
720722
)
723+
724+
def test_generate_report_end_to_end(self):
725+
with tempfile.TemporaryDirectory() as temp_dir:
726+
junit_xml_file = os.path.join(temp_dir, "junit.xml")
727+
with open(junit_xml_file, "w") as junit_xml_handle:
728+
junit_xml_handle.write(
729+
dedent(
730+
"""\
731+
<?xml version="1.0" encoding="UTF-8"?>
732+
<testsuites time="0.00">
733+
<testsuite name="Passed" tests="1" failures="0" skipped="0" time="0.00">
734+
<testcase classname="Bar/test_1" name="test_1" time="0.00"/>
735+
</testsuite>
736+
</testsuites>"""
737+
)
738+
)
739+
ninja_log_file = os.path.join(temp_dir, "ninja.log")
740+
with open(ninja_log_file, "w") as ninja_log_handle:
741+
ninja_log_handle.write(
742+
dedent(
743+
"""\
744+
[1/5] test/1.stamp
745+
[2/5] test/2.stamp
746+
[3/5] test/3.stamp
747+
[4/5] test/4.stamp
748+
FAILED: test/4.stamp
749+
touch test/4.stamp
750+
Wow! That's so True!
751+
[5/5] test/5.stamp"""
752+
)
753+
)
754+
self.assertEqual(
755+
generate_test_report_lib.generate_report_from_files(
756+
"Foo", 1, [junit_xml_file, ninja_log_file]
757+
),
758+
dedent(
759+
"""\
760+
# Foo
761+
762+
* 1 test passed
763+
764+
All tests passed but another part of the build **failed**. Click on a failure below to see the details.
765+
766+
<details>
767+
<summary>test/4.stamp</summary>
768+
769+
```
770+
FAILED: test/4.stamp
771+
touch test/4.stamp
772+
Wow! That's so True!
773+
```
774+
</details>
775+
776+
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."""
777+
),
778+
)

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