diff --git a/README.md b/README.md index 955d64ec..d5cac278 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The possible inputs for this action are: | `monorepo-base-path` (**Optional**) | The location of your monrepo `packages` path | | | `lcov-file` (**Optional**) | The location of the lcov file to read the coverage report. `Needed only for single repos` | `./coverage/lcov.info` | | `lcov-base` (**Optional**) | The location of the lcov file resulting from running the tests in the base branch. When this is set a diff of the coverage percentages is shown. `Needed only for single repos`. | | +| `hide-details` (**Optional**) | Flag to optionally hide coverage details, this feature is useful for big repositories with lots of files. | `false` | ## Examples diff --git a/action.yml b/action.yml index 963c3d36..955a0cbd 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: lcov-base: description: The location of the lcov file for the base branch. Applicable for single repo setup. required: false + hide-details: + description: Flag to optionally hide coverage details, this feature is useful for big repositories with lots of files. + required: false runs: using: node12 main: dist/main.js diff --git a/dist/main.js b/dist/main.js index a1cd21b6..70db6bf9 100644 --- a/dist/main.js +++ b/dist/main.js @@ -4,8 +4,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var fs = require('fs'); var fs__default = _interopDefault(fs); -var os = _interopDefault(require('os')); var path = _interopDefault(require('path')); +var os = _interopDefault(require('os')); var http = _interopDefault(require('http')); var https = _interopDefault(require('https')); require('net'); @@ -6035,6 +6035,7 @@ function commentForMonorepo( lcovBaseArrayForMonorepo, options, ) { + const { hideDetails, base } = options; const html = lcovArrayForMonorepo.map(lcovObj => { const baseLcov = lcovBaseArrayForMonorepo.find( el => el.packageName === lcovObj.packageName, @@ -6050,7 +6051,7 @@ function commentForMonorepo( ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return `${table( + const coverageTable = table( tbody( tr( th(lcovObj.packageName), @@ -6058,14 +6059,19 @@ function commentForMonorepo( pdiffHtml, ), ), - )} \n\n ${details( - summary("Coverage Report"), - tabulate(lcovObj.lcov, options), - )}
`; + ); + const detailsTable = !hideDetails + ? `\n\n ${details( + summary("Coverage Report"), + tabulate(lcovObj.lcov, options), + )}
` + : ""; + + return `${coverageTable} ${detailsTable}`.trim(); }); return fragment( - `Coverage after merging into ${b(options.base)}

`, + `Coverage after merging into ${b(base)}

`, html.join(""), ); } @@ -6081,17 +6087,19 @@ function comment(lcov, before, options) { const pdiff = pafter - pbefore; const plus = pdiff > 0 ? "+" : ""; const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴"; + const { hideDetails, base } = options; const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return fragment( - `Coverage after merging ${b(options.head)} into ${b( - options.base, - )}

`, - table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))), - "\n\n", - details(summary("Coverage Report"), tabulate(lcov, options)), + const title = `Coverage after merging into ${b(base)}

