Skip to content

Commit 233a41f

Browse files
author
Graydon Hope
committed
Return non-zero exit code when scan report data is not healthy. This is the expected behaviour based on our docs: https://docs.socket.dev/docs/socket-ci#non-zero-exit-code
1 parent 9cc003b commit 233a41f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/cli/src/commands/scan/output-scan-report.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export async function outputScanReport(
9191
return
9292
}
9393

94+
if (!scanReport.data.healthy) {
95+
// When report contains healthy: false, process should exit with non-zero code.
96+
process.exitCode = 1
97+
}
98+
9499
// I don't think we emit the default error message with banner for an unhealthy report, do we?
95100
// if (!scanReport.data.healthy) {
96101
// logger.fail(failMsgWithBadge(scanReport.message, scanReport.cause))

packages/cli/test/unit/commands/ci/handle-ci.test.mts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,25 @@ describe('handleCi', () => {
266266
expect(mockDebug).toHaveBeenCalledWith('Failed to get default org slug')
267267
expect(mockDebugDir).toHaveBeenCalledWith({ orgSlugCResult: error })
268268
})
269+
270+
it('sets exit code to 1 when scan report is unhealthy',
271+
async () => {
272+
mockGetDefaultOrgSlug.mockResolvedValue({
273+
ok: true,
274+
data: 'test-org',
275+
})
276+
277+
mockGitBranch.mockResolvedValue('main')
278+
mockGetRepoName.mockResolvedValue('test-repo')
279+
280+
mockHandleCreateNewScan.mockImplementation(async () => {
281+
process.exitCode = 1
282+
})
283+
284+
await handleCi(false)
285+
286+
expect(process.exitCode).toBe(1)
287+
expect(mockHandleCreateNewScan).toHaveBeenCalled()
288+
}
289+
)
269290
})

0 commit comments

Comments
 (0)