Skip to content

Commit

Permalink
Body too long (#18)
Browse files Browse the repository at this point in the history
* @vercel/ncc minor update

* fix error when comment body is too long (#15)

* update verstion to 1.1.5

* add explanation image to README
  • Loading branch information
MishaKav authored Jul 17, 2021
1 parent db17a70 commit 2cb7a17
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/live-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: ./data/pytest-coverage_4.txt
junitxml-path: ./data/pytest_1.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multiple-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v2

- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
multiple-files: |
My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml
Expand Down
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on

```yaml
- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
```
## Inputs
| Name | Required | Default | Description |
| ---------------------- | -------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `github-token` | ✓ | `${{github.token}}` | An alternative GitHub token, other than the default provided by GitHub Actions runner |
| `pytest-coverage-path` | | `./pytest-coverage.txt` | The location of the txt output of pytest-coverage. Used to generate the comment |
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects |
| `badge-title` | | `Coverage` | Title for the badge icon |
| `hide-badge` | | false | Hide badge with percentage |
| `hide-report` | | false | Hide coverage report |
| `junitxml-path` | | '' | The location of the junitxml path |
| `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. |
| Name | Required | Default | Description |
| ---------------------- | -------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `github-token` | ✓ | `${{github.token}}` | An alternative GitHub token, other than the default provided by GitHub Actions runner |
| `pytest-coverage-path` | | `./pytest-coverage.txt` | The location of the txt output of pytest-coverage. Used to generate the comment |
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects |
| `badge-title` | | `Coverage` | Title for the badge icon |
| `hide-badge` | | false | Hide badge with percentage |
| `hide-report` | | false | Hide coverage report |
| `junitxml-path` | | '' | The location of the junitxml path |
| `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. |
| `multiple-files` | | '' | You can pass array of titles and files to generate single comment with table of results.<br/>Single line should look like `Title, ./path/to/pytest-coverage.txt, ./path/to/pytest.xml`<br/> example:<br/> `My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml`<br/>**Note:** In that mode the `output` for `coverage` and `color` will be for the first file only. |

## Output example
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
pytest --junitxml=pytest.xml --cov=app tests/ | tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
Expand All @@ -82,7 +82,7 @@ Example GitHub Action workflow that uses coverage percentage as output (see the
```yaml
- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
Expand All @@ -97,7 +97,7 @@ Example GitHub Action workflow that passes all params to Pytest Coverage Comment

```yaml
- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: ./path-to-file/pytest-coverage.txt
title: My Coverage Report Title
Expand All @@ -109,6 +109,8 @@ Example GitHub Action workflow that passes all params to Pytest Coverage Comment
junitxml-title: My JUnit Xml Summary Title
```

![image](https://user-images.githubusercontent.com/289035/126039976-3f1bf8dd-5a6b-4103-8548-fc3eecc377d7.png)

Example GitHub Action workflow that runs pytest inside **docker**
It will generate `pytest-coverage.txt` and `pytest.xml` in `/tmp` directory inside docker and share `/tmp` directory with GitHub workspace.

Expand All @@ -118,7 +120,7 @@ It will generate `pytest-coverage.txt` and `pytest.xml` in `/tmp` directory insi
docker run -v /tmp:/tmp $IMAGE_TAG python3 -m pytest --cov-report=term-missing:skip-covered --junitxml=/tmp/pytest.xml --cov=src tests/ | tee /tmp/pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
pytest-coverage-path: /tmp/pytest-coverage.txt
junitxml-path: /tmp/pytest.xml
Expand All @@ -128,7 +130,7 @@ Example GitHub Action workflow that uses multiple files mode (see the [live work

```yaml
- name: Pytest coverage comment
uses: MishaKav/[email protected].4
uses: MishaKav/[email protected].5
with:
multiple-files: |
My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml
Expand Down
52 changes: 34 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13104,119 +13104,119 @@ module.exports = eval("require")("encoding");
/***/ ((module) => {

"use strict";
module.exports = require("assert");;
module.exports = require("assert");

/***/ }),

/***/ 8614:
/***/ ((module) => {

"use strict";
module.exports = require("events");;
module.exports = require("events");

/***/ }),

/***/ 5747:
/***/ ((module) => {

"use strict";
module.exports = require("fs");;
module.exports = require("fs");

/***/ }),

/***/ 8605:
/***/ ((module) => {

"use strict";
module.exports = require("http");;
module.exports = require("http");

/***/ }),

/***/ 7211:
/***/ ((module) => {

"use strict";
module.exports = require("https");;
module.exports = require("https");

/***/ }),

/***/ 1631:
/***/ ((module) => {

"use strict";
module.exports = require("net");;
module.exports = require("net");

/***/ }),

/***/ 2087:
/***/ ((module) => {

"use strict";
module.exports = require("os");;
module.exports = require("os");

/***/ }),

/***/ 5622:
/***/ ((module) => {

"use strict";
module.exports = require("path");;
module.exports = require("path");

/***/ }),

/***/ 2413:
/***/ ((module) => {

"use strict";
module.exports = require("stream");;
module.exports = require("stream");

/***/ }),

/***/ 4304:
/***/ ((module) => {

"use strict";
module.exports = require("string_decoder");;
module.exports = require("string_decoder");

/***/ }),

/***/ 8213:
/***/ ((module) => {

"use strict";
module.exports = require("timers");;
module.exports = require("timers");

/***/ }),

/***/ 4016:
/***/ ((module) => {

"use strict";
module.exports = require("tls");;
module.exports = require("tls");

/***/ }),

/***/ 8835:
/***/ ((module) => {

"use strict";
module.exports = require("url");;
module.exports = require("url");

/***/ }),

/***/ 1669:
/***/ ((module) => {

"use strict";
module.exports = require("util");;
module.exports = require("util");

/***/ }),

/***/ 8761:
/***/ ((module) => {

"use strict";
module.exports = require("zlib");;
module.exports = require("zlib");

/***/ })

Expand Down Expand Up @@ -13255,7 +13255,9 @@ module.exports = require("zlib");;
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
Expand All @@ -13265,6 +13267,8 @@ const { getCoverageReport } = __nccwpck_require__(3248);
const { getSummaryReport } = __nccwpck_require__(9670);
const { getMultipleReport } = __nccwpck_require__(4158);

const MAX_COMMENT_LENGTH = 65536;

const main = async () => {
const token = core.getInput('github-token', { required: true });
const title = core.getInput('title', { required: false });
Expand Down Expand Up @@ -13311,10 +13315,22 @@ const main = async () => {
if (multipleFiles && multipleFiles.length) {
finalHtml += getMultipleReport(options);
} else {
const { html, coverage, color } = getCoverageReport(options);
let report = getCoverageReport(options);
const { coverage, color } = report;
const summaryReport = getSummaryReport(options);

finalHtml += html;
if (report.html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
console.warn(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
console.warn(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true" or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}

finalHtml += report.html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;

if (coverage) {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pytest-coverage-comment",
"version": "1.1.4",
"version": "1.1.5",
"description": "Comments a pull request with the pytest code coverage badge, full report and tests summary",
"author": "Misha Kav",
"license": "MIT",
Expand Down Expand Up @@ -28,7 +28,7 @@
"xml2js": "^0.4.23"
},
"devDependencies": {
"@vercel/ncc": "^0.28.6",
"@vercel/ncc": "^0.29.0",
"eslint": "^7.30.0",
"prettier": "^2.3.2"
},
Expand Down
18 changes: 16 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { getCoverageReport } = require('./parse');
const { getSummaryReport } = require('./junitXml');
const { getMultipleReport } = require('./multiFiles');

const MAX_COMMENT_LENGTH = 65536;

const main = async () => {
const token = core.getInput('github-token', { required: true });
const title = core.getInput('title', { required: false });
Expand Down Expand Up @@ -50,10 +52,22 @@ const main = async () => {
if (multipleFiles && multipleFiles.length) {
finalHtml += getMultipleReport(options);
} else {
const { html, coverage, color } = getCoverageReport(options);
let report = getCoverageReport(options);
const { coverage, color } = report;
const summaryReport = getSummaryReport(options);

finalHtml += html;
if (report.html.length + summaryReport.length > MAX_COMMENT_LENGTH) {
// generate new html without report
console.warn(
`Your comment is too long (maximum is ${MAX_COMMENT_LENGTH} characters), coverage report will not be added.`
);
console.warn(
`Try add: "--cov-report=term-missing:skip-covered", or add "hide-report: true" or switch to "multiple-files" mode`
);
report = getSummaryReport({ ...options, hideReport: true });
}

finalHtml += report.html;
finalHtml += finalHtml.length ? `\n\n${summaryReport}` : summaryReport;

if (coverage) {
Expand Down

0 comments on commit 2cb7a17

Please sign in to comment.