-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildSummary.ts
More file actions
76 lines (71 loc) · 2.45 KB
/
Copy pathbuildSummary.ts
File metadata and controls
76 lines (71 loc) · 2.45 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
// Copyright 2024-25 The MathWorks, Inc.
import * as core from "@actions/core";
import { join } from "path";
import { readFileSync, unlinkSync, existsSync } from "fs";
export function addSummary(taskSummaryTableRows: string[][]) {
try {
core.summary.addHeading("MATLAB Build Results").addTable(taskSummaryTableRows);
} catch (e) {
console.error("An error occurred while adding the build results table to the summary:", e);
}
}
export function getSummaryRows(buildSummary: string): any[] {
const rows = JSON.parse(buildSummary).map((t: any) => {
if (t.failed) {
return [t.name, "🔴 Failed", t.description, t.duration];
} else if (t.skipped) {
return [
t.name,
"🔵 Skipped" + " (" + interpretSkipReason(t.skipReason) + ")",
t.description,
t.duration,
];
} else {
return [t.name, "🟢 Successful", t.description, t.duration];
}
});
return rows;
}
export function interpretSkipReason(skipReason: string) {
switch (skipReason) {
case "UpToDate":
return "up-to-date";
case "UserSpecified":
case "UserRequested":
return "user requested";
case "DependencyFailed":
return "dependency failed";
default:
return skipReason;
}
}
export function processAndAddBuildSummary(runnerTemp: string, runId: string) {
const header = [
{ data: "MATLAB Task", header: true },
{ data: "Status", header: true },
{ data: "Description", header: true },
{ data: "Duration (HH:mm:ss)", header: true },
];
const filePath: string = join(runnerTemp, `buildSummary${runId}.json`);
let taskSummaryTable;
if (existsSync(filePath)) {
try {
const buildSummary = readFileSync(filePath, { encoding: "utf8" });
const rows = getSummaryRows(buildSummary);
taskSummaryTable = [header, ...rows];
} catch (e) {
console.error("An error occurred while reading the build summary file:", e);
return;
} finally {
try {
unlinkSync(filePath);
} catch (e) {
console.error(
`An error occurred while trying to delete the build summary file ${filePath}:`,
e,
);
}
}
addSummary(taskSummaryTable);
}
}