forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.mts
More file actions
91 lines (77 loc) · 2.33 KB
/
Copy pathresults.mts
File metadata and controls
91 lines (77 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import path from 'path';
import Zip from 'adm-zip';
import type {JsonReport} from '../../packages/benchpress/src/reporter/json_file_reporter_types.js';
import {bold} from '@angular/ng-dev';
/** Results of an individual benchmark scenario. */
export interface ScenarioResult {
id: string;
data: JsonReport;
summaryConsoleText: string;
summaryMarkdownText: string;
}
/**
* Overall result of a benchmark target.
* A benchmark target may contain multiple scenarios.
*/
export interface OverallResult {
scenarios: ScenarioResult[];
summaryConsoleText: string;
summaryMarkdownText: string;
}
/** Collects and parses the benchmark results of the given Bazel target testlog directory. */
export function collectBenchmarkResults(testlogDir: string): OverallResult {
const z = new Zip(path.join(testlogDir, 'test.outputs/outputs.zip'));
const scenarioResults: ScenarioResult[] = [];
for (const e of z.getEntries()) {
if (path.extname(e.entryName) !== '.json') {
continue;
}
const data = JSON.parse(z.readAsText(e.entryName));
// Skip files that do not look like benchpress reports.
if (!isJsonReport(data)) {
continue;
}
scenarioResults.push({
id: data.description.id,
data,
// Output used for console output when running locally/CI.
summaryConsoleText: `\
${data.metricsText}
${data.validSampleTexts.join('\n')}
${data.statsText}`,
// Output used for e.g. GitHub actions.
summaryMarkdownText: `\
<details><summary>Full example results</summary>
\`\`\`
${data.metricsText}
${data.validSampleTexts.join('\n')}
${data.statsText}
\`\`\`
</details>
\`\`\`
${data.metricsText}
${data.statsText}
\`\`\``,
});
}
return {
scenarios: scenarioResults,
summaryConsoleText: scenarioResults
.map((s) => `${bold(s.id)}\n\n${s.summaryConsoleText}`)
.join('`\n'),
summaryMarkdownText: scenarioResults
.map((s) => `### ${s.id}\n\n${s.summaryMarkdownText}`)
.join('`\n'),
};
}
/** Whether the object corresponds to a benchpress JSON report. */
function isJsonReport(data: any): data is JsonReport {
return data['completeSample'] !== undefined;
}