Skip to content

Commit 9561e12

Browse files
committed
refactor: remove ci-test script and implement setup function for dependency installation
1 parent 669aa7c commit 9561e12

File tree

7 files changed

+122
-22
lines changed

7 files changed

+122
-22
lines changed

dist/index.js

Lines changed: 64 additions & 11 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.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"setup": "npm i && npm run bundle",
2929
"analyze": "cem analyze",
3030
"bundle": "npm run format:write && npm run package",
31-
"ci-test": "npx jest",
3231
"coverage": "npx make-coverage-badge --output-path ./badges/coverage.svg",
3332
"docs": "npx typedoc --logLevel Warn",
3433
"format:write": "npx prettier --write .",

src/main.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { comment } from "./scripts/comment";
88
import { cwd, chdir } from "process";
99
// import { coverage } from './scripts/coverage'
1010
import minimist from "minimist";
11+
import { setup } from "./scripts/setup";
1112

1213
export type stepResponse = { output: string; error: boolean };
1314
export const failedEmoji = "❌";
@@ -68,12 +69,6 @@ export async function run(): Promise<void> {
6869
const isLocal =
6970
argv._.findLast((x: string) => x == "--local") == "--local" ? true : false;
7071

71-
try {
72-
await exec("npm ci");
73-
} catch (error: unknown) {
74-
if (error instanceof Error) setFailed(error.message);
75-
}
76-
7772
try {
7873
const workingDirectory = getInput("working-directory");
7974
// Check if the working directory is different from the current directory
@@ -106,11 +101,14 @@ export async function run(): Promise<void> {
106101

107102
// const runCoverage: boolean = getBooleanInput('run-coverage');
108103
// const coveragePassScore: string = getInput('coverage-pass-score');
109-
104+
// get comment input
110105
const createComment: boolean = isLocal
111106
? true
112107
: getBooleanInput("create-comment");
113108

109+
// run set up
110+
const setupStr: stepResponse | undefined = await setup();
111+
114112
// run Static Analysis
115113
const analyzeStr: stepResponse | undefined = doStaticAnalysis
116114
? await analyze()
@@ -136,6 +134,7 @@ export async function run(): Promise<void> {
136134
await comment(
137135
octokit,
138136
context,
137+
setupStr,
139138
analyzeStr,
140139
codeFormattingStr,
141140
testingStr,

src/scripts/comment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { stepResponse } from "src/main";
66
export const comment = async (
77
ocotokit: ReturnType<typeof getOctokit>,
88
context: Context,
9+
setupStr: stepResponse | undefined,
910
analyzeStr: stepResponse | undefined,
1011
codeFormattingStr: stepResponse | undefined,
1112
testingStr: stepResponse | undefined,
@@ -14,11 +15,12 @@ export const comment = async (
1415
const commentBody = `
1516
## PR Checks Complete\n
1617
<ul>
18+
${setupStr?.output}
1719
${analyzeStr?.output}
1820
${codeFormattingStr?.output}
1921
${testingStr?.output}
2022
</ul>`;
21-
// ## Coverage = ${coverageStr?.output}\n`
23+
// ## Coverage = ${coverageStr?.output}\n`
2224

2325
const { data: comments } = await ocotokit.rest.issues.listComments({
2426
issue_number: context.issue.number,

src/scripts/setup.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { setFailed } from "@actions/core";
2+
import { stepResponse, buildComment } from "src/main";
3+
4+
export const setup = async (): Promise<stepResponse> => {
5+
const commands = [{ label: "Install Dependencies", command: "npm ci" }];
6+
7+
const [commentBody, errorMessages] = await buildComment(commands);
8+
9+
if (errorMessages) {
10+
setFailed(errorMessages.trim());
11+
return { output: commentBody.trim(), error: true };
12+
} else {
13+
return { output: commentBody.trim(), error: false };
14+
}
15+
};

src/scripts/testing.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
import { setFailed } from "@actions/core";
22
import { stepResponse, buildComment } from "src/main";
3+
import { exec } from "@actions/exec";
34

45
export const testing = async (): Promise<stepResponse> => {
6+
const runCommand = (command: string): Promise<string> => {
7+
return new Promise((resolve, reject) => {
8+
exec(command, [], {
9+
listeners: {
10+
stdout: (data: Buffer) => {
11+
resolve(data.toString());
12+
},
13+
stderr: (data: Buffer) => {
14+
reject(data.toString());
15+
},
16+
},
17+
}).catch((error: any) => {
18+
reject(error);
19+
});
20+
});
21+
};
22+
23+
await runCommand("npm ls @playwright/test | grep @playwright | sed 's/.*@//'")
24+
.then((version) => {
25+
process.env.PLAYWRIGHT_VERSION = version.trim();
26+
})
27+
.catch((error) => {
28+
setFailed(`Failed to get Playwright version: ${error}`);
29+
return { output: "", error: true };
30+
});
31+
532
const commands = [
6-
{ label: "Testing", command: "npm run test -- --coverage" },
33+
// { label: "Testing", command: "npm run test -- --coverage" },
34+
{
35+
label: "Install PlayWright Browsers",
36+
command: "npx playwright install --with-deps",
37+
},
38+
{ label: "Testing", command: "npm run test" },
739
{ label: "TSDoc", command: "npm run docs" },
840
];
941

0 commit comments

Comments
 (0)