From b6155b9f0948f5c42e6d206bb156fd9028675e79 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 3 Jul 2024 10:47:59 +0100 Subject: [PATCH 1/2] fix: Add basic error reporting --- .github/workflows/pull-request.yml | 2 +- .gitignore | 11 +++--- src/main.ts | 35 ++++++++++++------- src/scripts/analyze.ts | 10 +++--- src/scripts/comment.ts | 9 ++--- src/scripts/runTests.ts | 55 ++++++++---------------------- tests/src/scripts/coverage.test.ts | 6 +--- tests/src/scripts/runTests.test.ts | 6 +--- 8 files changed, 53 insertions(+), 81 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 90acfc7..305571f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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 diff --git a/.gitignore b/.gitignore index bc5bcde..eb986de 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +**/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 diff --git a/src/main.ts b/src/main.ts index 0ebe432..9d3e478 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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"; @@ -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(); diff --git a/src/scripts/analyze.ts b/src/scripts/analyze.ts index a129817..0bc04c9 100644 --- a/src/scripts/analyze.ts +++ b/src/scripts/analyze.ts @@ -57,9 +57,9 @@ export const getAnalyze = async (): Promise => { const output = `${ANALYZE_FAILURE}; ${issuesFound}
See details - ${errorString.join( - "" - )}${warningString.join("")}${infoString.join("")}
TypeFile nameDetails
+ TypeFile nameDetails${errorString.join("")}${warningString.join( + "" + )}${infoString.join("")} `; response = { output: output, error: true }; @@ -84,6 +84,4 @@ export const getErrEmoji = (errType: analyzeErrTypes) => { }; export const generateTableRow = (err: analyzeDetails, type: analyzeErrTypes) => - `${getErrEmoji(type)}Error${err.file}${ - err.details - }`; + `${getErrEmoji(type)}Error${err.file}${err.details}`; diff --git a/src/scripts/comment.ts b/src/scripts/comment.ts index d3e77da..8798115 100644 --- a/src/scripts/comment.ts +++ b/src/scripts/comment.ts @@ -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 = `

PR Checks complete