Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for Multi module projects #50

Merged
merged 48 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
65e0b55
Add validation for required inputs
thsaravana Jul 23, 2023
03f18cc
Tech Debt - Adding eslint
thsaravana Jul 23, 2023
23e2b02
Tech Debt - Adding prettier and fixing existing issues
thsaravana Jul 23, 2023
a3db001
Tech Debt - Removing webpack
thsaravana Jul 23, 2023
c301c80
Tech Debt - Fixing warnings
thsaravana Jul 23, 2023
56d58c0
Tech Debt - Fixing single quote
thsaravana Jul 23, 2023
d73519c
Tech Debt - Turning off the dot-notation rule
thsaravana Jul 23, 2023
d399b61
Tech Debt - Cleaning up test file warnings
thsaravana Jul 23, 2023
f9e1102
Tech Debt - Fixing the context const issue in test files
thsaravana Jul 23, 2023
80c5d32
Send the Modules coverage information to action from process
thsaravana Jul 24, 2023
bc4b4ae
Passing coverage-changed-files from process
thsaravana Jul 24, 2023
37752cb
Adding Module table (removed files table temporarily)
thsaravana Jul 24, 2023
96a2946
Adding Files table back in
thsaravana Jul 24, 2023
a49faa0
Fixing the table formatting issues
thsaravana Jul 24, 2023
b4419c6
Fixing the Files status issue
thsaravana Jul 24, 2023
f2367a9
Render will add PR comment for Single and Multi module
thsaravana Jul 24, 2023
53e9167
Fixing the action test cases
thsaravana Jul 24, 2023
5345c33
Testing the glob pattern matching
thsaravana Jul 24, 2023
7a2a3d7
Testing the glob pattern matching
thsaravana Jul 24, 2023
575fff8
Using globSync
thsaravana Jul 24, 2023
37b3821
Logging path
thsaravana Jul 24, 2023
6b8f1ae
Filtering empty paths
thsaravana Jul 24, 2023
33ad78e
typeof check for path returned
thsaravana Jul 24, 2023
d62784f
Fixing the path type
thsaravana Jul 24, 2023
fb12b7b
Fixing the path type
thsaravana Jul 24, 2023
e581f33
Debugging the getJsonReports function
thsaravana Jul 24, 2023
faa89e8
Passing array directly to globSync
thsaravana Jul 24, 2023
eada1b7
Replacing globSync with glob
thsaravana Jul 24, 2023
f93e18a
Testing the @actions/glob
thsaravana Jul 24, 2023
b366372
Revert "Testing the @actions/glob"
thsaravana Jul 24, 2023
848a823
Revert "Replacing globSync with glob"
thsaravana Jul 24, 2023
a804e0a
Revert "Passing array directly to globSync"
thsaravana Jul 24, 2023
9de483f
Revert "Debugging the getJsonReports function"
thsaravana Jul 24, 2023
e039c82
Revert "Fixing the path type"
thsaravana Jul 24, 2023
1006fe4
Revert "typeof check for path returned"
thsaravana Jul 24, 2023
919d0cc
Revert "Filtering empty paths"
thsaravana Jul 24, 2023
5cf2f33
Revert "Logging path"
thsaravana Jul 24, 2023
a9a0936
Revert "Using globSync"
thsaravana Jul 24, 2023
ac6f5b6
Revert "Testing the glob pattern matching"
thsaravana Jul 24, 2023
f8177ac
Using @actions/glob to support wildcards in paths
thsaravana Jul 24, 2023
67465d2
Deleting webpack.config.js
thsaravana Jul 24, 2023
8f21b1f
Adding more debug logs
thsaravana Jul 24, 2023
e2df100
Running Lint in CI
thsaravana Jul 25, 2023
9635a47
Improving code coverage
thsaravana Jul 25, 2023
c51b286
Updating CI to use node16
thsaravana Jul 25, 2023
2897966
Adding test for missing cases
thsaravana Jul 25, 2023
0adc085
Updating README.md
thsaravana Jul 25, 2023
05774d6
Updating screenshots
thsaravana Jul 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/index.js
24 changes: 24 additions & 0 deletions .eslintrc.js
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'],
},
}
35 changes: 21 additions & 14 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ name: Tests

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'

- name: Run unit tests
run: |
npm install
npm test
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install
run: |
npm install

- name: Lint
run: |
npm run lint

- name: Run unit tests
run: |
npm test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/index.js
12 changes: 12 additions & 0 deletions .prettierrc.js
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
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,43 @@ 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/actions/runs/3026912615/workflow)

```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

> 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/actions/runs/3026888514/workflow)

```yaml
- name: Jacoco Report to PR
id: jacoco
uses: madrapps/jacoco-report@v1.4
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/jacoco-report@v1.4
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
```


## 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).

Expand Down
90 changes: 90 additions & 0 deletions __tests__/action.test.js
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()
})
})
Loading