Skip to content

Commit 31b9b97

Browse files
committed
Create lit analyzer specific comment table
1 parent 58aefb4 commit 31b9b97

File tree

5 files changed

+192
-89
lines changed

5 files changed

+192
-89
lines changed

dist/index.js

Lines changed: 78 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getBooleanInput, getInput, setFailed, debug } from "@actions/core";
22
import { exec } from "@actions/exec";
33
import { getOctokit, context } from "@actions/github";
4-
import { analyze } from "./scripts/analyze";
4+
import { analyze, eslint, litAnalyzer } from "./scripts/analyze";
55
import { formatting } from "./scripts/formatting";
66
import { testing } from "./scripts/testing";
77
import { comment } from "./scripts/comment";
@@ -24,11 +24,11 @@ export const buildComment = async (
2424
for (const { label, command } of commands) {
2525
const result = await runCommand(command, label);
2626
if (result) {
27-
commentBody += `<li>${failedEmoji} - ${label}
28-
<details><summary>See details</summary>${result}</details></li>`;
27+
commentBody += `${failedEmoji} - ${label}
28+
<details><summary>See details</summary>${result}</details>`;
2929
errorMessages += `${result}`;
3030
} else {
31-
commentBody += `<li>${passedEmoji} - ${label}\n</li>`;
31+
commentBody += `${passedEmoji} - ${label}\n`;
3232
}
3333
}
3434
return [commentBody, errorMessages];
@@ -120,6 +120,13 @@ export async function run(): Promise<void> {
120120
? await eslint({ label: "ESLint", command: "npm run lint" })
121121
: undefined;
122122

123+
const litAnalyzerStr: stepResponse | undefined = doStaticAnalysis
124+
? await litAnalyzer({
125+
label: "Lit Analyzer",
126+
command: "npm run lint:lit-analyzer",
127+
})
128+
: undefined;
129+
123130
// run Code Formatting
124131
const codeFormattingStr: stepResponse | undefined = doCodeFormatting
125132
? await formatting()
@@ -143,6 +150,7 @@ export async function run(): Promise<void> {
143150
setupStr,
144151
analyzeStr,
145152
eslintStr,
153+
litAnalyzerStr,
146154
codeFormattingStr,
147155
testingStr,
148156
);
@@ -152,45 +160,3 @@ export async function run(): Promise<void> {
152160
if (error instanceof Error) setFailed(error.message);
153161
}
154162
}
155-
156-
const eslint = async (command: Command): Promise<stepResponse> => {
157-
let response: stepResponse = { output: "", error: false };
158-
let outputStr = "";
159-
let error = false;
160-
try {
161-
await exec(command.command, [], {
162-
listeners: {
163-
stdout: (data) => {
164-
outputStr += data.toString();
165-
},
166-
},
167-
});
168-
} catch (error) {
169-
error = true;
170-
setFailed(`Failed ${command.label}: ${error}`);
171-
}
172-
173-
const lines = outputStr.split("\n");
174-
const table = lines
175-
.map((line) => {
176-
const match = line.match(/^(.*?):(\d+):(\d+): (.*)$/);
177-
if (match) {
178-
const [_, file, line, column, message] = match;
179-
return `<tr><td>${file}</td><td>${line}</td><td>${column}</td><td>${message}</td></tr>`;
180-
}
181-
return "";
182-
})
183-
.join("");
184-
185-
const problemCount = lines.filter((line) =>
186-
line.match(/^(.*?):(\d+):(\d+): (.*)$/),
187-
).length;
188-
189-
if (problemCount > 0) {
190-
response.error = true;
191-
response.output = `<li>${failedEmoji} - ${command.label}: ${problemCount} problem${problemCount !== 1 ? "s" : ""} found\n<details><summary>See Details</summary><table><tr><th>File</th><th>Line</th><th>Column</th><th>Message</th></tr>${table}</table></details></li>`;
192-
} else {
193-
response.output = `<li>${passedEmoji} - ${command.label}\n</li>`;
194-
}
195-
return response;
196-
};

src/scripts/analyze.ts

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,100 @@
11
import { setFailed } from "@actions/core";
22
import { exec } from "@actions/exec";
3-
import { stepResponse, buildComment, Command, passedEmoji } from "src/main";
3+
import {
4+
stepResponse,
5+
buildComment,
6+
Command,
7+
passedEmoji,
8+
failedEmoji,
9+
} from "src/main";
10+
11+
export const eslint = async (command: Command): Promise<stepResponse> => {
12+
let response: stepResponse = { output: "", error: false };
13+
let outputStr = "";
14+
try {
15+
await exec(command.command, [], {
16+
listeners: {
17+
stdout: (data) => {
18+
outputStr += data.toString();
19+
},
20+
},
21+
});
22+
} catch (error) {
23+
setFailed(`Failed ${command.label}: ${error}`);
24+
}
25+
26+
const lines = outputStr.split("\n");
27+
const table = lines
28+
.map((line) => {
29+
const match = line.match(/^(.*?):(\d+):(\d+): (.*)$/);
30+
if (match) {
31+
const [_, file, line, column, message] = match;
32+
return `<tr><td>${file}</td><td>${line}</td><td>${column}</td><td>${message}</td></tr>`;
33+
}
34+
return "";
35+
})
36+
.join("");
37+
38+
const problemCount = lines.filter((line) =>
39+
line.match(/^(.*?):(\d+):(\d+): (.*)$/),
40+
).length;
41+
42+
if (problemCount > 0) {
43+
response.error = true;
44+
response.output = `${failedEmoji} - ${command.label}: ${problemCount} problem${problemCount !== 1 ? "s" : ""} found\n<details><summary>See Details</summary><table><tr><th>File</th><th>Line</th><th>Column</th><th>Message</th></tr>${table}</table></details>`;
45+
} else {
46+
response.output = `${passedEmoji} - ${command.label}\n`;
47+
}
48+
return response;
49+
};
50+
51+
// const customElementsManifestAnalyzer = async (
52+
// command: Command,
53+
// ): Promise<stepResponse> => {};
54+
55+
export const litAnalyzer = async (command: Command): Promise<stepResponse> => {
56+
let response: stepResponse = { output: "", error: false };
57+
let outputStr = "";
58+
try {
59+
await exec(command.command, [], {
60+
listeners: {
61+
stdout: (data) => {
62+
outputStr += data.toString();
63+
},
64+
},
65+
});
66+
} catch (error) {
67+
setFailed(`Failed ${command.label}: ${error}`);
68+
}
69+
70+
const lines = outputStr.split("\n");
71+
const table = lines
72+
.map((line) => {
73+
const match = line.match(/^\s*(\S+)\s+(\d+):\s+(.*)$/);
74+
if (match) {
75+
const [_, file, line, message] = match;
76+
return `<tr><td>${file}</td><td>${line}</td><td>${message}</td></tr>`;
77+
}
78+
return "";
79+
})
80+
.join("");
81+
82+
const problemCount = lines.filter((line) =>
83+
line.match(/^\s*(\S+)\s+(\d+):\s+(.*)$/),
84+
).length;
85+
86+
if (problemCount > 0) {
87+
response.error = true;
88+
response.output = `${failedEmoji} - ${command.label}: ${problemCount} problem${problemCount !== 1 ? "s" : ""} found\n<details><summary>See Details</summary><table><tr><th>File</th><th>Line</th><th>Message</th></tr>${table}</table></details>`;
89+
} else {
90+
response.output = `${passedEmoji} - ${command.label}\n`;
91+
}
92+
return response;
93+
};
494

595
export const analyze = async (): Promise<stepResponse> => {
696
const commands = [
797
{ label: "Custom Elements Manifest Analyzer", command: "npm run analyze" },
8-
{ label: "Lit Analyzer", command: "npm run lint:lit-analyzer" },
998
];
1099

11100
const [commentBody, errorMessages] = await buildComment(commands);

src/scripts/comment.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ export const comment = async (
99
setupStr: stepResponse | undefined,
1010
analyzeStr: stepResponse | undefined,
1111
eslintStr: stepResponse | undefined,
12+
litAnalyzerStr: stepResponse | undefined,
1213
codeFormattingStr: stepResponse | undefined,
1314
testingStr: stepResponse | undefined,
1415
): Promise<stepResponse> => {
1516
try {
1617
const commentBody = `
17-
## PR Checks Complete\n
18-
<ul>
19-
${setupStr?.output}
20-
${analyzeStr?.output}
21-
${eslintStr?.output}
22-
${codeFormattingStr?.output}
23-
${testingStr?.output}
24-
</ul>`;
18+
## PR Checks Complete\n
19+
<ul>
20+
<li>${setupStr?.output}</li>
21+
<li>${analyzeStr?.output}</li>
22+
<li>${eslintStr?.output}</li>
23+
<li>${litAnalyzerStr?.output}</li>
24+
<li>${codeFormattingStr?.output}</li>
25+
<li>${testingStr?.output}</li>
26+
</ul>`;
2527
// ## Coverage = ${coverageStr?.output}\n`
2628

2729
const { data: comments } = await ocotokit.rest.issues.listComments({

0 commit comments

Comments
 (0)