From 38d3aace3704c78e3bc4b354a43f8f8b42d84b77 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 22 Aug 2024 21:15:42 +0100 Subject: [PATCH] chore(automated): Lint commit and format --- README.md | 21 +++++++++++---------- action.yml | 5 +++++ src/main.ts | 7 +++++-- src/scripts/coverage.ts | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f013113..afb51ee 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,17 @@ jobs: ## Inputs -| Name | Description | Required | Default | -| ----------------- | ----------------------------------------------------------------- | -------- | ------- | -| token | Token used for pushing fixes and commenting on PRs. | true | | -| run-tests | Whether tests should be run. | false | true | -| run-analysis | Whether static analysis should be run. | false | true | -| run-coverage | Whether code coverage should be run. | false | true | -| run-prev-coverage | Whether code coverage should be compared with the base branch. | false | true | -| run-behind-by | Whether action should check if HEAD branch is behind base branch. | false | true | -| create-comment | Whether the action should comment the output status. | false | true | -| working-directory | Working directory to run the action in | false | "." | +| Name | Description | Required | Default | +| ------------------- | ----------------------------------------------------------------- | -------- | ------- | +| token | Token used for pushing fixes and commenting on PRs. | true | | +| run-tests | Whether tests should be run. | false | true | +| run-analysis | Whether static analysis should be run. | false | true | +| run-coverage | Whether code coverage should be run. | false | true | +| run-prev-coverage | Whether code coverage should be compared with the base branch. | false | true | +| run-behind-by | Whether action should check if HEAD branch is behind base branch. | false | true | +| create-comment | Whether the action should comment the output status. | false | true | +| working-directory | Working directory to run the action in | false | "." | +| coverage-pass-score | Coverage passing percentage | false | "90" | ## Coverage diff --git a/action.yml b/action.yml index d3c7f30..fdacb96 100644 --- a/action.yml +++ b/action.yml @@ -50,3 +50,8 @@ inputs: required: false default: true type: boolean + + coverage-pass-score: + description: "Coverage passing percentage" + required: false + default: "90" diff --git a/src/main.ts b/src/main.ts index ec69b1d..b1a4764 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export const COVERAGE_DIR = ".coverage"; const run = async (isLocal: boolean) => { try { - const workingDirectory = getInput("working-directory"); + const workingDirectory = isLocal ? "." : getInput("working-directory"); // Check if the working directory is different from the current directory if (workingDirectory && workingDirectory !== process.cwd()) { process.chdir(workingDirectory); @@ -30,6 +30,7 @@ const run = async (isLocal: boolean) => { const runPrevCoverage = isLocal ? true : getBooleanInput("run-prev-coverage"); const runBehindBy = isLocal ? true : getBooleanInput("run-behind-by"); const createComment = isLocal ? true : getBooleanInput("create-comment"); + const score = isLocal ? "90" : getInput("coverage-pass-score"); const octokit = getOctokit(token); let prevCoverage: Lcov | undefined; @@ -46,7 +47,9 @@ const run = async (isLocal: boolean) => { const analyzeStr: stepResponse | undefined = runAnalyze ? await getAnalyze() : undefined; const testStr: stepResponse | undefined = runTests ? await getTest(COVERAGE_DIR) : undefined; - const coverageStr: stepResponse | undefined = runCoverage ? getCoverage(prevCoverage, COVERAGE_DIR) : undefined; + const coverageStr: stepResponse | undefined = runCoverage + ? getCoverage(prevCoverage, COVERAGE_DIR, score) + : undefined; const comment: string | undefined = createComment ? getComment(analyzeStr, testStr, coverageStr, behindByStr) diff --git a/src/scripts/coverage.ts b/src/scripts/coverage.ts index f769ad3..2a4287d 100644 --- a/src/scripts/coverage.ts +++ b/src/scripts/coverage.ts @@ -13,9 +13,20 @@ export const COV_FAILURE = "⚠️ - Coverage check failed"; * @param coverageDirectory - Directory to store coverage report * @returns Coverage report as a stepResponse object */ -export const getCoverage = (prevCoverage: Lcov | undefined, coverageDirectory: string): stepResponse => { +export const getCoverage = ( + prevCoverage: Lcov | undefined, + coverageDirectory: string, + scoreStr: string +): stepResponse => { startGroup("Checking test coverage"); let response: stepResponse | undefined; + let score = 90; + + try { + score = parseInt(scoreStr); + } catch (error) { + console.error("Error parsing score", "Will default to 90", error); + } try { const contents = readFileSync(`${coverageDirectory}/lcov.info`, "utf8"); @@ -28,7 +39,7 @@ export const getCoverage = (prevCoverage: Lcov | undefined, coverageDirectory: s const arr = Object.values(lcov).map((e) => { const fileName = e.sf; const percent = Math.round((e.lh / e.lf) * 1000) / 10; - const passing = percent > 96 ? "✅" : "⛔️"; + const passing = percent > score ? "✅" : "⛔️"; return `${fileName}${percent}%${passing}`; }); debug(`Coverage at ${totalPercent}%`);