|
1 | 1 | use std::collections::BTreeMap;
|
2 |
| -use std::fs::File; |
3 |
| -use std::io::Write; |
4 | 2 | use std::path::Path;
|
5 | 3 |
|
6 | 4 | use anyhow::Context;
|
7 | 5 | use build_helper::metrics::{
|
8 | 6 | BuildStep, JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, format_build_steps,
|
9 | 7 | };
|
10 | 8 |
|
11 |
| -pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow::Result<()> { |
| 9 | +pub fn postprocess_metrics(metrics_path: &Path) -> anyhow::Result<()> { |
12 | 10 | let metrics = load_metrics(metrics_path)?;
|
13 | 11 |
|
14 |
| - let mut file = File::options() |
15 |
| - .append(true) |
16 |
| - .create(true) |
17 |
| - .open(summary_path) |
18 |
| - .with_context(|| format!("Cannot open summary file at {summary_path:?}"))?; |
19 |
| - |
20 | 12 | if !metrics.invocations.is_empty() {
|
21 |
| - writeln!(file, "# Bootstrap steps")?; |
22 |
| - record_bootstrap_step_durations(&metrics, &mut file)?; |
23 |
| - record_test_suites(&metrics, &mut file)?; |
| 13 | + println!("# Bootstrap steps"); |
| 14 | + record_bootstrap_step_durations(&metrics); |
| 15 | + record_test_suites(&metrics); |
24 | 16 | }
|
25 | 17 |
|
26 | 18 | Ok(())
|
27 | 19 | }
|
28 | 20 |
|
29 |
| -fn record_bootstrap_step_durations(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> { |
| 21 | +fn record_bootstrap_step_durations(metrics: &JsonRoot) { |
30 | 22 | for invocation in &metrics.invocations {
|
31 | 23 | let step = BuildStep::from_invocation(invocation);
|
32 | 24 | let table = format_build_steps(&step);
|
33 | 25 | eprintln!("Step `{}`\n{table}\n", invocation.cmdline);
|
34 |
| - writeln!( |
35 |
| - file, |
| 26 | + println!( |
36 | 27 | r"<details>
|
37 | 28 | <summary>{}</summary>
|
38 | 29 | <pre><code>{table}</code></pre>
|
39 | 30 | </details>
|
40 | 31 | ",
|
41 | 32 | invocation.cmdline
|
42 |
| - )?; |
| 33 | + ); |
43 | 34 | }
|
44 | 35 | eprintln!("Recorded {} bootstrap invocation(s)", metrics.invocations.len());
|
45 |
| - |
46 |
| - Ok(()) |
47 | 36 | }
|
48 | 37 |
|
49 |
| -fn record_test_suites(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> { |
| 38 | +fn record_test_suites(metrics: &JsonRoot) { |
50 | 39 | let suites = get_test_suites(&metrics);
|
51 | 40 |
|
52 | 41 | if !suites.is_empty() {
|
53 | 42 | let aggregated = aggregate_test_suites(&suites);
|
54 | 43 | let table = render_table(aggregated);
|
55 |
| - writeln!(file, "\n# Test results\n")?; |
56 |
| - writeln!(file, "{table}")?; |
| 44 | + println!("\n# Test results\n"); |
| 45 | + println!("{table}"); |
57 | 46 | } else {
|
58 | 47 | eprintln!("No test suites found in metrics");
|
59 | 48 | }
|
60 |
| - |
61 |
| - Ok(()) |
62 | 49 | }
|
63 | 50 |
|
64 | 51 | fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
|
|
0 commit comments