Skip to content

Commit dc1834d

Browse files
committed
update .gitignore, enhance VSCode launch configuration, and refactor error handling in main.ts and testing.ts
1 parent 3cad312 commit dc1834d

File tree

7 files changed

+94
-70
lines changed

7 files changed

+94
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ __tests__/runner/*
104104
# TS Docs
105105
docs
106106

107+
# VSCode
107108
.vscode

.vscode/launch.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
"request": "launch",
88
"runtimeExecutable": "npx",
99
"cwd": "${workspaceRoot}",
10-
"args": ["local-action", ".", "src/main.ts", ".env"],
10+
"args": ["local-action", ".", "src/main.ts", ".env", "-- --local"],
1111
"console": "integratedTerminal",
1212
"skipFiles": ["<node_internals>/**", "node_modules/**"],
1313
"env": {
1414
"NODE_OPTIONS": "--experimental-specifier-resolution=node"
15-
}
15+
},
16+
"preLaunchTask": "npm: install"
1617
}
1718
]
1819
}

dist/index.js

Lines changed: 44 additions & 33 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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getBooleanInput, getInput, setFailed } from "@actions/core";
1+
import { getBooleanInput, getInput, setFailed, debug } from "@actions/core";
22
import { exec } from "@actions/exec";
33
import { getOctokit, context } from "@actions/github";
44
import { analyze } from "./scripts/analyze";
@@ -13,6 +13,26 @@ export type stepResponse = { output: string; error: boolean };
1313
export const failedEmoji = "❌";
1414
export const passedEmoji = "✅";
1515

16+
export const runCommand = async (
17+
command: string,
18+
label: string,
19+
): Promise<string | boolean> => {
20+
try {
21+
await exec(command);
22+
return false;
23+
} catch (error: unknown) {
24+
if (error instanceof Error) {
25+
debug(`${label} failed: ${error.message}`);
26+
return error.message;
27+
} else if (typeof error === "string") {
28+
debug(`${label} failed: ${error}`);
29+
return error;
30+
} else {
31+
return true;
32+
}
33+
}
34+
};
35+
1636
/**
1737
* The main function for the action.
1838
* @returns {Promise<void>} Resolves when the action is complete.

src/scripts/analyze.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
import { exec } from "@actions/exec";
2-
import { setFailed, debug } from "@actions/core";
3-
import { stepResponse, failedEmoji, passedEmoji } from "src/main";
4-
5-
const runCommand = async (
6-
command: string,
7-
label: string,
8-
): Promise<string | boolean> => {
9-
try {
10-
await exec(command);
11-
return false;
12-
} catch (error: unknown) {
13-
if (error instanceof Error) {
14-
debug(`${label} failed: ${error.message}`);
15-
return error.message;
16-
} else if (typeof error === "string") {
17-
debug(`${label} failed: ${error}`);
18-
return error;
19-
} else {
20-
return true;
21-
}
22-
}
23-
};
1+
import { setFailed } from "@actions/core";
2+
import { stepResponse, failedEmoji, passedEmoji, runCommand } from "src/main";
243

254
export const analyze = async (): Promise<stepResponse> => {
265
const results = [

src/scripts/testing.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
import { exec } from "@actions/exec";
22
import { setFailed } from "@actions/core";
3-
import { stepResponse } from "src/main";
3+
import { stepResponse, failedEmoji, passedEmoji, runCommand } from "src/main";
44

55
export const testing = async (): Promise<stepResponse> => {
6-
try {
7-
// Run tests and generate coverage
8-
await exec("npm run test -- --coverage");
6+
const results = [
7+
{ label: "Testing", command: "npm run test -- --coverage" },
8+
{ label: "TSDoc", command: "npm run docs" },
9+
];
910

10-
// Test tsdoc
11-
await exec("npm run docs");
11+
let commentBody = "\n";
12+
let errorMessages = "";
1213

13-
return { output: "Testing complete", error: false };
14-
} catch (error) {
15-
if (error instanceof Error) setFailed(error.message);
16-
return { output: "Testing failed", error: true };
14+
for (const { label, command } of results) {
15+
const result = await runCommand(command, label);
16+
if (result) {
17+
commentBody += `${failedEmoji} - ${label}\n`;
18+
errorMessages += `${result}\n`;
19+
} else {
20+
commentBody += `${passedEmoji} - ${label}\n`;
21+
}
22+
}
23+
24+
if (errorMessages) {
25+
setFailed(errorMessages.trim());
26+
return { output: commentBody.trim(), error: true };
27+
} else {
28+
return { output: commentBody.trim(), error: false };
1729
}
1830
};

0 commit comments

Comments
 (0)