Skip to content

Commit

Permalink
Create lit analyzer specific comment table
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Dec 18, 2024
1 parent 58aefb4 commit 31b9b97
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 89 deletions.
110 changes: 78 additions & 32 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

58 changes: 12 additions & 46 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getBooleanInput, getInput, setFailed, debug } from "@actions/core";
import { exec } from "@actions/exec";
import { getOctokit, context } from "@actions/github";
import { analyze } from "./scripts/analyze";
import { analyze, eslint, litAnalyzer } from "./scripts/analyze";
import { formatting } from "./scripts/formatting";
import { testing } from "./scripts/testing";
import { comment } from "./scripts/comment";
Expand All @@ -24,11 +24,11 @@ export const buildComment = async (
for (const { label, command } of commands) {
const result = await runCommand(command, label);
if (result) {
commentBody += `<li>${failedEmoji} - ${label}
<details><summary>See details</summary>${result}</details></li>`;
commentBody += `${failedEmoji} - ${label}
<details><summary>See details</summary>${result}</details>`;
errorMessages += `${result}`;
} else {
commentBody += `<li>${passedEmoji} - ${label}\n</li>`;
commentBody += `${passedEmoji} - ${label}\n`;
}
}
return [commentBody, errorMessages];
Expand Down Expand Up @@ -120,6 +120,13 @@ export async function run(): Promise<void> {
? await eslint({ label: "ESLint", command: "npm run lint" })
: undefined;

const litAnalyzerStr: stepResponse | undefined = doStaticAnalysis
? await litAnalyzer({
label: "Lit Analyzer",
command: "npm run lint:lit-analyzer",
})
: undefined;

// run Code Formatting
const codeFormattingStr: stepResponse | undefined = doCodeFormatting
? await formatting()
Expand All @@ -143,6 +150,7 @@ export async function run(): Promise<void> {
setupStr,
analyzeStr,
eslintStr,
litAnalyzerStr,
codeFormattingStr,
testingStr,
);
Expand All @@ -152,45 +160,3 @@ export async function run(): Promise<void> {
if (error instanceof Error) setFailed(error.message);
}
}

const eslint = async (command: Command): Promise<stepResponse> => {
let response: stepResponse = { output: "", error: false };
let outputStr = "";
let error = false;
try {
await exec(command.command, [], {
listeners: {
stdout: (data) => {
outputStr += data.toString();
},
},
});
} catch (error) {
error = true;
setFailed(`Failed ${command.label}: ${error}`);
}

const lines = outputStr.split("\n");
const table = lines
.map((line) => {
const match = line.match(/^(.*?):(\d+):(\d+): (.*)$/);
if (match) {
const [_, file, line, column, message] = match;
return `<tr><td>${file}</td><td>${line}</td><td>${column}</td><td>${message}</td></tr>`;
}
return "";
})
.join("");

const problemCount = lines.filter((line) =>
line.match(/^(.*?):(\d+):(\d+): (.*)$/),
).length;

if (problemCount > 0) {
response.error = true;
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>`;
} else {
response.output = `<li>${passedEmoji} - ${command.label}\n</li>`;
}
return response;
};
93 changes: 91 additions & 2 deletions src/scripts/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,100 @@
import { setFailed } from "@actions/core";
import { exec } from "@actions/exec";
import { stepResponse, buildComment, Command, passedEmoji } from "src/main";
import {
stepResponse,
buildComment,
Command,
passedEmoji,
failedEmoji,
} from "src/main";

export const eslint = async (command: Command): Promise<stepResponse> => {
let response: stepResponse = { output: "", error: false };

Check failure on line 12 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

'response' is never reassigned. Use 'const' instead
let outputStr = "";
try {
await exec(command.command, [], {
listeners: {
stdout: (data) => {
outputStr += data.toString();
},
},
});
} catch (error) {
setFailed(`Failed ${command.label}: ${error}`);

Check failure on line 23 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

Invalid type "unknown" of template literal expression
}

const lines = outputStr.split("\n");
const table = lines
.map((line) => {
const match = line.match(/^(.*?):(\d+):(\d+): (.*)$/);
if (match) {
const [_, file, line, column, message] = match;

Check failure on line 31 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

'_' is assigned a value but never used
return `<tr><td>${file}</td><td>${line}</td><td>${column}</td><td>${message}</td></tr>`;
}
return "";
})
.join("");

const problemCount = lines.filter((line) =>
line.match(/^(.*?):(\d+):(\d+): (.*)$/),
).length;

if (problemCount > 0) {
response.error = true;
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>`;
} else {
response.output = `${passedEmoji} - ${command.label}\n`;
}
return response;
};

// const customElementsManifestAnalyzer = async (
// command: Command,
// ): Promise<stepResponse> => {};

export const litAnalyzer = async (command: Command): Promise<stepResponse> => {
let response: stepResponse = { output: "", error: false };

Check failure on line 56 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

'response' is never reassigned. Use 'const' instead
let outputStr = "";
try {
await exec(command.command, [], {
listeners: {
stdout: (data) => {
outputStr += data.toString();
},
},
});
} catch (error) {
setFailed(`Failed ${command.label}: ${error}`);

Check failure on line 67 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

Invalid type "unknown" of template literal expression
}

const lines = outputStr.split("\n");
const table = lines
.map((line) => {
const match = line.match(/^\s*(\S+)\s+(\d+):\s+(.*)$/);
if (match) {
const [_, file, line, message] = match;

Check failure on line 75 in src/scripts/analyze.ts

View workflow job for this annotation

GitHub Actions / code-quality

'_' is assigned a value but never used
return `<tr><td>${file}</td><td>${line}</td><td>${message}</td></tr>`;
}
return "";
})
.join("");

const problemCount = lines.filter((line) =>
line.match(/^\s*(\S+)\s+(\d+):\s+(.*)$/),
).length;

if (problemCount > 0) {
response.error = true;
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>`;
} else {
response.output = `${passedEmoji} - ${command.label}\n`;
}
return response;
};

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

const [commentBody, errorMessages] = await buildComment(commands);
Expand Down
18 changes: 10 additions & 8 deletions src/scripts/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ export const comment = async (
setupStr: stepResponse | undefined,
analyzeStr: stepResponse | undefined,
eslintStr: stepResponse | undefined,
litAnalyzerStr: stepResponse | undefined,
codeFormattingStr: stepResponse | undefined,
testingStr: stepResponse | undefined,
): Promise<stepResponse> => {
try {
const commentBody = `
## PR Checks Complete\n
<ul>
${setupStr?.output}
${analyzeStr?.output}
${eslintStr?.output}
${codeFormattingStr?.output}
${testingStr?.output}
</ul>`;
## PR Checks Complete\n
<ul>
<li>${setupStr?.output}</li>
<li>${analyzeStr?.output}</li>
<li>${eslintStr?.output}</li>
<li>${litAnalyzerStr?.output}</li>
<li>${codeFormattingStr?.output}</li>
<li>${testingStr?.output}</li>
</ul>`;
// ## Coverage = ${coverageStr?.output}\n`

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

0 comments on commit 31b9b97

Please sign in to comment.