From db72e7e7c96f98d239967958b0a0a6ca7d3bb45f Mon Sep 17 00:00:00 2001
From: Saravana
Date: Mon, 31 Jul 2023 14:29:18 +0200
Subject: [PATCH] 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
---
README.md | 9 ++++---
__tests__/util.test.js | 10 ++++++++
action.yml | 4 +++
dist/index.js | 55 ++++++++++++++++++++++++------------------
package.json | 2 +-
src/action.js | 13 +++++++---
src/util.js | 38 +++++++++++++++--------------
7 files changed, 82 insertions(+), 49 deletions(-)
diff --git a/README.md b/README.md
index c1f5f51..8505547 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ for [Creating a workflow file](https://help.github.com/en/articles/configuring-a
the files changed
- `pass-emoji` - [*optional* {default: :green_apple:}] Emoji to use for pass status shown when 'coverage >= min coverage' (should be a Github supported emoji).
- `fail-emoji` - [*optional* {default: :x:}] Emoji to use for fail status shown when 'coverage < min coverage' (should be a Github supported emoji).
+- `continue-on-error` - [*optional* {default: true}] If true, then do not fail the action on error, but log a warning
- `debug-mode` - [*optional* {default: false}] If true, run the action in debug mode and get debug logs printed in console
### Outputs
@@ -60,7 +61,7 @@ jobs:
- name: Add coverage to PR
id: jacoco
- uses: madrapps/jacoco-report@v1.6
+ uses: madrapps/jacoco-report@v1.6.1
with:
paths: |
${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml,
@@ -110,7 +111,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
```yaml
- name: Jacoco Report to PR
id: jacoco
- uses: madrapps/jacoco-report@v1.6
+ uses: madrapps/jacoco-report@v1.6.1
with:
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
@@ -131,7 +132,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
```yaml
- name: Jacoco Report to PR
id: jacoco
- uses: madrapps/jacoco-report@v1.6
+ uses: madrapps/jacoco-report@v1.6.1
with:
paths: |
${{ github.workspace }}/**/build/reports/jacoco/**/prodNormalDebugCoverage.xml,
@@ -151,7 +152,7 @@ refer [jacoco-android-playground](https://github.com/thsaravana/jacoco-android-p
```yaml
- name: Jacoco Report to PR
id: jacoco
- uses: madrapps/jacoco-report@v1.6
+ uses: madrapps/jacoco-report@v1.6.1
with:
paths: ${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
diff --git a/__tests__/util.test.js b/__tests__/util.test.js
index fb4440f..a718c9d 100644
--- a/__tests__/util.test.js
+++ b/__tests__/util.test.js
@@ -7,6 +7,16 @@ jest.mock('@actions/github')
describe('Util', function () {
describe('getChangedLines', function () {
+ it('when patch is null', async () => {
+ const changedLines = util.getChangedLines(null)
+ expect(changedLines).toEqual([])
+ })
+
+ it('when patch is invalid', async () => {
+ const changedLines = util.getChangedLines('invalid-patch')
+ expect(changedLines).toEqual([])
+ })
+
it('multiple consecutive lines', async () => {
const patch =
'@@ -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 }'
diff --git a/action.yml b/action.yml
index c4ce80d..e95f18b 100644
--- a/action.yml
+++ b/action.yml
@@ -34,6 +34,10 @@ inputs:
description: 'Github emoji to use for fail status shown when coverage lesser than min coverage (should be a Github supported emoji)'
required: false
default: ':x:'
+ continue-on-error:
+ description: 'When there is an error do not fail the action, but log a warning'
+ required: false
+ default: 'true'
debug-mode:
description: 'Run the action in debug mode and get debug logs printed in console'
required: false
diff --git a/dist/index.js b/dist/index.js
index d4ee967..d1ba233 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -18662,6 +18662,7 @@ const { debug, getChangedLines } = __nccwpck_require__(683)
const glob = __nccwpck_require__(6562)
async function action() {
+ let continueOnError = true
try {
const token = core.getInput('token')
if (!token) {
@@ -18692,6 +18693,7 @@ async function action() {
const passEmoji = core.getInput('pass-emoji')
const failEmoji = core.getInput('fail-emoji')
+ continueOnError = parseBooleans(core.getInput('continue-on-error'))
const debugMode = parseBooleans(core.getInput('debug-mode'))
const event = github.context.eventName
@@ -18729,7 +18731,7 @@ async function action() {
if (debugMode) core.info(`reportPaths: ${reportPaths}`)
const reportsJsonAsync = getJsonReports(reportPaths, debugMode)
- const changedFiles = await getChangedFiles(base, head, client)
+ const changedFiles = await getChangedFiles(base, head, client, debugMode)
if (debugMode) core.info(`changedFiles: ${debug(changedFiles)}`)
const reportsJson = await reportsJsonAsync
@@ -18772,7 +18774,11 @@ async function action() {
)
}
} catch (error) {
- core.setFailed(error)
+ if (continueOnError) {
+ core.error(error)
+ } else {
+ core.setFailed(error)
+ }
}
}
@@ -18789,7 +18795,7 @@ async function getJsonReports(xmlPaths, debugMode) {
)
}
-async function getChangedFiles(base, head, client) {
+async function getChangedFiles(base, head, client, debugMode) {
const response = await client.rest.repos.compareCommits({
base,
head,
@@ -18799,6 +18805,7 @@ async function getChangedFiles(base, head, client) {
const changedFiles = []
response.data.files.forEach((file) => {
+ if (debugMode) core.info(`file: ${debug(file)}`)
const changedFile = {
filePath: file.filename,
url: file.blob_url,
@@ -19306,28 +19313,30 @@ function debug(obj) {
const pattern = /^@@ -([0-9]*),?\S* \+([0-9]*),?/
function getChangedLines(patch) {
- const lines = patch.split('\n')
- const groups = getDiffGroups(lines)
const lineNumbers = new Set()
- groups.forEach((group) => {
- const firstLine = group.shift()
- if (firstLine) {
- const diffGroup = firstLine.match(pattern)
- if (diffGroup) {
- let bX = parseInt(diffGroup[2])
-
- group.forEach((line) => {
- bX++
-
- if (line.startsWith('+')) {
- lineNumbers.add(bX - 1)
- } else if (line.startsWith('-')) {
- bX--
- }
- })
+ if (patch) {
+ const lines = patch.split('\n')
+ const groups = getDiffGroups(lines)
+ groups.forEach((group) => {
+ const firstLine = group.shift()
+ if (firstLine) {
+ const diffGroup = firstLine.match(pattern)
+ if (diffGroup) {
+ let bX = parseInt(diffGroup[2])
+
+ group.forEach((line) => {
+ bX++
+
+ if (line.startsWith('+')) {
+ lineNumbers.add(bX - 1)
+ } else if (line.startsWith('-')) {
+ bX--
+ }
+ })
+ }
}
- }
- })
+ })
+ }
return [...lineNumbers]
}
diff --git a/package.json b/package.json
index cd8a210..7f72f27 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jacoco-report",
- "version": "1.6.0",
+ "version": "1.6.1",
"description": "Github action that publishes the JaCoCo report as a comment in the Pull Request",
"main": "index.js",
"scripts": {
diff --git a/src/action.js b/src/action.js
index 405d539..769bff6 100644
--- a/src/action.js
+++ b/src/action.js
@@ -9,6 +9,7 @@ const { debug, getChangedLines } = require('./util')
const glob = require('@actions/glob')
async function action() {
+ let continueOnError = true
try {
const token = core.getInput('token')
if (!token) {
@@ -39,6 +40,7 @@ async function action() {
const passEmoji = core.getInput('pass-emoji')
const failEmoji = core.getInput('fail-emoji')
+ continueOnError = parseBooleans(core.getInput('continue-on-error'))
const debugMode = parseBooleans(core.getInput('debug-mode'))
const event = github.context.eventName
@@ -76,7 +78,7 @@ async function action() {
if (debugMode) core.info(`reportPaths: ${reportPaths}`)
const reportsJsonAsync = getJsonReports(reportPaths, debugMode)
- const changedFiles = await getChangedFiles(base, head, client)
+ const changedFiles = await getChangedFiles(base, head, client, debugMode)
if (debugMode) core.info(`changedFiles: ${debug(changedFiles)}`)
const reportsJson = await reportsJsonAsync
@@ -119,7 +121,11 @@ async function action() {
)
}
} catch (error) {
- core.setFailed(error)
+ if (continueOnError) {
+ core.error(error)
+ } else {
+ core.setFailed(error)
+ }
}
}
@@ -136,7 +142,7 @@ async function getJsonReports(xmlPaths, debugMode) {
)
}
-async function getChangedFiles(base, head, client) {
+async function getChangedFiles(base, head, client, debugMode) {
const response = await client.rest.repos.compareCommits({
base,
head,
@@ -146,6 +152,7 @@ async function getChangedFiles(base, head, client) {
const changedFiles = []
response.data.files.forEach((file) => {
+ if (debugMode) core.info(`file: ${debug(file)}`)
const changedFile = {
filePath: file.filename,
url: file.blob_url,
diff --git a/src/util.js b/src/util.js
index bc3a539..88a155b 100644
--- a/src/util.js
+++ b/src/util.js
@@ -14,28 +14,30 @@ function debug(obj) {
const pattern = /^@@ -([0-9]*),?\S* \+([0-9]*),?/
function getChangedLines(patch) {
- const lines = patch.split('\n')
- const groups = getDiffGroups(lines)
const lineNumbers = new Set()
- groups.forEach((group) => {
- const firstLine = group.shift()
- if (firstLine) {
- const diffGroup = firstLine.match(pattern)
- if (diffGroup) {
- let bX = parseInt(diffGroup[2])
+ if (patch) {
+ const lines = patch.split('\n')
+ const groups = getDiffGroups(lines)
+ groups.forEach((group) => {
+ const firstLine = group.shift()
+ if (firstLine) {
+ const diffGroup = firstLine.match(pattern)
+ if (diffGroup) {
+ let bX = parseInt(diffGroup[2])
- group.forEach((line) => {
- bX++
+ group.forEach((line) => {
+ bX++
- if (line.startsWith('+')) {
- lineNumbers.add(bX - 1)
- } else if (line.startsWith('-')) {
- bX--
- }
- })
+ if (line.startsWith('+')) {
+ lineNumbers.add(bX - 1)
+ } else if (line.startsWith('-')) {
+ bX--
+ }
+ })
+ }
}
- }
- })
+ })
+ }
return [...lineNumbers]
}