Skip to content

Commit

Permalink
feat: document barecheck application usage (#78)
Browse files Browse the repository at this point in the history
* add barecheck app token input

* use github application token

* build new version

* fix sinfle line text

* add input test

* impove input args coverage

* update images and add docs about uncovered lines

* comment one test

* revert
  • Loading branch information
vitaliimelnychuk authored Jun 23, 2021
1 parent d20aa5e commit 72693aa
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ jobs:
id: code-coverage
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage/lcov.info"
base-lcov-file: "./lcov.info"
minimum-ratio: 0
send-summary-comment: true
show-annotations: "warning"
env:
BARECHECK_GITHUB_APP_TOKEN: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

GitHub Action that generates coverage reports

![code coverage report](./docs/img/barecheck-comment.png)
![code coverage report success](./docs/img/barecheck-comment-success.png)

## Show annotations

As a part of code coverage report action also enable an ability to show annotations along with changed lines to keep control what is covered with tests without interapting review process

![show annotations](./docs/img/show-annotations.png)

## Show uncovered files

In the rea; world, it's hard to get 100% code coverage and keep it all the time. Instead of showing you all uncovered files Barecheck show only the ones you have changed.
![code coverage report](./docs/img/barecheck-comment-fail.png)

## Usage

To integrate with this Github Action, you can just use following configuration in your already created workflow. As a result you will get Github Pull request comment with total code coverage

```yml
- name: Generate Code Coverage report
id: code-coverage
uses: barecheck/code-coverage-action@v0.3.3
uses: barecheck/code-coverage-action@v0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage/lcov.info"
base-lcov-file: "./coverage/base-lcov.info"
send-summary-comment: true
Expand All @@ -30,14 +35,15 @@ To integrate with this Github Action, you can just use following configuration i
## Inputs
| Key | Required | Default | Description |
| ---------------------- | -------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `github-token` | **yes** | - | Your Github token that would be used to send summary comment |
| `lcov-file` | **yes** | - | Lcov.info file that was generated after your test coverage command |
| `base-lcov-file` | **yes** | - | Lcov.info file that would be used for code coverage |
| `send-summary-comment` | **no** | true | Option to send Github code coverage comment based on the changes that were made in PR |
| `show-annotations` | **no** | 'warning' | Option to enable Github anotation that would show uncovered files in review tab. Options: ' ' \| warning \| error |
| `minimum-ratio` | **no** | '' | Percantage of uncovered lines that is allowed for new changes |
| Key | Required | Default | Description |
| ---------------------------- | -------- | --------- | ----------------------------------------------------------------------------------------------------------------- |
| `github-token` | **no** | - | **DEPRECATED\*** Install application and use `barecheck-github-app-token` instead |
| `barecheck-github-app-token` | **yes** | - | Barecheck application token, received after application installation comment |
| `lcov-file` | **yes** | - | Lcov.info file that was generated after your test coverage command |
| `base-lcov-file` | **yes** | - | Lcov.info file that would be used for code coverage |
| `send-summary-comment` | **no** | true | Option to send Github code coverage comment based on the changes that were made in PR |
| `show-annotations` | **no** | 'warning' | Option to enable Github anotation that would show uncovered files in review tab. Options: ' ' \| warning \| error |
| `minimum-ratio` | **no** | '' | Percantage of uncovered lines that is allowed for new changes |

## Workflow Example

Expand Down Expand Up @@ -96,9 +102,9 @@ jobs:
# Compares two code coverage files and generates report as a comment
- name: Generate Code Coverage report
id: code-coverage
uses: barecheck/code-coverage-action@v0.3.3
uses: barecheck/code-coverage-action@v0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage/lcov.info"
base-lcov-file: "./lcov.info"
minimum-ratio: 0 # Fails Github action once code coverage is decreasing
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ branding:
inputs:
github-token:
description: Your GitHub secret token
deprecationMessage: The token will be deprecated in the next versions, please install app and use `barecheck-github-app-token` instead
required: false
barecheck-github-app-token:
description: Barecheck application token, received after application installation
required: true
lcov-file:
description: "Compare code coverage report"
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10024,11 +10024,15 @@ const showAnnotations = async (compareFileData) => {
);

fileLinesWithChangedFiles.forEach(({ file, lines }) => {
const formattedLines = lines
.map((line) => (Array.isArray(line) ? line.join("-") : line))
.join(", ");
const linesToDisplay = lines.map((line) =>
Array.isArray(line) ? line.join("-") : line
);

const linesWord = linesToDisplay.length === 1 ? "line is" : "lines are";

const formattedLines = linesToDisplay.join(", ");

const message = `file=${file}::${formattedLines} lines are not covered with tests`;
const message = `file=${file}::${formattedLines} ${linesWord} not covered with tests`;

// NOTE: consider an option to show lines directly by attaching 'line' param
// Need to fix the issue where we consider 'empty line' as covered line
Expand Down Expand Up @@ -10351,7 +10355,8 @@ const getShowAnnotations = () => {

const getGithubToken = () => core.getInput("github-token");

const getBarecheckGithubAppToken = () => process.env.BARECHECK_GITHUB_APP_TOKEN;
const getBarecheckGithubAppToken = () =>
core.getInput("barecheck-github-app-token");

module.exports = {
getShowAnnotations,
Expand Down
Binary file added docs/img/barecheck-comment-fail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/barecheck-comment-success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/barecheck-comment.png
Binary file not shown.
Binary file modified docs/img/show-annotations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/features/showAnnotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ const showAnnotations = async (compareFileData) => {
);

fileLinesWithChangedFiles.forEach(({ file, lines }) => {
const formattedLines = lines
.map((line) => (Array.isArray(line) ? line.join("-") : line))
.join(", ");
const linesToDisplay = lines.map((line) =>
Array.isArray(line) ? line.join("-") : line
);

const message = `file=${file}::${formattedLines} lines are not covered with tests`;
const linesWord = linesToDisplay.length === 1 ? "line is" : "lines are";

const formattedLines = linesToDisplay.join(", ");

const message = `file=${file}::${formattedLines} ${linesWord} not covered with tests`;

// NOTE: consider an option to show lines directly by attaching 'line' param
// Need to fix the issue where we consider 'empty line' as covered line
Expand Down
3 changes: 2 additions & 1 deletion src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const getShowAnnotations = () => {

const getGithubToken = () => core.getInput("github-token");

const getBarecheckGithubAppToken = () => process.env.BARECHECK_GITHUB_APP_TOKEN;
const getBarecheckGithubAppToken = () =>
core.getInput("barecheck-github-app-token");

module.exports = {
getShowAnnotations,
Expand Down
2 changes: 1 addition & 1 deletion tests/features/showAnnotations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("features/showAnnotations", () => {
assert.isTrue(mergeFileLinesWithChangedFiles.calledOnce);
assert.isTrue(info.calledTwice);
assert.deepEqual(info.secondCall.args, [
`::warning file=${filename}::${line} lines are not covered with tests`
`::warning file=${filename}::${line} line is not covered with tests`
]);
});

Expand Down
15 changes: 15 additions & 0 deletions tests/input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ describe("input", () => {
);
});
});
describe("getBarecheckGithubAppToken", () => {
it("should returnvalue from getInput core function", () => {
const expectedRes = "token:124";
const getInput = sinon
.stub()
.withArgs("barecheck-github-app-token")
.returns(expectedRes);

const { getBarecheckGithubAppToken } = inputMock({ getInput });

const res = getBarecheckGithubAppToken();

assert.equal(res, expectedRes);
});
});
});

0 comments on commit 72693aa

Please sign in to comment.