Skip to content

Commit c8f7c41

Browse files
authored
Merge pull request #5 from hidakatsuya/always-show-the-report
Always report lint results to Job Summaries
2 parents d77f20c + e515fb3 commit c8f7c41

File tree

11 files changed

+387
-159
lines changed

11 files changed

+387
-159
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- run: npm test
1313

1414
# test action works running from the graph
15-
test:
15+
action-test-success:
1616
runs-on: ubuntu-latest
1717

1818
env:
@@ -23,13 +23,23 @@ jobs:
2323
- uses: ./
2424
with:
2525
result-path: "__tests__/xml/success*.xml"
26-
ignore-warning: false
26+
27+
action-test-success-with-warnings:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v3
2732
- uses: ./
2833
with:
2934
result-path: "__tests__/xml/failure2.xml"
30-
ignore-warning: true
35+
fail-on-warning: false
36+
37+
action-test-error:
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v3
3142
- uses: ./
32-
if: env.RUN_FAILURE_TEST == 'true'
3343
with:
3444
result-path: "__tests__/xml/failure*.xml"
35-
ignore-warning: false
45+
continue-on-error: true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Alternatively, you can specify a major version, such as `hidakatsuya/action-repo
2525
Indicates the relative path from the working directory to Android Lint result XML file.
2626
Path patterns by [@actions/glob](https://www.npmjs.com/package/@actions/glob) can also be specified.
2727

28-
### ignore-warning (optional)
28+
### fail-on-warning (optional)
2929

30-
Indicates whether warnings should be ignored as build failures. Default is `false`.
30+
Indicates whether the action should fail if there is a severity warning issue. Default is `true`.
3131

3232
### follow-symbolic-links (optional)
3333

__tests__/check.test.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const { check } = require("../src/check")
22
const path = require("path")
33

44
describe("single XML file", () => {
5-
test("when the result is success", async () => {
5+
test("when the results is success", async () => {
66
const results = await check({ pathPattern: path.join(__dirname, "xml/success1.xml") })
77

8-
expect(results.isPassed).toBe(true)
8+
expect(results.status).toEqual("success")
99
expect(results.failures.length).toEqual(0)
1010
expect(results.results.length).toEqual(1)
1111

@@ -16,15 +16,16 @@ describe("single XML file", () => {
1616
expect(result.warnings.length).toEqual(0)
1717
})
1818

19-
test("when the result is failure", async () => {
19+
test("when the results is error including warning", async () => {
2020
const results = await check({ pathPattern: path.join(__dirname, "xml/failure1.xml") })
2121

22-
expect(results.isPassed).toBe(false)
22+
expect(results.status).toEqual("error")
2323
expect(results.failures.length).toEqual(1)
2424
expect(results.results.length).toEqual(1)
2525

2626
const { result } = results.results[0]
2727

28+
expect(result.status).toEqual("error")
2829
expect(result.issues.length).toEqual(2)
2930

3031
expect(result.warnings.length).toEqual(1)
@@ -33,21 +34,39 @@ describe("single XML file", () => {
3334
expect(result.errors.length).toEqual(1)
3435
expect(result.errors[0].message).toMatch("The resource `R.color.purple_500` appears to be unused")
3536
})
37+
38+
test("when the results is warning only", async () => {
39+
const results = await check({ pathPattern: path.join(__dirname, "xml/failure2.xml") })
40+
41+
expect(results.status).toEqual("warning")
42+
expect(results.failures.length).toEqual(1)
43+
expect(results.results.length).toEqual(1)
44+
45+
const { result } = results.results[0]
46+
47+
expect(result.status).toEqual("warning")
48+
expect(result.issues.length).toEqual(1)
49+
50+
expect(result.warnings.length).toEqual(1)
51+
expect(result.warnings[0].message).toMatch("The resource `R.color.purple_700` appears to be unused")
52+
53+
expect(result.errors.length).toEqual(0)
54+
})
3655
})
3756

3857
describe("multiple XML files", () => {
3958
test("when the all results are success", async () => {
4059
const results = await check({ pathPattern: path.join(__dirname, "xml/success*.xml") })
4160

42-
expect(results.isPassed).toBe(true)
61+
expect(results.status).toEqual("success")
4362
expect(results.failures.length).toEqual(0)
4463
expect(results.results.length).toEqual(2)
4564
})
4665

4766
test("when the all results are failure", async () => {
4867
const results = await check({ pathPattern: path.join(__dirname, "xml/failure*.xml") })
4968

50-
expect(results.isPassed).toBe(false)
69+
expect(results.status).toEqual("error")
5170
expect(results.failures.length).toEqual(2)
5271
expect(results.results.length).toEqual(2)
5372
})
@@ -59,30 +78,12 @@ describe("multiple XML files", () => {
5978
]
6079
const results = await check({ pathPattern })
6180

62-
expect(results.isPassed).toBe(false)
81+
expect(results.status).toEqual("error")
6382
expect(results.failures.length).toEqual(1)
6483
expect(results.results.length).toEqual(2)
6584
})
6685
})
6786

68-
describe("ignoreWarning", () => {
69-
test("when true", async () => {
70-
const results = await check({ pathPattern: path.join(__dirname, "xml/failure2.xml"), ignoreWarning: true })
71-
72-
expect(results.isPassed).toBe(true)
73-
expect(results.failures.length).toEqual(0)
74-
expect(results.results.length).toEqual(1)
75-
})
76-
77-
test("when false", async () => {
78-
const results = await check({ pathPattern: path.join(__dirname, "xml/failure2.xml"), ignoreWarning: false })
79-
80-
expect(results.isPassed).toBe(false)
81-
expect(results.failures.length).toEqual(1)
82-
expect(results.results.length).toEqual(1)
83-
})
84-
})
85-
8687
test("when the XML file can't be found", async () => {
8788
await expect(check({ pathPattern: path.join(__dirname, "xml/unknown.xml") }))
8889
.rejects.toThrow("No XML file found")
@@ -97,7 +98,7 @@ describe("basic glob path pattern", () => {
9798
test("**/xml/failure*.xml", async () => {
9899
const results = await check({ pathPattern: "**/xml/failure*.xml" })
99100

100-
expect(results.isPassed).toBe(false)
101+
expect(results.status).toEqual("error")
101102
expect(results.failures.length).toEqual(2)
102103
expect(results.results.length).toEqual(2)
103104
})

__tests__/report.test.js

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,116 @@ const { Issue, Result, Results } = require("../src/check")
44

55
const baseDir = "/path/to"
66

7-
function buildIssue(no = 1) {
7+
function buildIssue({ severity, identifier = 1 }) {
88
return new Issue({
99
location: {
10-
"@_file": `/path/to/app/src/source${no}.kt`,
11-
"@_line": `${no}`,
10+
"@_file": `/path/to/app/src/source${identifier}.kt`,
11+
"@_line": `${identifier}`,
1212
},
1313
"@_id": "SomeError",
14-
"@_severity": "Warning",
15-
"@_message": `Error message${no}`,
14+
"@_severity": severity,
15+
"@_message": `Error message${identifier}`,
1616
"@_summary": "Some Error",
1717
"@_errorLine1": "line1",
1818
"@_errorLine2": "line2"
1919
})
2020
}
2121

2222
beforeEach(() => {
23+
core.summary.emptyBuffer()
2324
core.summary.write = jest.fn()
2425
})
2526

26-
test("single result", async () => {
27-
const result = new Result([buildIssue()])
28-
const results = new Results([{ path: "/path/to/app/build/result.xml", result }])
27+
afterEach(() => {
28+
core.summary.write.mockReset()
29+
})
2930

30-
await report({ results, core, baseDir })
31+
describe("single result", () => {
32+
test("when the results is success", async () => {
33+
const result = new Result([])
34+
const results = new Results([{ path: "/path/to/app/build/result.xml", result }])
3135

32-
expect(core.summary.write.mock.calls.length).toEqual(1)
36+
await report({ results, core, baseDir })
3337

34-
const summary = core.summary.stringify()
38+
expect(core.summary.write.mock.calls.length).toEqual(1)
39+
40+
const summary = core.summary.stringify()
41+
42+
expect(summary).toMatch([
43+
"<h2>✔ Android Lint</h2>",
44+
"<p>No issue.</p>"
45+
].join("\n"))
46+
47+
expect(summary).not.toMatch("<h3>app/build/result.xml</h3>")
48+
})
49+
50+
test("when the results is error", async () => {
51+
const result = new Result([buildIssue({ severity: "Error", identifier: 1 })])
52+
const results = new Results([{ path: "/path/to/app/build/result.xml", result }])
53+
54+
await report({ results, core, baseDir })
55+
56+
expect(core.summary.write.mock.calls.length).toEqual(1)
3557

36-
expect(summary).toMatch("<h2>Android Lint</h2>")
37-
expect(summary).toMatch("<h3>app/build/result.xml</h3>")
38-
expect(summary).toMatch("<details><summary>⚠️ Warnings</summary>")
39-
expect(summary).toMatch("#### app/src/source1.kt (1 issues)")
40-
expect(summary).toMatch("* **Line#1** - SomeError: Error message1")
41-
expect(summary).toMatch(" ```")
42-
expect(summary).toMatch(" line1")
43-
expect(summary).toMatch(" line2")
44-
expect(summary).toMatch(" ```")
58+
const summary = core.summary.stringify()
59+
60+
expect(summary).toMatch([
61+
"<h2>❌ Android Lint</h2>",
62+
"<h3>app/build/result.xml</h3>",
63+
"<details><summary>❌ Errors</summary>",
64+
"",
65+
"#### app/src/source1.kt (1 issues)",
66+
"* **Line#1** - SomeError: Error message1",
67+
" ```",
68+
" line1",
69+
" line2",
70+
" ```"
71+
].join("\n"))
72+
73+
expect(summary).not.toMatch("No issue")
74+
expect(summary).not.toMatch("Warnings")
75+
})
76+
77+
test("when the results is warning", async () => {
78+
const result = new Result([buildIssue({ severity: "Warning", identifier: 2 })])
79+
const results = new Results([{ path: "/path/to/app/build/result.xml", result }])
80+
81+
await report({ results, core, baseDir })
82+
83+
expect(core.summary.write.mock.calls.length).toEqual(1)
84+
85+
const summary = core.summary.stringify()
86+
87+
expect(summary).toMatch([
88+
"<h2>⚠ Android Lint</h2>",
89+
"<h3>app/build/result.xml</h3>",
90+
"<details><summary>⚠️ Warnings</summary>",
91+
"",
92+
"#### app/src/source2.kt (1 issues)",
93+
"* **Line#2** - SomeError: Error message2",
94+
" ```",
95+
" line1",
96+
" line2",
97+
" ```"
98+
].join("\n"))
99+
100+
expect(summary).not.toMatch("No issue")
101+
expect(summary).not.toMatch("Errors")
102+
})
45103
})
46104

