Skip to content

Commit b8725b9

Browse files
thelukewaltongithub-actions
andauthored
test (#40)
Co-authored-by: github-actions <github-actions@github.com>
1 parent b06c962 commit b8725b9

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

dist/index.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113287,8 +113287,15 @@ const behind_1 = __nccwpck_require__(98890);
113287113287
const push_1 = __nccwpck_require__(13662);
113288113288
const prevCoverage_1 = __nccwpck_require__(39033);
113289113289
const minimist_1 = __importDefault(__nccwpck_require__(13566));
113290+
const node_child_process_1 = __nccwpck_require__(17718);
113290113291
exports.COVERAGE_DIR = ".coverage";
113291113292
const run = async (isLocal) => {
113293+
try {
113294+
(0, node_child_process_1.execSync)("flutter pub get");
113295+
}
113296+
catch (e) {
113297+
console.error(e);
113298+
}
113292113299
try {
113293113300
const workingDirectory = isLocal ? "." : (0, core_1.getInput)("working-directory");
113294113301
// Check if the working directory is different from the current directory
@@ -113325,9 +113332,10 @@ const run = async (isLocal) => {
113325113332
: undefined;
113326113333
if (createComment)
113327113334
(0, comment_1.postComment)(octokit, comment, github_1.context);
113328-
await (0, push_1.push)(exports.COVERAGE_DIR);
113329-
if (analyzeStr?.error || testStr?.error || coverageStr?.error) {
113330-
(0, core_1.setFailed)(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`);
113335+
await (0, push_1.pushChanges)(exports.COVERAGE_DIR);
113336+
const errors = [analyzeStr, testStr, coverageStr].filter((step) => step?.error);
113337+
if (errors.length > 0) {
113338+
(0, core_1.setFailed)(errors.map((step) => step?.output).join("; "));
113331113339
}
113332113340
}
113333113341
catch (err) {
@@ -113806,15 +113814,15 @@ const generatePreviousCoverage = async (prev_sha, current_branch, coverage_direc
113806113814
"use strict";
113807113815

113808113816
Object.defineProperty(exports, "__esModule", ({ value: true }));
113809-
exports.push = void 0;
113817+
exports.pushChanges = void 0;
113810113818
const core_1 = __nccwpck_require__(72614);
113811113819
const exec_1 = __nccwpck_require__(2259);
113812113820
const child_process_1 = __nccwpck_require__(32081);
113813113821
const core_2 = __nccwpck_require__(72614);
113814113822
/**
113815113823
* Push changes to the branch
113816113824
*/
113817-
const push = async (coverageDirectory) => {
113825+
const pushChanges = async (coverageDirectory) => {
113818113826
(0, core_1.startGroup)("Check for changes");
113819113827
let stdout = "";
113820113828
try {
@@ -113863,7 +113871,7 @@ const push = async (coverageDirectory) => {
113863113871
}
113864113872
}
113865113873
};
113866-
exports.push = push;
113874+
exports.pushChanges = pushChanges;
113867113875

113868113876

113869113877
/***/ }),
@@ -113908,6 +113916,9 @@ const getTest = async (coverageDir) => {
113908113916
failIds.push(element.testID);
113909113917
}
113910113918
});
113919+
if (failIds.length == 0) {
113920+
failIds = obj.filter((e) => e.hasOwnProperty("error")).map((e) => e.testID);
113921+
}
113911113922
let initialString = "";
113912113923
if (failIds.length > 1) {
113913113924
initialString = `${failIds.length} tests failed`;
@@ -113941,6 +113952,10 @@ const getTest = async (coverageDir) => {
113941113952
testDetails = testDetails.replace(/(?:<>'"`)/g, "");
113942113953
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
113943113954
});
113955+
if (initialString == "") {
113956+
initialString = "Error running tests";
113957+
errorString.push("Unable to get test details. Run flutter test to replicate");
113958+
}
113944113959
const output = `⛔️ - ${initialString}</br >
113945113960
<details><summary>See details</summary>
113946113961
${errorString.join("")}
@@ -114182,6 +114197,14 @@ module.exports = require("net");
114182114197

114183114198
/***/ }),
114184114199

114200+
/***/ 17718:
114201+
/***/ ((module) => {
114202+
114203+
"use strict";
114204+
module.exports = require("node:child_process");
114205+
114206+
/***/ }),
114207+
114185114208
/***/ 15673:
114186114209
/***/ ((module) => {
114187114210

src/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ import { getTest } from "./scripts/runTests";
66
import { createComment as getComment, postComment } from "./scripts/comment";
77
import { setup } from "./scripts/setup";
88
import { checkBranchStatus } from "./scripts/behind";
9-
import { push } from "./scripts/push";
9+
import { pushChanges } from "./scripts/push";
1010
import { retrievePreviousCoverage } from "./scripts/prevCoverage";
1111
import { Lcov } from "lcov-utils";
1212
import minimist from "minimist";
13+
import { execSync } from "node:child_process";
1314

1415
export type stepResponse = { output: string; error: boolean };
1516
export const COVERAGE_DIR = ".coverage";
1617

1718
const run = async (isLocal: boolean) => {
19+
try {
20+
execSync("flutter pub get");
21+
} catch (e) {
22+
console.error(e);
23+
}
24+
1825
try {
1926
const workingDirectory = isLocal ? "." : getInput("working-directory");
2027
// Check if the working directory is different from the current directory
@@ -57,10 +64,11 @@ const run = async (isLocal: boolean) => {
5764

5865
if (createComment) postComment(octokit, comment!, context);
5966

60-
await push(COVERAGE_DIR);
67+
await pushChanges(COVERAGE_DIR);
6168

62-
if (analyzeStr?.error || testStr?.error || coverageStr?.error) {
63-
setFailed(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`);
69+
const errors = [analyzeStr, testStr, coverageStr].filter((step) => step?.error);
70+
if (errors.length > 0) {
71+
setFailed(errors.map((step) => step?.output).join("; "));
6472
}
6573
} catch (err) {
6674
setFailed(`Action failed with error ${err}`);

src/scripts/push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { start } from "repl";
77
/**
88
* Push changes to the branch
99
*/
10-
export const push = async (coverageDirectory: string) => {
10+
export const pushChanges = async (coverageDirectory: string) => {
1111
startGroup("Check for changes");
1212
let stdout: string = "";
1313
try {

src/scripts/runTests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const getTest = async (coverageDir: string): Promise<stepResponse> => {
3434
failIds.push(element.testID);
3535
}
3636
});
37+
if (failIds.length == 0) {
38+
failIds = obj.filter((e: any) => e.hasOwnProperty("error")).map((e: any) => e.testID);
39+
}
3740
let initialString = "";
3841
if (failIds.length > 1) {
3942
initialString = `${failIds.length} tests failed`;
@@ -85,6 +88,11 @@ export const getTest = async (coverageDir: string): Promise<stepResponse> => {
8588
errorString.push("<details><summary>" + testName + "</br></summary>`" + testDetails + "`</details>");
8689
});
8790

91+
if (initialString == "") {
92+
initialString = "Error running tests";
93+
errorString.push("Unable to get test details. Run flutter test to replicate");
94+
}
95+
8896
const output = `⛔️ - ${initialString}</br >
8997
<details><summary>See details</summary>
9098
${errorString.join("")}

0 commit comments

Comments
 (0)