-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full support for Multi module projects (#50)
* Add validation for required inputs * Tech Debt - Adding eslint * Tech Debt - Adding prettier and fixing existing issues * Tech Debt - Removing webpack * Tech Debt - Fixing warnings * Tech Debt - Fixing single quote * Tech Debt - Turning off the dot-notation rule * Tech Debt - Cleaning up test file warnings * Tech Debt - Fixing the context const issue in test files * Send the Modules coverage information to action from process * Passing coverage-changed-files from process * Adding Module table (removed files table temporarily) * Adding Files table back in * Fixing the table formatting issues * Fixing the Files status issue * Render will add PR comment for Single and Multi module * Fixing the action test cases * Testing the glob pattern matching * Testing the glob pattern matching * Using globSync * Logging path * Filtering empty paths * typeof check for path returned * Fixing the path type * Fixing the path type * Debugging the getJsonReports function * Passing array directly to globSync * Replacing globSync with glob * Testing the @actions/glob * Revert "Testing the @actions/glob" This reverts commit f93e18a. * Revert "Replacing globSync with glob" This reverts commit eada1b7. * Revert "Passing array directly to globSync" This reverts commit faa89e8. * Revert "Debugging the getJsonReports function" This reverts commit e581f33. * Revert "Fixing the path type" This reverts commit d62784f. * Revert "typeof check for path returned" This reverts commit 33ad78e * Revert "Filtering empty paths" This reverts commit 6b8f1ae. * Revert "Logging path" This reverts commit 37b3821. * Revert "Using globSync" This reverts commit 575fff8. * Revert "Testing the glob pattern matching" This reverts commit 5345c33. * Using @actions/glob to support wildcards in paths * Deleting webpack.config.js * Adding more debug logs * Running Lint in CI * Improving code coverage * Updating CI to use node16 * Adding test for missing cases * Updating README.md * Updating screenshots
- Loading branch information
1 parent
9a2d796
commit 4a4edd0
Showing
26 changed files
with
14,152 additions
and
6,689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
es2021: true, | ||
jest: true, | ||
jasmine: true, | ||
}, | ||
extends: ['standard', 'prettier'], | ||
overrides: [ | ||
{ | ||
files: ['.eslintrc.{js, cjs}'], | ||
}, | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: true, | ||
}, | ||
rules: { | ||
quotes: ['error', 'single', { avoidEscape: true }], | ||
'no-var': ['error'], | ||
'dot-notation': ['off'], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs | ||
|
||
/** @type {import("prettier").Options} */ | ||
const config = { | ||
trailingComma: 'es5', | ||
tabWidth: 2, | ||
semi: false, | ||
singleQuote: true, | ||
useTabs: false, | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a | |
|
||
### Inputs | ||
|
||
- `paths` - [**required**] Comma separated paths of the generated jacoco xml files | ||
- `paths` - [**required**] Comma separated paths of the generated jacoco xml files (supports wildcard glob pattern) | ||
- `token` - [**required**] Github personal token to add commits to Pull Request | ||
- `min-coverage-overall` - [*optional*] The minimum code coverage that is required to pass for overall project | ||
- `min-coverage-changed-files` - [*optional*] The minimum code coverage that is required to pass for changed files | ||
|
@@ -25,6 +25,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a | |
- `title` - [*optional*] Title for the Pull Request comment | ||
- `skip-if-no-changes` - [*optional*] If true, comment won't be added if there is no coverage information present for | ||
the files changed | ||
- `debug-mode` - [*optional*] If true, run the action in debug mode and get debug logs printed in console | ||
|
||
### Outputs | ||
|
||
|
@@ -59,14 +60,18 @@ jobs: | |
id: jacoco | ||
uses: madrapps/[email protected] | ||
with: | ||
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml | ||
paths: | | ||
${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, | ||
${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
min-coverage-overall: 40 | ||
min-coverage-changed-files: 60 | ||
``` | ||
<br> | ||
<img src="/preview/screenshot.png" alt="output screenshot" title="output screenshot" width="500" /> | ||
<img src="/preview/single-module-screenshot.png" alt="single module screenshot" title="single module screenshot" width="500" /> | ||
<br> | ||
<img src="/preview/multi-module-screenshot.png" alt="multi-module screenshot" title="multi-module screenshot" width="500" /> | ||
### Example Project | ||
|
@@ -78,42 +83,65 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p | |
## Example Cases | ||
1. If you want to fail your workflow when the minimum coverage is not met | ||
> You can write an additional step that uses | ||
the Outputs for the jacoco-report action and fail the workflow. | ||
Refer [sample pull request](https://github.com/thsaravana/jacoco-playground/pull/16) and | ||
its [workflow](https://github.com/thsaravana/jacoco-playground/actions/runs/3026912615/workflow) | ||
> the Outputs for the jacoco-report action and fail the workflow. | ||
> Refer [sample pull request](https://github.com/thsaravana/jacoco-playground/pull/16) and | ||
> its [workflow](https://github.com/thsaravana/jacoco-playground/blob/pr-failure-on-threshold/.github/workflows/coverage.yml) | ||
```yaml | ||
- name: Fail PR if overall coverage is less than 80% | ||
if: ${{ steps.jacoco.outputs.coverage-overall < 80.0 }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed('Overall coverage is less than 80%!') | ||
- name: Fail PR if overall coverage is less than 80% | ||
if: ${{ steps.jacoco.outputs.coverage-overall < 80.0 }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed('Overall coverage is less than 80%!') | ||
``` | ||
2. If you don't want to add the coverage comment everytime you push a commit to a pull request, but update the existing coverage comment instead | ||
2. If you don't want to add the coverage comment everytime you push a commit to a pull request, but update the existing | ||
coverage comment instead | ||
> Set the `update-comment` input to true and also set a `title` input. | ||
Refer [sample pull request](https://github.com/thsaravana/jacoco-playground/pull/15) and | ||
its [workflow](https://github.com/thsaravana/jacoco-playground/actions/runs/3026888514/workflow) | ||
> Refer [sample pull request](https://github.com/thsaravana/jacoco-playground/pull/15) and | ||
> its [workflow](https://github.com/thsaravana/jacoco-playground/blob/update-comment/.github/workflows/coverage.yml) | ||
|
||
```yaml | ||
- name: Jacoco Report to PR | ||
id: jacoco | ||
uses: madrapps/[email protected] | ||
with: | ||
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
min-coverage-overall: 40 | ||
min-coverage-changed-files: 60 | ||
title: Code Coverage | ||
update-comment: true | ||
- name: Jacoco Report to PR | ||
id: jacoco | ||
uses: madrapps/[email protected] | ||
with: | ||
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
min-coverage-overall: 40 | ||
min-coverage-changed-files: 60 | ||
title: Code Coverage | ||
update-comment: true | ||
``` | ||
|
||
3. If you have a multi-module project like `android`, with multiple modules each with its own jacoco report | ||
|
||
> Set the `paths` input with wildcard glob pattern (as shown in the Example workflow). This will pick all the files | ||
> matching the pattern. Ensure your pattern matches only one report per module, since for the same module, you could | ||
> have `debugCoverage.xml` and `releaseCoverage.xml`. | ||
> Refer [sample pull request](https://github.com/thsaravana/jacoco-android-playground/pull/9) and | ||
> its [workflow](https://github.com/thsaravana/jacoco-android-playground/blob/testing-multi-module-support/.github/workflows/coverage.yml) | ||
|
||
```yaml | ||
- name: Jacoco Report to PR | ||
id: jacoco | ||
uses: madrapps/jacoco-report@multi-module-support | ||
with: | ||
paths: | | ||
${{ github.workspace }}/**/build/reports/jacoco/**/prodNormalDebugCoverage.xml, | ||
${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
min-coverage-overall: 40 | ||
min-coverage-changed-files: 60 | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
1. If the PR is created by bots like *dependabot*, then the GITHUB_TOKEN won't have sufficient access to write the | ||
1. If the PR is created by bots like _dependabot_, then the GITHUB_TOKEN won't have sufficient access to write the | ||
coverage comment. So add the appropriate permission to your job (as shown in the Example workflow). More information | ||
[here](https://github.com/Madrapps/jacoco-report/issues/24). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const action = require('../src/action') | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
|
||
jest.mock('@actions/core') | ||
jest.mock('@actions/github') | ||
|
||
describe('Input validation', function () { | ||
function getInput(key) { | ||
switch (key) { | ||
case 'paths': | ||
return './__tests__/__fixtures__/report.xml' | ||
case 'token': | ||
return 'SMPLEHDjasdf876a987' | ||
} | ||
} | ||
|
||
const createComment = jest.fn() | ||
const listComments = jest.fn() | ||
const updateComment = jest.fn() | ||
|
||
core.getInput = jest.fn(getInput) | ||
github.getOctokit = jest.fn(() => { | ||
return { | ||
repos: { | ||
compareCommits: jest.fn(() => { | ||
return { | ||
data: { | ||
files: [ | ||
{ | ||
filename: 'src/main/kotlin/com/madrapps/jacoco/Math.kt', | ||
blob_url: | ||
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt', | ||
}, | ||
{ | ||
filename: | ||
'src/main/java/com/madrapps/jacoco/operation/StringOp.java', | ||
blob_url: | ||
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java', | ||
}, | ||
], | ||
}, | ||
} | ||
}), | ||
}, | ||
issues: { | ||
createComment, | ||
listComments, | ||
updateComment, | ||
}, | ||
} | ||
}) | ||
core.setFailed = jest.fn((c) => { | ||
fail(c) | ||
}) | ||
|
||
it('Fail if paths is not present', async () => { | ||
core.getInput = jest.fn((c) => { | ||
switch (c) { | ||
case 'paths': | ||
return '' | ||
default: | ||
return getInput(c) | ||
} | ||
}) | ||
github.context.eventName = 'pull_request' | ||
|
||
core.setFailed = jest.fn((c) => { | ||
expect(c).toEqual("'paths' is missing") | ||
}) | ||
await action.action() | ||
}) | ||
|
||
it('Fail if token is not present', async () => { | ||
core.getInput = jest.fn((c) => { | ||
switch (c) { | ||
case 'token': | ||
return '' | ||
default: | ||
return getInput(c) | ||
} | ||
}) | ||
github.context.eventName = 'pull_request' | ||
|
||
core.setFailed = jest.fn((c) => { | ||
expect(c).toEqual("'token' is missing") | ||
}) | ||
await action.action() | ||
}) | ||
}) |
Oops, something went wrong.