From c219209990f1da905adc6e63c8a40762ec374c0b Mon Sep 17 00:00:00 2001 From: Nikita Terentyev Date: Wed, 9 Oct 2024 11:39:04 +0700 Subject: [PATCH] Add input for skipping full covered files from xml --- README.md | 1 + action.yml | 5 +++++ dist/index.js | 18 +++++++++++------- src/cli.js | 1 + src/index.js | 4 ++++ src/parseXml.js | 14 +++++++------- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0936477..64b2b0f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on | `junitxml-title` | | '' | Title for summary for junitxml | | `create-new-comment` | | false | When false, will update the same comment, otherwise will publish new comment on each run. | | `hide-comment` | | false | Hide the whole comment (use when you need only the `output`). Useful for auto-update bagdes in readme. See the [workflow](../main/.github/workflows/live-test.yml) for example | +| `xml-skip-covered` | | false | Hide files from xml report with 100% coverage | | `default-branch` | | `main` | This branch name is useful when generate "coverageHtml", it points direct links to files on this branch (instead of commit).
Usually "main" or "master" | | `multiple-files` | | '' | You can pass array of titles and files to generate single comment with table of results.
Single line should look like `Title, ./path/to/pytest-coverage.txt, ./path/to/pytest-junit.xml`
example:
`My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml`
**Note:** In that mode the `output` for `coverage` and `color` will be for the first file only. | | `remove-link-from-badge` | | false | When true, it will remove the link from badge to readme | diff --git a/action.yml b/action.yml index 8a9abc7..ef18923 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,11 @@ inputs: default: 'false' required: false + xml-skip-covered: + description: 'Hide files from xml report with 100% coverage.' + default: 'false' + required: false + report-only-changed-files: description: 'Show in report only changed files for this commit, and not all files' default: 'false' diff --git a/dist/index.js b/dist/index.js index c26944c..23fafa4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -17396,7 +17396,7 @@ const getCoverageXmlReport = (options) => { } if (parsedXml && isValid) { - const coverageObj = coverageXmlToFiles(parsedXml); + const coverageObj = coverageXmlToFiles(parsedXml, options.xmlSkipCovered); const dataFromXml = { coverage: coverageObj, total: coverage }; const html = toHtml(null, options, dataFromXml); const color = getCoverageColor(coverage ? coverage.cover : '0'); @@ -17436,7 +17436,7 @@ const getXmlContent = (data) => { }; // parse coverage xml to Files structure -const coverageXmlToFiles = (coverageXml) => { +const coverageXmlToFiles = (coverageXml, xmlSkipCovered) => { let files = []; coverageXml.packages[0].package @@ -17445,7 +17445,7 @@ const coverageXmlToFiles = (coverageXml) => { package.classes[0].class .filter((c) => c.lines) .forEach((c) => { - const fileObj = parseClass(c); + const fileObj = parseClass(c, xmlSkipCovered); if (fileObj) { files.push(fileObj); @@ -17456,19 +17456,19 @@ const coverageXmlToFiles = (coverageXml) => { return files; }; -const parseClass = (classObj) => { +const parseClass = (classObj, xmlSkipCovered) => { if (!classObj || !classObj.lines) { return null; } - const { stmts, missing, totalMissing: miss } = parseLines(classObj.lines); const { filename: name, 'line-rate': lineRate } = classObj['$']; - const isFullCoverage = lineRate === '1'; + if (xmlSkipCovered && isFullCoverage) { + return null; + } const cover = isFullCoverage ? '100%' : `${parseInt(parseFloat(lineRate) * 100)}%`; - return { name, stmts, miss, cover, missing }; }; @@ -17875,6 +17875,9 @@ const main = async () => { required: false, }); const hideComment = core.getBooleanInput('hide-comment', { required: false }); + const xmlSkipCovered = core.getBooleanInput('xml-skip-covered', { + required: false, + }); const reportOnlyChangedFiles = core.getBooleanInput( 'report-only-changed-files', { required: false }, @@ -17920,6 +17923,7 @@ const main = async () => { hideReport, createNewComment, hideComment, + xmlSkipCovered, reportOnlyChangedFiles, removeLinkFromBadge, defaultBranch, diff --git a/src/cli.js b/src/cli.js index 54a03cf..e7e72d7 100644 --- a/src/cli.js +++ b/src/cli.js @@ -67,6 +67,7 @@ const main = async () => { reportOnlyChangedFiles: false, removeLinkFromBadge: false, hideComment: false, + // xmlSkipCovered: true, xmlTitle: '', // multipleFiles, changedFiles: { diff --git a/src/index.js b/src/index.js index e8fa5e0..f37fd8a 100644 --- a/src/index.js +++ b/src/index.js @@ -63,6 +63,9 @@ const main = async () => { required: false, }); const hideComment = core.getBooleanInput('hide-comment', { required: false }); + const xmlSkipCovered = core.getBooleanInput('xml-skip-covered', { + required: false, + }); const reportOnlyChangedFiles = core.getBooleanInput( 'report-only-changed-files', { required: false }, @@ -108,6 +111,7 @@ const main = async () => { hideReport, createNewComment, hideComment, + xmlSkipCovered, reportOnlyChangedFiles, removeLinkFromBadge, defaultBranch, diff --git a/src/parseXml.js b/src/parseXml.js index b8e354b..d6c5eec 100644 --- a/src/parseXml.js +++ b/src/parseXml.js @@ -61,7 +61,7 @@ const getCoverageXmlReport = (options) => { } if (parsedXml && isValid) { - const coverageObj = coverageXmlToFiles(parsedXml); + const coverageObj = coverageXmlToFiles(parsedXml, options.xmlSkipCovered); const dataFromXml = { coverage: coverageObj, total: coverage }; const html = toHtml(null, options, dataFromXml); const color = getCoverageColor(coverage ? coverage.cover : '0'); @@ -101,7 +101,7 @@ const getXmlContent = (data) => { }; // parse coverage xml to Files structure -const coverageXmlToFiles = (coverageXml) => { +const coverageXmlToFiles = (coverageXml, xmlSkipCovered) => { let files = []; coverageXml.packages[0].package @@ -110,7 +110,7 @@ const coverageXmlToFiles = (coverageXml) => { package.classes[0].class .filter((c) => c.lines) .forEach((c) => { - const fileObj = parseClass(c); + const fileObj = parseClass(c, xmlSkipCovered); if (fileObj) { files.push(fileObj); @@ -121,19 +121,19 @@ const coverageXmlToFiles = (coverageXml) => { return files; }; -const parseClass = (classObj) => { +const parseClass = (classObj, xmlSkipCovered) => { if (!classObj || !classObj.lines) { return null; } - const { stmts, missing, totalMissing: miss } = parseLines(classObj.lines); const { filename: name, 'line-rate': lineRate } = classObj['$']; - const isFullCoverage = lineRate === '1'; + if (xmlSkipCovered && isFullCoverage) { + return null; + } const cover = isFullCoverage ? '100%' : `${parseInt(parseFloat(lineRate) * 100)}%`; - return { name, stmts, miss, cover, missing }; };