Skip to content

Commit

Permalink
chore(automated): Lint commit and format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Aug 22, 2024
1 parent 9a2facd commit 38d3aac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ inputs:
required: false
default: true
type: boolean

coverage-pass-score:
description: "Coverage passing percentage"
required: false
default: "90"
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions src/scripts/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 `<tr><td>${fileName}</td><td>${percent}%</td><td>${passing}</td></tr>`;
});
debug(`Coverage at ${totalPercent}%`);
Expand Down

0 comments on commit 38d3aac

Please sign in to comment.