From fa599626840a12f297acf70947b66829098651f9 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 29 Aug 2024 14:50:48 +0100 Subject: [PATCH] test --- dist/index.js | 35 +++++++++++++++++++++++++++++------ src/main.ts | 16 ++++++++++++---- src/scripts/push.ts | 2 +- src/scripts/runTests.ts | 8 ++++++++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index e6db9bc..30a0c80 100644 --- a/dist/index.js +++ b/dist/index.js @@ -113287,8 +113287,15 @@ const behind_1 = __nccwpck_require__(98890); const push_1 = __nccwpck_require__(13662); const prevCoverage_1 = __nccwpck_require__(39033); const minimist_1 = __importDefault(__nccwpck_require__(13566)); +const node_child_process_1 = __nccwpck_require__(17718); exports.COVERAGE_DIR = ".coverage"; const run = async (isLocal) => { + try { + (0, node_child_process_1.execSync)("flutter pub get"); + } + catch (e) { + console.error(e); + } try { const workingDirectory = isLocal ? "." : (0, core_1.getInput)("working-directory"); // Check if the working directory is different from the current directory @@ -113325,9 +113332,10 @@ const run = async (isLocal) => { : undefined; if (createComment) (0, comment_1.postComment)(octokit, comment, github_1.context); - await (0, push_1.push)(exports.COVERAGE_DIR); - if (analyzeStr?.error || testStr?.error || coverageStr?.error) { - (0, core_1.setFailed)(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`); + await (0, push_1.pushChanges)(exports.COVERAGE_DIR); + const errors = [analyzeStr, testStr, coverageStr].filter((step) => step?.error); + if (errors.length > 0) { + (0, core_1.setFailed)(errors.map((step) => step?.output).join("; ")); } } catch (err) { @@ -113806,7 +113814,7 @@ const generatePreviousCoverage = async (prev_sha, current_branch, coverage_direc "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.push = void 0; +exports.pushChanges = void 0; const core_1 = __nccwpck_require__(72614); const exec_1 = __nccwpck_require__(2259); const child_process_1 = __nccwpck_require__(32081); @@ -113814,7 +113822,7 @@ const core_2 = __nccwpck_require__(72614); /** * Push changes to the branch */ -const push = async (coverageDirectory) => { +const pushChanges = async (coverageDirectory) => { (0, core_1.startGroup)("Check for changes"); let stdout = ""; try { @@ -113863,7 +113871,7 @@ const push = async (coverageDirectory) => { } } }; -exports.push = push; +exports.pushChanges = pushChanges; /***/ }), @@ -113908,6 +113916,9 @@ const getTest = async (coverageDir) => { failIds.push(element.testID); } }); + if (failIds.length == 0) { + failIds = obj.filter((e) => e.hasOwnProperty("error")).map((e) => e.testID); + } let initialString = ""; if (failIds.length > 1) { initialString = `${failIds.length} tests failed`; @@ -113941,6 +113952,10 @@ const getTest = async (coverageDir) => { testDetails = testDetails.replace(/(?:<>'"`)/g, ""); errorString.push("
" + testName + "
`" + testDetails + "`
"); }); + if (initialString == "") { + initialString = "Error running tests"; + errorString.push("Unable to get test details. Run flutter test to replicate"); + } const output = `⛔️ - ${initialString}
See details ${errorString.join("")} @@ -114182,6 +114197,14 @@ module.exports = require("net"); /***/ }), +/***/ 17718: +/***/ ((module) => { + +"use strict"; +module.exports = require("node:child_process"); + +/***/ }), + /***/ 15673: /***/ ((module) => { diff --git a/src/main.ts b/src/main.ts index b1a4764..6f4882d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,15 +6,22 @@ import { getTest } from "./scripts/runTests"; import { createComment as getComment, postComment } from "./scripts/comment"; import { setup } from "./scripts/setup"; import { checkBranchStatus } from "./scripts/behind"; -import { push } from "./scripts/push"; +import { pushChanges } from "./scripts/push"; import { retrievePreviousCoverage } from "./scripts/prevCoverage"; import { Lcov } from "lcov-utils"; import minimist from "minimist"; +import { execSync } from "node:child_process"; export type stepResponse = { output: string; error: boolean }; export const COVERAGE_DIR = ".coverage"; const run = async (isLocal: boolean) => { + try { + execSync("flutter pub get"); + } catch (e) { + console.error(e); + } + try { const workingDirectory = isLocal ? "." : getInput("working-directory"); // Check if the working directory is different from the current directory @@ -57,10 +64,11 @@ const run = async (isLocal: boolean) => { if (createComment) postComment(octokit, comment!, context); - await push(COVERAGE_DIR); + await pushChanges(COVERAGE_DIR); - if (analyzeStr?.error || testStr?.error || coverageStr?.error) { - setFailed(`${analyzeStr?.output}\n${testStr?.output}\n${coverageStr?.output}`); + const errors = [analyzeStr, testStr, coverageStr].filter((step) => step?.error); + if (errors.length > 0) { + setFailed(errors.map((step) => step?.output).join("; ")); } } catch (err) { setFailed(`Action failed with error ${err}`); diff --git a/src/scripts/push.ts b/src/scripts/push.ts index 17bcd8c..68e95a6 100644 --- a/src/scripts/push.ts +++ b/src/scripts/push.ts @@ -7,7 +7,7 @@ import { start } from "repl"; /** * Push changes to the branch */ -export const push = async (coverageDirectory: string) => { +export const pushChanges = async (coverageDirectory: string) => { startGroup("Check for changes"); let stdout: string = ""; try { diff --git a/src/scripts/runTests.ts b/src/scripts/runTests.ts index fedaa01..b70bf83 100644 --- a/src/scripts/runTests.ts +++ b/src/scripts/runTests.ts @@ -34,6 +34,9 @@ export const getTest = async (coverageDir: string): Promise => { failIds.push(element.testID); } }); + if (failIds.length == 0) { + failIds = obj.filter((e: any) => e.hasOwnProperty("error")).map((e: any) => e.testID); + } let initialString = ""; if (failIds.length > 1) { initialString = `${failIds.length} tests failed`; @@ -85,6 +88,11 @@ export const getTest = async (coverageDir: string): Promise => { errorString.push("
" + testName + "
`" + testDetails + "`
"); }); + if (initialString == "") { + initialString = "Error running tests"; + errorString.push("Unable to get test details. Run flutter test to replicate"); + } + const output = `⛔️ - ${initialString}
See details ${errorString.join("")}