`; + const coverageTable = table( + tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml)), ); + const detailsTable = !hideDetails + ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` + : ""; + + return fragment(title, coverageTable, detailsTable); } /** @@ -6217,14 +6225,13 @@ const getLcovFiles = (dir, filelist = []) => { filelist = fs__default.statSync(path.join(dir, file)).isDirectory() ? getLcovFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov.info"); - }) + .filter(file => file.path.includes("lcov.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -6239,14 +6246,13 @@ const getLcovBaseFiles = (dir, filelist = []) => { filelist = fs__default.statSync(path.join(dir, file)).isDirectory() ? getLcovBaseFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov-base.info"); - }) + .filter(file => file.path.includes("lcov-base.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -6256,6 +6262,8 @@ async function main() { const token = core$1.getInput("github-token"); const lcovFile = core$1.getInput("lcov-file") || "./coverage/lcov.info"; const baseFile = core$1.getInput("lcov-base"); + const hideDetails = !!core$1.getInput("hide-details"); + // Add base path for monorepo const monorepoBasePath = core$1.getInput("monorepo-base-path"); @@ -6264,6 +6272,7 @@ async function main() { (await fs.promises.readFile(lcovFile, "utf-8").catch(err => null)); if (!monorepoBasePath && !raw) { console.log(`No coverage report found at '${lcovFile}', exiting...`); + return; } @@ -6274,8 +6283,8 @@ async function main() { console.log(`No coverage report found at '${baseFile}', ignoring...`); } - let lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; - let lcovBaseArray = monorepoBasePath + const lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; + const lcovBaseArray = monorepoBasePath ? getLcovBaseFiles(monorepoBasePath) : []; @@ -6309,6 +6318,7 @@ async function main() { prefix: `${process.env.GITHUB_WORKSPACE}/`, head: context.payload.pull_request.head.ref, base: context.payload.pull_request.base.ref, + hideDetails, }; const lcov = !monorepoBasePath && (await parse$1(raw)); @@ -6330,7 +6340,7 @@ async function main() { }); } -main().catch(function(err) { +main().catch(err => { console.log(err); core$1.setFailed(err.message); }); diff --git a/src/comment.js b/src/comment.js index 96ed1da0..abe6fe61 100644 --- a/src/comment.js +++ b/src/comment.js @@ -13,6 +13,7 @@ export function commentForMonorepo( lcovBaseArrayForMonorepo, options, ) { + const { hideDetails, base } = options; const html = lcovArrayForMonorepo.map(lcovObj => { const baseLcov = lcovBaseArrayForMonorepo.find( el => el.packageName === lcovObj.packageName, @@ -28,7 +29,7 @@ export function commentForMonorepo( ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return `${table( + const coverageTable = table( tbody( tr( th(lcovObj.packageName), @@ -36,14 +37,19 @@ export function commentForMonorepo( pdiffHtml, ), ), - )} \n\n ${details( - summary("Coverage Report"), - tabulate(lcovObj.lcov, options), - )}
`; + ); + const detailsTable = !hideDetails + ? `\n\n ${details( + summary("Coverage Report"), + tabulate(lcovObj.lcov, options), + )}
` + : ""; + + return `${coverageTable} ${detailsTable}`.trim(); }); return fragment( - `Coverage after merging into ${b(options.base)}

`, + `Coverage after merging into ${b(base)}

`, html.join(""), ); } @@ -59,17 +65,19 @@ export function comment(lcov, before, options) { const pdiff = pafter - pbefore; const plus = pdiff > 0 ? "+" : ""; const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴"; + const { hideDetails, base } = options; const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return fragment( - `Coverage after merging ${b(options.head)} into ${b( - options.base, - )}

`, - table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))), - "\n\n", - details(summary("Coverage Report"), tabulate(lcov, options)), + const title = `Coverage after merging into ${b(base)}

`; + const coverageTable = table( + tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml)), ); + const detailsTable = !hideDetails + ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` + : ""; + + return fragment(title, coverageTable, detailsTable); } /** diff --git a/src/index.js b/src/index.js index 6e1cc294..9e89a153 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import fs, { promises } from "fs"; +import path from "path"; import core from "@actions/core"; import github from "@actions/github"; -import path from "path"; import { parse } from "./lcov"; import { diff, diffForMonorepo } from "./comment"; import { upsertComment } from "./github"; @@ -17,14 +17,13 @@ const getLcovFiles = (dir, filelist = []) => { filelist = fs.statSync(path.join(dir, file)).isDirectory() ? getLcovFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov.info"); - }) + .filter(file => file.path.includes("lcov.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -39,14 +38,13 @@ const getLcovBaseFiles = (dir, filelist = []) => { filelist = fs.statSync(path.join(dir, file)).isDirectory() ? getLcovBaseFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov-base.info"); - }) + .filter(file => file.path.includes("lcov-base.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -56,6 +54,8 @@ async function main() { const token = core.getInput("github-token"); const lcovFile = core.getInput("lcov-file") || "./coverage/lcov.info"; const baseFile = core.getInput("lcov-base"); + const hideDetails = !!core.getInput("hide-details"); + // Add base path for monorepo const monorepoBasePath = core.getInput("monorepo-base-path"); @@ -64,6 +64,7 @@ async function main() { (await promises.readFile(lcovFile, "utf-8").catch(err => null)); if (!monorepoBasePath && !raw) { console.log(`No coverage report found at '${lcovFile}', exiting...`); + return; } @@ -74,8 +75,8 @@ async function main() { console.log(`No coverage report found at '${baseFile}', ignoring...`); } - let lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; - let lcovBaseArray = monorepoBasePath + const lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; + const lcovBaseArray = monorepoBasePath ? getLcovBaseFiles(monorepoBasePath) : []; @@ -109,6 +110,7 @@ async function main() { prefix: `${process.env.GITHUB_WORKSPACE}/`, head: context.payload.pull_request.head.ref, base: context.payload.pull_request.base.ref, + hideDetails, }; const lcov = !monorepoBasePath && (await parse(raw)); @@ -130,7 +132,7 @@ async function main() { }); } -main().catch(function(err) { +main().catch(err => { console.log(err); core.setFailed(err.message); });