Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add -A
git commit -m 'ci(automated commit): lint format and import sort'
git commit -m 'ci(automated commit): Build bundled file'
git push
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ migrate_working_dir/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
**/.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
build/



**/docs/addver
**/docs/addver
*/package_config_subset
tests/pass_repo/.dart_tool/package_config_subset
tests/pass_repo/.dart_tool/package_config.json
tests/pass_repo/build/test_cache/build/cache.dill.track.dill
47 changes: 23 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30776,8 +30776,7 @@ const getTest = async () => {
const obj = JSON.parse(objStr);
let failIds = [];
obj.forEach((element) => {
if (element.type == "testDone" &&
element.result.toLowerCase() == "error") {
if (element.type == "testDone" && element.result.toLowerCase() == "error") {
failIds.push(element.testID);
}
});
Expand All @@ -30791,18 +30790,14 @@ const getTest = async () => {
const errorString = [];
failIds.forEach((e1) => {
const allEntries = obj.filter((e) => (e.hasOwnProperty("testID") && e.testID == e1) ||
(e.hasOwnProperty("test") &&
e.test.hasOwnProperty("id") &&
e.test.id == e1));
(e.hasOwnProperty("test") && e.test.hasOwnProperty("id") && e.test.id == e1));
const entry1 = allEntries.find((e) => e.hasOwnProperty("test") && e.test.hasOwnProperty("id"));
let testName = "Error getting test name";
if (entry1) {
testName = entry1.test.name.split("/test/").slice(-1);
}
const entry2 = allEntries.find((e) => e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1);
const entry3 = allEntries.find((e) => e.hasOwnProperty("message") &&
e.message.length > 1 &&
e.message.includes("EXCEPTION CAUGHT BY FLUTTER"));
const entry3 = allEntries.find((e) => e.hasOwnProperty("message") && e.message.length > 1 && e.message.includes("EXCEPTION CAUGHT BY FLUTTER"));
const entry4 = allEntries.find((e) => e.hasOwnProperty("error") && e.error.length > 1);
let testDetails = "Unable to get test details. Run flutter test to replicate";
if (entry2) {
Expand All @@ -30814,11 +30809,7 @@ const getTest = async () => {
else if (entry4) {
testDetails = entry4.error;
}
errorString.push("<details><summary>" +
testName +
"</br></summary>`" +
testDetails +
"`</details>");
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
});
const output = `⛔️ - ${initialString}</br >
<details><summary>See details</summary>
Expand Down Expand Up @@ -33152,17 +33143,25 @@ const setup_1 = __nccwpck_require__(9346);
const behind_1 = __nccwpck_require__(8890);
const push_1 = __nccwpck_require__(3662);
const run = async () => {
const token = process.env.GITHUB_TOKEN || (0, core_1.getInput)("token");
const octokit = (0, github_1.getOctokit)(token);
const behindByStr = await (0, behind_1.checkBranchStatus)(octokit, github_1.context);
await (0, setup_1.setup)();
const oldCoverage = (0, coverage_1.getOldCoverage)();
const analyzeStr = await (0, analyze_1.getAnalyze)();
const testStr = await (0, runTests_1.getTest)();
const coverageStr = await (0, coverage_1.getCoverage)(oldCoverage);
const comment = (0, comment_1.createComment)(analyzeStr, testStr, coverageStr, behindByStr);
(0, comment_1.postComment)(octokit, comment, github_1.context);
await (0, push_1.push)();
try {
const token = process.env.GITHUB_TOKEN || (0, core_1.getInput)("token");
const octokit = (0, github_1.getOctokit)(token);
const behindByStr = await (0, behind_1.checkBranchStatus)(octokit, github_1.context);
await (0, setup_1.setup)();
const oldCoverage = (0, coverage_1.getOldCoverage)();
const analyzeStr = await (0, analyze_1.getAnalyze)();
const testStr = await (0, runTests_1.getTest)();
const coverageStr = await (0, coverage_1.getCoverage)(oldCoverage);
const comment = (0, comment_1.createComment)(analyzeStr, testStr, coverageStr, behindByStr);
(0, comment_1.postComment)(octokit, comment, github_1.context);
await (0, push_1.push)();
if (analyzeStr.error || testStr.error || coverageStr.error) {
(0, core_1.setFailed)(`${analyzeStr.output}\n${testStr.output}\n${coverageStr.output}`);
}
}
catch (err) {
(0, core_1.setFailed)(`Action failed with error ${err}`);
}
};
run();

Expand Down
35 changes: 23 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInput } from "@actions/core";
import { getInput, setFailed } from "@actions/core";
import { getAnalyze } from "./scripts/analyze";
import { getOctokit, context } from "@actions/github";
import { getCoverage, getOldCoverage } from "./scripts/coverage";
Expand All @@ -11,17 +11,28 @@ import { push } from "./scripts/push";
export type stepResponse = { output: string; error: boolean };

const run = async () => {
const token = process.env.GITHUB_TOKEN || getInput("token");
const octokit = getOctokit(token);
const behindByStr = await checkBranchStatus(octokit, context);
await setup();
const oldCoverage: number | undefined = getOldCoverage();
const analyzeStr: stepResponse = await getAnalyze();
const testStr: stepResponse = await getTest();
const coverageStr: stepResponse = await getCoverage(oldCoverage);
const comment = createComment(analyzeStr, testStr, coverageStr, behindByStr);
postComment(octokit, comment, context);
await push();
try {
const token = process.env.GITHUB_TOKEN || getInput("token");
const octokit = getOctokit(token);
const behindByStr = await checkBranchStatus(octokit, context);
await setup();
const oldCoverage: number | undefined = getOldCoverage();

const analyzeStr: stepResponse = await getAnalyze();
const testStr: stepResponse = await getTest();
const coverageStr: stepResponse = await getCoverage(oldCoverage);

const comment = createComment(analyzeStr, testStr, coverageStr, behindByStr);

postComment(octokit, comment, context);
await push();

if (analyzeStr.error || testStr.error || coverageStr.error) {
setFailed(`${analyzeStr.output}\n${testStr.output}\n${coverageStr.output}`);
}
} catch (err) {
setFailed(`Action failed with error ${err}`);
}
};

run();
10 changes: 4 additions & 6 deletions src/scripts/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const getAnalyze = async (): Promise<stepResponse> => {
const output = `${ANALYZE_FAILURE}; ${issuesFound}</br>
<details><summary>See details</summary>
<table>
<tr><th></th><th>Type</th><th>File name</th><th>Details</th></tr>${errorString.join(
""
)}${warningString.join("")}${infoString.join("")}</table></details>
<tr><th></th><th>Type</th><th>File name</th><th>Details</th></tr>${errorString.join("")}${warningString.join(
""
)}${infoString.join("")}</table></details>
`;

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

export const generateTableRow = (err: analyzeDetails, type: analyzeErrTypes) =>
`<tr><td>${getErrEmoji(type)}</td><td>Error</td><td>${err.file}</td><td>${
err.details
}</td></tr>`;
`<tr><td>${getErrEmoji(type)}</td><td>Error</td><td>${err.file}</td><td>${err.details}</td></tr>`;
9 changes: 2 additions & 7 deletions src/scripts/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const createComment = (
coverage: stepResponse,
behindBy: stepResponse
): string => {
const isSuccess =
!analyze.error && !test.error && !coverage.error && !behindBy.error;
const isSuccess = !analyze.error && !test.error && !coverage.error && !behindBy.error;

let output = `<h2>PR Checks complete</h2>
<ul>
Expand All @@ -29,11 +28,7 @@ ${SIGNATURE}
return output;
};

export async function postComment(
octokit: InstanceType<typeof GitHub>,
commentMessage: string,
context: Context
) {
export async function postComment(octokit: InstanceType<typeof GitHub>, commentMessage: string, context: Context) {
startGroup(`Commenting on PR`);

const pr = {
Expand Down
55 changes: 15 additions & 40 deletions src/scripts/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ export const getTest = async (): Promise<stepResponse> => {
const objStr = "[" + stdout.split("\n").join(",").slice(0, -1) + "]";
const obj = JSON.parse(objStr);
let failIds: string[] = [];
obj.forEach(
(element: { type: string; result: string; testID: string }) => {
if (
element.type == "testDone" &&
element.result.toLowerCase() == "error"
) {
failIds.push(element.testID);
}
obj.forEach((element: { type: string; result: string; testID: string }) => {
if (element.type == "testDone" && element.result.toLowerCase() == "error") {
failIds.push(element.testID);
}
);
});
let initialString = "";
if (failIds.length > 1) {
initialString = `${failIds.length} tests failed`;
Expand All @@ -50,43 +45,29 @@ export const getTest = async (): Promise<stepResponse> => {
test: { hasOwnProperty: (arg0: string) => any; id: any };
}) =>
(e.hasOwnProperty("testID") && e.testID == e1) ||
(e.hasOwnProperty("test") &&
e.test.hasOwnProperty("id") &&
e.test.id == e1)
(e.hasOwnProperty("test") && e.test.hasOwnProperty("id") && e.test.id == e1)
);
const entry1 = allEntries.find(
(e: {
hasOwnProperty: (arg0: string) => any;
test: { hasOwnProperty: (arg0: string) => any };
}) => e.hasOwnProperty("test") && e.test.hasOwnProperty("id")
(e: { hasOwnProperty: (arg0: string) => any; test: { hasOwnProperty: (arg0: string) => any } }) =>
e.hasOwnProperty("test") && e.test.hasOwnProperty("id")
);
let testName = "Error getting test name";
if (entry1) {
testName = entry1.test.name.split("/test/").slice(-1);
}
const entry2 = allEntries.find(
(e: {
hasOwnProperty: (arg0: string) => any;
stackTrace: string | any[];
}) => e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1
(e: { hasOwnProperty: (arg0: string) => any; stackTrace: string | any[] }) =>
e.hasOwnProperty("stackTrace") && e.stackTrace.length > 1
);
const entry3 = allEntries.find(
(e: {
hasOwnProperty: (arg0: string) => any;
message: string | string[];
}) =>
e.hasOwnProperty("message") &&
e.message.length > 1 &&
e.message.includes("EXCEPTION CAUGHT BY FLUTTER")
(e: { hasOwnProperty: (arg0: string) => any; message: string | string[] }) =>
e.hasOwnProperty("message") && e.message.length > 1 && e.message.includes("EXCEPTION CAUGHT BY FLUTTER")
);
const entry4 = allEntries.find(
(e: {
hasOwnProperty: (arg0: string) => any;
error: string | any[];
}) => e.hasOwnProperty("error") && e.error.length > 1
(e: { hasOwnProperty: (arg0: string) => any; error: string | any[] }) =>
e.hasOwnProperty("error") && e.error.length > 1
);
let testDetails =
"Unable to get test details. Run flutter test to replicate";
let testDetails = "Unable to get test details. Run flutter test to replicate";
if (entry2) {
testDetails = entry2.stackTrace;
} else if (entry3) {
Expand All @@ -95,13 +76,7 @@ export const getTest = async (): Promise<stepResponse> => {
testDetails = entry4.error;
}

errorString.push(
"<details><summary>" +
testName +
"</br></summary>`" +
testDetails +
"`</details>"
);
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
});

const output = `⛔️ - ${initialString}</br >
Expand Down
6 changes: 1 addition & 5 deletions tests/src/scripts/coverage.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { exec, execSync } from "child_process";
import { stepResponse } from "../../../src/main";
import {
COV_FAILURE,
getCoverage,
getOldCoverage,
} from "../../../src/scripts/coverage";
import { COV_FAILURE, getCoverage, getOldCoverage } from "../../../src/scripts/coverage";
const oldCoverage = 83.33;

test("should return stepResponse object", () => {
Expand Down
6 changes: 1 addition & 5 deletions tests/src/scripts/runTests.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getTest,
TEST_ERROR,
TEST_SUCCESS,
} from "../../../src/scripts/runTests";
import { getTest, TEST_ERROR, TEST_SUCCESS } from "../../../src/scripts/runTests";

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