Skip to content

Commit

Permalink
Releasing v1.6.1 (#59)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thsaravana authored Jul 31, 2023
1 parent 94dfcf8 commit db72e7e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 49 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 }}
Expand All @@ -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,
Expand All @@ -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 }}
Expand Down
10 changes: 10 additions & 0 deletions __tests__/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }'
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 32 additions & 23 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -18772,7 +18774,11 @@ async function action() {
)
}
} catch (error) {
core.setFailed(error)
if (continueOnError) {
core.error(error)
} else {
core.setFailed(error)
}
}
}

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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]
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 10 additions & 3 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -119,7 +121,11 @@ async function action() {
)
}
} catch (error) {
core.setFailed(error)
if (continueOnError) {
core.error(error)
} else {
core.setFailed(error)
}
}
}

Expand All @@ -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,
Expand All @@ -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,
Expand Down
38 changes: 20 additions & 18 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down

0 comments on commit db72e7e

Please sign in to comment.