47105
test("multiple results", async () => {
48106
const results = new Results([
49107
{
50108
path: "/path/to/app/build/result1.xml",
51-
result: new Result([buildIssue(1), buildIssue(2)])
109+
result: new Result([
110+
buildIssue({ identifier: 1, severity: "Error" }),
111+
buildIssue({ identifier: 2, severity: "Warning" })
112+
])
52113
},
53114
{
54115
path: "/path/to/app/build/result2.xml",
55-
result: new Result([buildIssue(3)])
116+
result: new Result([buildIssue({ identifier: 3, severity: "Error" })])
56117
}
57118
])
58119

@@ -62,12 +123,36 @@ test("multiple results", async () => {
62123

63124
const summary = core.summary.stringify()
64125

65-
expect(summary).toMatch("<h2>Android Lint</h2>")
66-
expect(summary).toMatch("<h3>app/build/result1.xml</h3>")
67-
expect(summary).toMatch("<details><summary>⚠️ Warnings</summary>")
68-
expect(summary).toMatch("#### app/src/source1.kt (1 issues)")
69-
expect(summary).toMatch("* **Line#1** - SomeError: Error message1")
70-
expect(summary).toMatch("* **Line#2** - SomeError: Error message2")
71-
expect(summary).toMatch("#### app/src/source2.kt (1 issues)")
72-
expect(summary).toMatch("* **Line#3** - SomeError: Error message3")
126+
expect(summary).toMatch([
127+
"<h2>❌ Android Lint</h2>",
128+
"<h3>app/build/result1.xml</h3>",
129+
"<details><summary>❌ Errors</summary>",
130+
"",
131+
"#### app/src/source1.kt (1 issues)",
132+
"* **Line#1** - SomeError: Error message1",
133+
" ```",
134+
" line1",
135+
" line2",
136+
" ```",
137+
"</details>",
138+
"<details><summary>⚠️ Warnings</summary>",
139+
"",
140+
"#### app/src/source2.kt (1 issues)",
141+
"* **Line#2** - SomeError: Error message2",
142+
" ```",
143+
" line1",
144+
" line2",
145+
" ```",
146+
"</details>",
147+
"<h3>app/build/result2.xml</h3>",
148+
"<details><summary>❌ Errors</summary>",
149+
"",
150+
"#### app/src/source3.kt (1 issues)",
151+
"* **Line#3** - SomeError: Error message3",
152+
" ```",
153+
" line1",
154+
" line2",
155+
" ```",
156+
"</details>"
157+
].join("\n"))
73158
})

0 commit comments

Comments
 (0)