Skip to content

Commit

Permalink
Set exit code when encountering violations
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Apr 29, 2024
1 parent 3933099 commit c6be194
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
7 changes: 4 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from '@actions/core'
import * as main from '../src/main.ts'
import { Parser } from '../src/parser.ts'
import * as inputs from '../src/inputs.ts'
import write from '../src/write.ts'
import write, { Annotation } from '../src/write.ts'
import * as cleanup from '../src/cleanup.ts'

let runMock: jest.SpiedFunction<typeof main.run>
Expand All @@ -15,7 +15,7 @@ describe('run', () => {
jest.spyOn(inputs, 'formatFilters').mockReturnValue({ prefix: [], ignoreDecl: [], ignoreRsc: [] })
jest.spyOn(Parser, 'from').mockResolvedValue([new Parser('', '')])
jest.spyOn(write, 'createCheckRun').mockResolvedValue({ details_url: '', check_id: 0 })
jest.spyOn(write, 'annotations').mockResolvedValue([])
jest.spyOn(write, 'annotations').mockResolvedValue([{} as Annotation])
jest.spyOn(write, 'summary').mockImplementation()
jest.spyOn(cleanup, 'workflow').mockResolvedValue(false)
jest.spyOn(core, 'setFailed').mockImplementation()
Expand All @@ -34,7 +34,8 @@ describe('run', () => {
expect(write.annotations).toHaveBeenCalledTimes(1)
expect(write.summary).toHaveBeenCalledTimes(1)
expect(core.setFailed).not.toHaveBeenCalled()
expect(result).toMatchObject({ summary: undefined, annotations: [] })
expect(result).toMatchObject({ summary: undefined, annotations: [{} as Annotation] })
expect(process.exitCode).toBe(core.ExitCode.Failure)
})

it('should run the cleanup function and return', async () => {
Expand Down
6 changes: 6 additions & 0 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.

6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ export async function run(github: boolean = false): Promise<{ summary: string; a
const summary = await write.summary(parsers, resources, prefix, duration, details_url, github)
const annotations = await write.annotations(parsers, resources, prefix, check_id, summary, github)

// Update exit code
if (github && annotations.length > 0) {
process.exitCode = core.ExitCode.Failure
}

// Return results
return { summary, annotations }
} catch (error) {
const msg: string = error instanceof Error ? error.message : String(error)
if (github) core.setFailed(msg)
else console.error(msg)
} finally {
await Parser.clearTmpDir()
}
}

0 comments on commit c6be194

Please sign in to comment.