Skip to content

Commit

Permalink
feat(github-action): Should only fail when there are results on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvassallo committed May 23, 2024
1 parent 799aea3 commit f2b989d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 9 additions & 1 deletion action/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ jest.mock('../src/checkoutRepository', () => ({
}))
jest.mock('../src/handlePushRun', () => ({
__esModule: true,
handlePushRun: jest.fn(),
handlePushRun: jest.fn().mockReturnValue([
['file1.ts', 'Violation message 1', 'rule-id-1'],
['file2.ts', 'Violation message 2', 'rule-id-2']
]
),
default: jest.fn()
}))
jest.mock('../src/handleValidate', () => {
Expand Down Expand Up @@ -57,6 +61,10 @@ jest.mock('../src/handlePullRequestRun', () => {
if (config.createReview) {
handleCreateReviewSpy(...args)
}
return [
['file1.ts', 'Violation message 1', 'rule-id-1'],
['file2.ts', 'Violation message 2', 'rule-id-2']
]
}),
handleCreateReview: handleCreateReviewSpy,
default: jest.fn()
Expand Down
19 changes: 11 additions & 8 deletions action/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ export async function run(): Promise<void> {
} = result

if (sarifRun.results.length) {
core.setFailed(RunStrings.ValidationFailed)

if (analyze) {
core.setFailed(RunStrings.ValidationFailed)
await uploadCodeScan({ result })
} else {
await handleWriteActionSummary({
results:
eventName === 'pull_request'
? await handlePullRequestRun({ run: sarifRun })
: await handlePushRun({ run: sarifRun })
})
const results =
eventName === 'pull_request'
? await handlePullRequestRun({ run: sarifRun })
: await handlePushRun({ run: sarifRun })
if (results.length) {
core.setFailed(RunStrings.ValidationFailed)
await handleWriteActionSummary({
results
})
}
}
}
} catch (error) {
Expand Down

0 comments on commit f2b989d

Please sign in to comment.