Skip to content

Commit db72e7e

Browse files
authored
Releasing v1.6.1 (#59)
* Adding logs to check the file.patch availability * Using debug to log * Do not fail but just log * Try logging as error * Fail when continueOnError is false * Validate file.patch before parsing * Setting release to 1.6.1
1 parent 94dfcf8 commit db72e7e

File tree

7 files changed

+82
-49
lines changed

7 files changed

+82
-49
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a
2727
the files changed
2828
- `pass-emoji` - [*optional* {default: :green_apple:}] Emoji to use for pass status shown when 'coverage >= min coverage' (should be a Github supported emoji).
2929
- `fail-emoji` - [*optional* {default: :x:}] Emoji to use for fail status shown when 'coverage < min coverage' (should be a Github supported emoji).
30+
- `continue-on-error` - [*optional* {default: true}] If true, then do not fail the action on error, but log a warning
3031
- `debug-mode` - [*optional* {default: false}] If true, run the action in debug mode and get debug logs printed in console
3132

3233
### Outputs
@@ -60,7 +61,7 @@ jobs:
6061
6162
- name: Add coverage to PR
6263
id: jacoco
63-
uses: madrapps/[email protected]
64+
uses: madrapps/[email protected].1
6465
with:
6566
paths: |
6667
${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml,
@@ -110,7 +111,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
110111
```yaml
111112
- name: Jacoco Report to PR
112113
id: jacoco
113-
uses: madrapps/[email protected]
114+
uses: madrapps/[email protected].1
114115
with:
115116
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
116117
token: ${{ secrets.GITHUB_TOKEN }}
@@ -131,7 +132,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
131132
```yaml
132133
- name: Jacoco Report to PR
133134
id: jacoco
134-
uses: madrapps/[email protected]
135+
uses: madrapps/[email protected].1
135136
with:
136137
paths: |
137138
${{ github.workspace }}/**/build/reports/jacoco/**/prodNormalDebugCoverage.xml,
@@ -151,7 +152,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
151152
```yaml
152153
- name: Jacoco Report to PR
153154
id: jacoco
154-
uses: madrapps/[email protected]
155+
uses: madrapps/[email protected].1
155156
with:
156157
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
157158
token: ${{ secrets.GITHUB_TOKEN }}

__tests__/util.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ jest.mock('@actions/github')
77

88
describe('Util', function () {
99
describe('getChangedLines', function () {
10+
it('when patch is null', async () => {
11+
const changedLines = util.getChangedLines(null)
12+
expect(changedLines).toEqual([])
13+
})
14+
15+
it('when patch is invalid', async () => {
16+
const changedLines = util.getChangedLines('invalid-patch')
17+
expect(changedLines).toEqual([])
18+
})
19+
1020
it('multiple consecutive lines', async () => {
1121
const patch =
1222
'@@ -18,6 +18,10 @@ class Arithmetic : MathOperation {\n return a / b\n }\n \n+ override fun difference(a: Int, b: Int): Int {\n+ return subtract(a, b)\n+ }\n+\n fun modulo(a: Int, b: Int): Int {\n return a % b\n }'

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ inputs:
3434
description: 'Github emoji to use for fail status shown when coverage lesser than min coverage (should be a Github supported emoji)'
3535
required: false
3636
default: ':x:'
37+
continue-on-error:
38+
description: 'When there is an error do not fail the action, but log a warning'
39+
required: false
40+
default: 'true'
3741
debug-mode:
3842
description: 'Run the action in debug mode and get debug logs printed in console'
3943
required: false

dist/index.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -18662,6 +18662,7 @@ const { debug, getChangedLines } = __nccwpck_require__(683)
1866218662
const glob = __nccwpck_require__(6562)
1866318663

1866418664
async function action() {
18665+
let continueOnError = true
1866518666
try {
1866618667
const token = core.getInput('token')
1866718668
if (!token) {
@@ -18692,6 +18693,7 @@ async function action() {
1869218693
const passEmoji = core.getInput('pass-emoji')
1869318694
const failEmoji = core.getInput('fail-emoji')
1869418695

18696+
continueOnError = parseBooleans(core.getInput('continue-on-error'))
1869518697
const debugMode = parseBooleans(core.getInput('debug-mode'))
1869618698

1869718699
const event = github.context.eventName
@@ -18729,7 +18731,7 @@ async function action() {
1872918731

1873018732
if (debugMode) core.info(`reportPaths: ${reportPaths}`)
1873118733
const reportsJsonAsync = getJsonReports(reportPaths, debugMode)
18732-
const changedFiles = await getChangedFiles(base, head, client)
18734+
const changedFiles = await getChangedFiles(base, head, client, debugMode)
1873318735
if (debugMode) core.info(`changedFiles: ${debug(changedFiles)}`)
1873418736

1873518737
const reportsJson = await reportsJsonAsync
@@ -18772,7 +18774,11 @@ async function action() {
1877218774
)
1877318775
}
1877418776
} catch (error) {
18775-
core.setFailed(error)
18777+
if (continueOnError) {
18778+
core.error(error)
18779+
} else {
18780+
core.setFailed(error)
18781+
}
1877618782
}
1877718783
}
1877818784

@@ -18789,7 +18795,7 @@ async function getJsonReports(xmlPaths, debugMode) {
1878918795
)
1879018796
}
1879118797

18792-
async function getChangedFiles(base, head, client) {
18798+
async function getChangedFiles(base, head, client, debugMode) {
1879318799
const response = await client.rest.repos.compareCommits({
1879418800
base,
1879518801
head,
@@ -18799,6 +18805,7 @@ async function getChangedFiles(base, head, client) {
1879918805

1880018806
const changedFiles = []
1880118807
response.data.files.forEach((file) => {
18808+
if (debugMode) core.info(`file: ${debug(file)}`)
1880218809
const changedFile = {
1880318810
filePath: file.filename,
1880418811
url: file.blob_url,
@@ -19306,28 +19313,30 @@ function debug(obj) {
1930619313
const pattern = /^@@ -([0-9]*),?\S* \+([0-9]*),?/
1930719314

1930819315
function getChangedLines(patch) {
19309-
const lines = patch.split('\n')
19310-
const groups = getDiffGroups(lines)
1931119316
const lineNumbers = new Set()
19312-
groups.forEach((group) => {
19313-
const firstLine = group.shift()
19314-
if (firstLine) {
19315-
const diffGroup = firstLine.match(pattern)
19316-
if (diffGroup) {
19317-
let bX = parseInt(diffGroup[2])
19318-
19319-
group.forEach((line) => {
19320-
bX++
19321-
19322-
if (line.startsWith('+')) {
19323-
lineNumbers.add(bX - 1)
19324-
} else if (line.startsWith('-')) {
19325-
bX--
19326-
}
19327-
})
19317+
if (patch) {
19318+
const lines = patch.split('\n')
19319+
const groups = getDiffGroups(lines)
19320+
groups.forEach((group) => {
19321+
const firstLine = group.shift()
19322+
if (firstLine) {
19323+
const diffGroup = firstLine.match(pattern)
19324+
if (diffGroup) {
19325+
let bX = parseInt(diffGroup[2])
19326+
19327+
group.forEach((line) => {
19328+
bX++
19329+
19330+
if (line.startsWith('+')) {
19331+
lineNumbers.add(bX - 1)
19332+
} else if (line.startsWith('-')) {
19333+
bX--
19334+
}
19335+
})
19336+
}
1932819337
}
19329-
}
19330-
})
19338+
})
19339+
}
1933119340
return [...lineNumbers]
1933219341
}
1933319342

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jacoco-report",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Github action that publishes the JaCoCo report as a comment in the Pull Request",
55
"main": "index.js",
66
"scripts": {

src/action.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { debug, getChangedLines } = require('./util')
99
const glob = require('@actions/glob')
1010

1111
async function action() {
12+
let continueOnError = true
1213
try {
1314
const token = core.getInput('token')
1415
if (!token) {
@@ -39,6 +40,7 @@ async function action() {
3940
const passEmoji = core.getInput('pass-emoji')
4041
const failEmoji = core.getInput('fail-emoji')
4142

43+
continueOnError = parseBooleans(core.getInput('continue-on-error'))
4244
const debugMode = parseBooleans(core.getInput('debug-mode'))
4345

4446
const event = github.context.eventName
@@ -76,7 +78,7 @@ async function action() {
7678

7779
if (debugMode) core.info(`reportPaths: ${reportPaths}`)
7880
const reportsJsonAsync = getJsonReports(reportPaths, debugMode)
79-
const changedFiles = await getChangedFiles(base, head, client)
81+
const changedFiles = await getChangedFiles(base, head, client, debugMode)
8082
if (debugMode) core.info(`changedFiles: ${debug(changedFiles)}`)
8183

8284
const reportsJson = await reportsJsonAsync
@@ -119,7 +121,11 @@ async function action() {
119121
)
120122
}
121123
} catch (error) {
122-
core.setFailed(error)
124+
if (continueOnError) {
125+
core.error(error)
126+
} else {
127+
core.setFailed(error)
128+
}
123129
}
124130
}
125131

@@ -136,7 +142,7 @@ async function getJsonReports(xmlPaths, debugMode) {
136142
)
137143
}
138144

139-
async function getChangedFiles(base, head, client) {
145+
async function getChangedFiles(base, head, client, debugMode) {
140146
const response = await client.rest.repos.compareCommits({
141147
base,
142148
head,
@@ -146,6 +152,7 @@ async function getChangedFiles(base, head, client) {
146152

147153
const changedFiles = []
148154
response.data.files.forEach((file) => {
155+
if (debugMode) core.info(`file: ${debug(file)}`)
149156
const changedFile = {
150157
filePath: file.filename,
151158
url: file.blob_url,

src/util.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ function debug(obj) {
1414
const pattern = /^@@ -([0-9]*),?\S* \+([0-9]*),?/
1515

1616
function getChangedLines(patch) {
17-
const lines = patch.split('\n')
18-
const groups = getDiffGroups(lines)
1917
const lineNumbers = new Set()
20-
groups.forEach((group) => {
21-
const firstLine = group.shift()
22-
if (firstLine) {
23-
const diffGroup = firstLine.match(pattern)
24-
if (diffGroup) {
25-
let bX = parseInt(diffGroup[2])
18+
if (patch) {
19+
const lines = patch.split('\n')
20+
const groups = getDiffGroups(lines)
21+
groups.forEach((group) => {
22+
const firstLine = group.shift()
23+
if (firstLine) {
24+
const diffGroup = firstLine.match(pattern)
25+
if (diffGroup) {
26+
let bX = parseInt(diffGroup[2])
2627

27-
group.forEach((line) => {
28-
bX++
28+
group.forEach((line) => {
29+
bX++
2930

30-
if (line.startsWith('+')) {
31-
lineNumbers.add(bX - 1)
32-
} else if (line.startsWith('-')) {
33-
bX--
34-
}
35-
})
31+
if (line.startsWith('+')) {
32+
lineNumbers.add(bX - 1)
33+
} else if (line.startsWith('-')) {
34+
bX--
35+
}
36+
})
37+
}
3638
}
37-
}
38-
})
39+
})
40+
}
3941
return [...lineNumbers]
4042
}
4143

0 commit comments

Comments
 (0)