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

Add ability to ignore warnings #819

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- run: ./gradlew lint
- uses: yutailang0119/action-android-lint@v3
with:
ignore-warnings: true # Ignore Lint Warnings
report-path: build/reports/*.xml # Support glob patterns by https://www.npmjs.com/package/@actions/glob
continue-on-error: false # If annotations contain error of severity, action-android-lint exit 1.
```
Expand Down
2 changes: 2 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {expect, test} from '@jest/globals'
test('test runs', () => {
process.env['INPUT_REPORT-PATH'] = path.join(__dirname, 'resource', '*.xml')
process.env['INPUT_FOLLOW-SYMBOLIC-LINKS'] = 'true'
process.env['INPUT_IGNORE-WARNINGS'] = 'false'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
Expand All @@ -30,6 +31,7 @@ test('test runs without error', () => {
'empty-results.xml'
)
process.env['INPUT_FOLLOW-SYMBOLIC-LINKS'] = 'true'
process.env['INPUT_IGNORE-WARNINGS'] = 'false'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
Expand Down
21 changes: 18 additions & 3 deletions __tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ test('test parseXmls', () => {
44
)

expect(parseXmls([file1, file2])).resolves.toEqual([annotation1, annotation2])
expect(parseXmls([file1, file2], false)).resolves.toEqual([annotation1, annotation2])
})

test('test parseXmls and ignore warnings', () => {
const file1 = path.join(__dirname, 'resource', 'lint-results.xml')
const file2 = path.join(__dirname, 'resource', 'empty-results.xml')

const annotation2 = new Annotation(
'Error',
'Ignoring results: The result of `subscribe` is not used',
'Foo.kt',
33,
44
)

expect(parseXmls([file1, file2], true)).resolves.toEqual([annotation2])
})

test('test parseXml with issues', () => {
Expand Down Expand Up @@ -52,13 +67,13 @@ test('test parseXml with issues', () => {
44
)

expect(parseXml(xml)).resolves.toEqual([annotation])
expect(parseXml(xml, false)).resolves.toEqual([annotation])
})

test('test parseXml without issue', () => {
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 7.2.1">
</issues>`

expect(parseXml(xml)).resolves.toEqual([])
expect(parseXml(xml, false)).resolves.toEqual([])
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
follow-symbolic-links:
description: 'Indicates whether to follow symbolic links'
default: true
ignore-warnings:
description: 'Ignore Lint Warnings'
default: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
48 changes: 31 additions & 17 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {parseXmls} from './parser'
async function run(): Promise<void> {
try {
const reportPath = core.getInput('report-path', {required: true})
const ignoreWarnings = core.getBooleanInput('ignore-warnings')
const globOptions = {
followSymbolicLinks: core.getBooleanInput('follow-symbolic-links')
}
const globber = await glob.create(reportPath, globOptions)
const files = await globber.glob()

const annotations = await parseXmls(files)
const annotations = await parseXmls(files, ignoreWarnings)

echoMessages(annotations)

Expand Down
15 changes: 12 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import * as core from '@actions/core'
import * as xml2js from 'xml2js'
import {Annotation} from './annotation'

export const parseXmls = async (files: string[]): Promise<Annotation[]> => {
export const parseXmls = async (
files: string[],
ignoreWarnings: boolean
): Promise<Annotation[]> => {
const list = await Promise.all(
files.map(async file => {
const xml = fs.readFileSync(file, 'utf-8')
return await parseXml(xml)
return await parseXml(xml, ignoreWarnings)
})
)
return list.flat()
}

export const parseXml = async (text: string): Promise<Annotation[]> => {
export const parseXml = async (
text: string,
ignoreWarnings: boolean
): Promise<Annotation[]> => {
const parser = new xml2js.Parser()
const xml = await parser.parseStringPromise(text)
if (xml.issues.issue === undefined) return []
Expand All @@ -22,6 +28,9 @@ export const parseXml = async (text: string): Promise<Annotation[]> => {
const annotations: Annotation[] = []
for (const issueElement of xml.issues.issue) {
const issue = issueElement.$
if (ignoreWarnings === true && issue.severity !== 'Error') {
continue;
}
for (const locationElement of issueElement.location) {
const location = locationElement.$

Expand Down
Loading