about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-03-10 15:57:12 +0100
committerGitHub <noreply@github.com>2025-03-10 15:57:12 +0100
commit5717cc9ef7cdba1fe1a7710637688dfb20a85493 (patch)
treefd1f3862426ff1ad2d1b89cecf18f8172efa90c9 /src
parent739672cf165b665ad4739a431d95d55d8e25db14 (diff)
parent1483cb67d91f493c9e8599cc969a03ae1b846435 (diff)
Rollup merge of #138268 - Kobzol:fix-summary-nan, r=jieyouxu
Handle empty test suites in GitHub job summary report

Should fix [NaN](https://github.com/rust-lang-ci/rust/actions/runs/13739044506#summary-38426140405)s being printed.

r? `@jieyouxu`
Diffstat (limited to 'src')
-rw-r--r--src/ci/citool/src/metrics.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ci/citool/src/metrics.rs b/src/ci/citool/src/metrics.rs
index 8548602b31c..83b3d5ceed0 100644
--- a/src/ci/citool/src/metrics.rs
+++ b/src/ci/citool/src/metrics.rs
@@ -67,6 +67,10 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
     let mut table = "| Test suite | Passed ✅ | Ignored 🚫 | Failed  ❌ |\n".to_string();
     writeln!(table, "|:------|------:|------:|------:|").unwrap();
 
+    fn compute_pct(value: f64, total: f64) -> f64 {
+        if total == 0.0 { 0.0 } else { value / total }
+    }
+
     fn write_row(
         buffer: &mut String,
         name: &str,
@@ -75,9 +79,9 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
     ) -> std::fmt::Result {
         let TestSuiteRecord { passed, ignored, failed } = record;
         let total = (record.passed + record.ignored + record.failed) as f64;
-        let passed_pct = ((*passed as f64) / total) * 100.0;
-        let ignored_pct = ((*ignored as f64) / total) * 100.0;
-        let failed_pct = ((*failed as f64) / total) * 100.0;
+        let passed_pct = compute_pct(*passed as f64, total) * 100.0;
+        let ignored_pct = compute_pct(*ignored as f64, total) * 100.0;
+        let failed_pct = compute_pct(*failed as f64, total) * 100.0;
 
         write!(buffer, "| {surround}{name}{surround} |")?;
         write!(buffer, " {surround}{passed} ({passed_pct:.0}%){surround} |")?;