Skip to content

Commit a2a68cd

Browse files
committed
fix: Add basic error reporting (#8)
refactor: Set line length to 120
1 parent 80285f5 commit a2a68cd

File tree

9 files changed

+76
-105
lines changed

9 files changed

+76
-105
lines changed

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
git config --global user.name "github-actions"
3838
git config --global user.email "[email protected]"
3939
git add -A
40-
git commit -m 'ci(automated commit): lint format and import sort'
40+
git commit -m 'ci(automated commit): Build bundled file'
4141
git push

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ migrate_working_dir/
156156
# Flutter/Dart/Pub related
157157
**/doc/api/
158158
**/ios/Flutter/.last_build_id
159-
.dart_tool/
159+
**/.dart_tool/
160160
.flutter-plugins
161161
.flutter-plugins-dependencies
162162
.pub-cache/
163163
.pub/
164164
build/
165-
166-
167-
168-
**/docs/addver
165+
**/docs/addver
166+
*/package_config_subset
167+
tests/pass_repo/.dart_tool/package_config_subset
168+
tests/pass_repo/.dart_tool/package_config.json
169+
tests/pass_repo/build/test_cache/build/cache.dill.track.dill

dist/index.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30776,8 +30776,7 @@ const getTest = async () => {
3077630776
const obj = JSON.parse(objStr);
3077730777
let failIds = [];
3077830778
obj.forEach((element) => {
30779-
if (element.type == "testDone" &&
30780-
element.result.toLowerCase() == "error") {
30779+
if (element.type == "testDone" && element.result.toLowerCase() == "error") {
3078130780
failIds.push(element.testID);
3078230781
}
3078330782
});
@@ -30791,18 +30790,14 @@ const getTest = async () => {
3079130790
const errorString = [];
3079230791
failIds.forEach((e1) => {
3079330792
const allEntries = obj.filter((e) => (e.hasOwnProperty("testID") && e.testID == e1) ||
30794-
(e.hasOwnProperty("test") &&
30795-
e.test.hasOwnProperty("id") &&
30796-
e.test.id == e1));
30793+
(e.hasOwnProperty("test") && e.test.hasOwnProperty("id") && e.test.id == e1));
3079730794
const entry1 = allEntries.find((e) => e.hasOwnProperty("test") && e.test.hasOwnProperty("id"));
3079830795
let testName = "Error getting test name";
3079930796
if (entry1) {
3080030797
testName = entry1.test.name.split("/test/").slice(-1);
3080130798
}
3080230799
const entry2 = allEntries.find((e) => e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1);
30803-
const entry3 = allEntries.find((e) => e.hasOwnProperty("message") &&
30804-
e.message.length > 1 &&
30805-
e.message.includes("EXCEPTION CAUGHT BY FLUTTER"));
30800+
const entry3 = allEntries.find((e) => e.hasOwnProperty("message") && e.message.length > 1 && e.message.includes("EXCEPTION CAUGHT BY FLUTTER"));
3080630801
const entry4 = allEntries.find((e) => e.hasOwnProperty("error") && e.error.length > 1);
3080730802
let testDetails = "Unable to get test details. Run flutter test to replicate";
3080830803
if (entry2) {
@@ -30814,11 +30809,7 @@ const getTest = async () => {
3081430809
else if (entry4) {
3081530810
testDetails = entry4.error;
3081630811
}
30817-
errorString.push("<details><summary>" +
30818-
testName +
30819-
"</br></summary>`" +
30820-
testDetails +
30821-
"`</details>");
30812+
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
3082230813
});
3082330814
const output = `⛔️ - ${initialString}</br >
3082430815
<details><summary>See details</summary>
@@ -33152,17 +33143,25 @@ const setup_1 = __nccwpck_require__(9346);
3315233143
const behind_1 = __nccwpck_require__(8890);
3315333144
const push_1 = __nccwpck_require__(3662);
3315433145
const run = async () => {
33155-
const token = process.env.GITHUB_TOKEN || (0, core_1.getInput)("token");
33156-
const octokit = (0, github_1.getOctokit)(token);
33157-
const behindByStr = await (0, behind_1.checkBranchStatus)(octokit, github_1.context);
33158-
await (0, setup_1.setup)();
33159-
const oldCoverage = (0, coverage_1.getOldCoverage)();
33160-
const analyzeStr = await (0, analyze_1.getAnalyze)();
33161-
const testStr = await (0, runTests_1.getTest)();
33162-
const coverageStr = await (0, coverage_1.getCoverage)(oldCoverage);
33163-
const comment = (0, comment_1.createComment)(analyzeStr, testStr, coverageStr, behindByStr);
33164-
(0, comment_1.postComment)(octokit, comment, github_1.context);
33165-
await (0, push_1.push)();
33146+
try {
33147+
const token = process.env.GITHUB_TOKEN || (0, core_1.getInput)("token");
33148+
const octokit = (0, github_1.getOctokit)(token);
33149+
const behindByStr = await (0, behind_1.checkBranchStatus)(octokit, github_1.context);
33150+
await (0, setup_1.setup)();
33151+
const oldCoverage = (0, coverage_1.getOldCoverage)();
33152+
const analyzeStr = await (0, analyze_1.getAnalyze)();
33153+
const testStr = await (0, runTests_1.getTest)();
33154+
const coverageStr = await (0, coverage_1.getCoverage)(oldCoverage);
33155+
const comment = (0, comment_1.createComment)(analyzeStr, testStr, coverageStr, behindByStr);
33156+
(0, comment_1.postComment)(octokit, comment, github_1.context);
33157+
await (0, push_1.push)();
33158+
if (analyzeStr.error || testStr.error || coverageStr.error) {
33159+
(0, core_1.setFailed)(`${analyzeStr.output}\n${testStr.output}\n${coverageStr.output}`);
33160+
}
33161+
}
33162+
catch (err) {
33163+
(0, core_1.setFailed)(`Action failed with error ${err}`);
33164+
}
3316633165
};
3316733166
run();
3316833167

src/main.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInput } from "@actions/core";
1+
import { getInput, setFailed } from "@actions/core";
22
import { getAnalyze } from "./scripts/analyze";
33
import { getOctokit, context } from "@actions/github";
44
import { getCoverage, getOldCoverage } from "./scripts/coverage";
@@ -11,17 +11,28 @@ import { push } from "./scripts/push";
1111
export type stepResponse = { output: string; error: boolean };
1212

1313
const run = async () => {
14-
const token = process.env.GITHUB_TOKEN || getInput("token");
15-
const octokit = getOctokit(token);
16-
const behindByStr = await checkBranchStatus(octokit, context);
17-
await setup();
18-
const oldCoverage: number | undefined = getOldCoverage();
19-
const analyzeStr: stepResponse = await getAnalyze();
20-
const testStr: stepResponse = await getTest();
21-
const coverageStr: stepResponse = await getCoverage(oldCoverage);
22-
const comment = createComment(analyzeStr, testStr, coverageStr, behindByStr);
23-
postComment(octokit, comment, context);
24-
await push();
14+
try {
15+
const token = process.env.GITHUB_TOKEN || getInput("token");
16+
const octokit = getOctokit(token);
17+
const behindByStr = await checkBranchStatus(octokit, context);
18+
await setup();
19+
const oldCoverage: number | undefined = getOldCoverage();
20+
21+
const analyzeStr: stepResponse = await getAnalyze();
22+
const testStr: stepResponse = await getTest();
23+
const coverageStr: stepResponse = await getCoverage(oldCoverage);
24+
25+
const comment = createComment(analyzeStr, testStr, coverageStr, behindByStr);
26+
27+
postComment(octokit, comment, context);
28+
await push();
29+
30+
if (analyzeStr.error || testStr.error || coverageStr.error) {
31+
setFailed(`${analyzeStr.output}\n${testStr.output}\n${coverageStr.output}`);
32+
}
33+
} catch (err) {
34+
setFailed(`Action failed with error ${err}`);
35+
}
2536
};
2637

2738
run();

src/scripts/analyze.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export const getAnalyze = async (): Promise<stepResponse> => {
5757
const output = `${ANALYZE_FAILURE}; ${issuesFound}</br>
5858
<details><summary>See details</summary>
5959
<table>
60-
<tr><th></th><th>Type</th><th>File name</th><th>Details</th></tr>${errorString.join(
61-
""
62-
)}${warningString.join("")}${infoString.join("")}</table></details>
60+
<tr><th></th><th>Type</th><th>File name</th><th>Details</th></tr>${errorString.join("")}${warningString.join(
61+
""
62+
)}${infoString.join("")}</table></details>
6363
`;
6464

6565
response = { output: output, error: true };
@@ -84,6 +84,4 @@ export const getErrEmoji = (errType: analyzeErrTypes) => {
8484
};
8585

8686
export const generateTableRow = (err: analyzeDetails, type: analyzeErrTypes) =>
87-
`<tr><td>${getErrEmoji(type)}</td><td>Error</td><td>${err.file}</td><td>${
88-
err.details
89-
}</td></tr>`;
87+
`<tr><td>${getErrEmoji(type)}</td><td>Error</td><td>${err.file}</td><td>${err.details}</td></tr>`;

src/scripts/comment.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ export const createComment = (
1111
coverage: stepResponse,
1212
behindBy: stepResponse
1313
): string => {
14-
const isSuccess =
15-
!analyze.error && !test.error && !coverage.error && !behindBy.error;
14+
const isSuccess = !analyze.error && !test.error && !coverage.error && !behindBy.error;
1615

1716
let output = `<h2>PR Checks complete</h2>
1817
<ul>
@@ -29,11 +28,7 @@ ${SIGNATURE}
2928
return output;
3029
};
3130

32-
export async function postComment(
33-
octokit: InstanceType<typeof GitHub>,
34-
commentMessage: string,
35-
context: Context
36-
) {
31+
export async function postComment(octokit: InstanceType<typeof GitHub>, commentMessage: string, context: Context) {
3732
startGroup(`Commenting on PR`);
3833

3934
const pr = {

src/scripts/runTests.ts

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ export const getTest = async (): Promise<stepResponse> => {
2424
const objStr = "[" + stdout.split("\n").join(",").slice(0, -1) + "]";
2525
const obj = JSON.parse(objStr);
2626
let failIds: string[] = [];
27-
obj.forEach(
28-
(element: { type: string; result: string; testID: string }) => {
29-
if (
30-
element.type == "testDone" &&
31-
element.result.toLowerCase() == "error"
32-
) {
33-
failIds.push(element.testID);
34-
}
27+
obj.forEach((element: { type: string; result: string; testID: string }) => {
28+
if (element.type == "testDone" && element.result.toLowerCase() == "error") {
29+
failIds.push(element.testID);
3530
}
36-
);
31+
});
3732
let initialString = "";
3833
if (failIds.length > 1) {
3934
initialString = `${failIds.length} tests failed`;
@@ -50,43 +45,29 @@ export const getTest = async (): Promise<stepResponse> => {
5045
test: { hasOwnProperty: (arg0: string) => any; id: any };
5146
}) =>
5247
(e.hasOwnProperty("testID") && e.testID == e1) ||
53-
(e.hasOwnProperty("test") &&
54-
e.test.hasOwnProperty("id") &&
55-
e.test.id == e1)
48+
(e.hasOwnProperty("test") && e.test.hasOwnProperty("id") && e.test.id == e1)
5649
);
5750
const entry1 = allEntries.find(
58-
(e: {
59-
hasOwnProperty: (arg0: string) => any;
60-
test: { hasOwnProperty: (arg0: string) => any };
61-
}) => e.hasOwnProperty("test") && e.test.hasOwnProperty("id")
51+
(e: { hasOwnProperty: (arg0: string) => any; test: { hasOwnProperty: (arg0: string) => any } }) =>
52+
e.hasOwnProperty("test") && e.test.hasOwnProperty("id")
6253
);
6354
let testName = "Error getting test name";
6455
if (entry1) {
6556
testName = entry1.test.name.split("/test/").slice(-1);
6657
}
6758
const entry2 = allEntries.find(
68-
(e: {
69-
hasOwnProperty: (arg0: string) => any;
70-
stackTrace: string | any[];
71-
}) => e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1
59+
(e: { hasOwnProperty: (arg0: string) => any; stackTrace: string | any[] }) =>
60+
e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1
7261
);
7362
const entry3 = allEntries.find(
74-
(e: {
75-
hasOwnProperty: (arg0: string) => any;
76-
message: string | string[];
77-
}) =>
78-
e.hasOwnProperty("message") &&
79-
e.message.length > 1 &&
80-
e.message.includes("EXCEPTION CAUGHT BY FLUTTER")
63+
(e: { hasOwnProperty: (arg0: string) => any; message: string | string[] }) =>
64+
e.hasOwnProperty("message") && e.message.length > 1 && e.message.includes("EXCEPTION CAUGHT BY FLUTTER")
8165
);
8266
const entry4 = allEntries.find(
83-
(e: {
84-
hasOwnProperty: (arg0: string) => any;
85-
error: string | any[];
86-
}) => e.hasOwnProperty("error") && e.error.length > 1
67+
(e: { hasOwnProperty: (arg0: string) => any; error: string | any[] }) =>
68+
e.hasOwnProperty("error") && e.error.length > 1
8769
);
88-
let testDetails =
89-
"Unable to get test details. Run flutter test to replicate";
70+
let testDetails = "Unable to get test details. Run flutter test to replicate";
9071
if (entry2) {
9172
testDetails = entry2.stackTrace;
9273
} else if (entry3) {
@@ -95,13 +76,7 @@ export const getTest = async (): Promise<stepResponse> => {
9576
testDetails = entry4.error;
9677
}
9778

98-
errorString.push(
99-
"<details><summary>" +
100-
testName +
101-
"</br></summary>`" +
102-
testDetails +
103-
"`</details>"
104-
);
79+
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
10580
});
10681

10782
const output = `⛔️ - ${initialString}</br >

tests/src/scripts/coverage.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { exec, execSync } from "child_process";
22
import { stepResponse } from "../../../src/main";
3-
import {
4-
COV_FAILURE,
5-
getCoverage,
6-
getOldCoverage,
7-
} from "../../../src/scripts/coverage";
3+
import { COV_FAILURE, getCoverage, getOldCoverage } from "../../../src/scripts/coverage";
84
const oldCoverage = 83.33;
95

106
test("should return stepResponse object", () => {

tests/src/scripts/runTests.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
getTest,
3-
TEST_ERROR,
4-
TEST_SUCCESS,
5-
} from "../../../src/scripts/runTests";
1+
import { getTest, TEST_ERROR, TEST_SUCCESS } from "../../../src/scripts/runTests";
62

73
test("all tests pass", async () => {
84
process.chdir("tests/pass_repo");

0 commit comments

Comments
 (0)