Skip to content

Commit

Permalink
Merge pull request #158 from bergander/AddOptionToFailCheckOnViolations
Browse files Browse the repository at this point in the history
Add option to fail check on violations
  • Loading branch information
lcollins authored May 4, 2024
2 parents 7f3c26f + cd62c15 commit eedc67b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Optional. Title for the check run to create. Defaults to `PMD Source Code Analyz
### `token`
Optional. GitHub API access token. Defaults to `${{ github.token }}`, which is set by `actions/checkout@v2` minimally.

### `fail-on-violation`
Optional. Whether to fail the check if any violations are found. Defaults to `false`.

## Example usage

```yaml
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export enum Inputs {
Name = 'name',
Title = 'title',
Path = 'path',
Token = 'token'
Token = 'token',
FailOnViolation = 'fail-on-violation'
}
10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async function run(): Promise<void> {
const path = core.getInput(Inputs.Path, {required: true})
const name = core.getInput(Inputs.Name)
const title = core.getInput(Inputs.Title)
const failOnViolations = core.getBooleanInput(Inputs.FailOnViolation)

const searchResult = await findResults(path)
if (searchResult.filesToUpload.length === 0) {
Expand Down Expand Up @@ -41,7 +42,7 @@ async function run(): Promise<void> {
core.debug(`Created ${groupedAnnotations.length} buckets`)

for (const annotationSet of groupedAnnotations) {
await createCheck(name, title, annotationSet, annotations.length)
await createCheck(name, title, annotationSet, annotations.length, failOnViolations)
}
}
} catch (error) {
Expand All @@ -53,7 +54,8 @@ async function createCheck(
name: string,
title: string,
annotations: Annotation[],
numErrors: number
numErrors: number,
failOnViolations: boolean
): Promise<void> {
const octokit = getOctokit(core.getInput(Inputs.Token))
let sha = context.sha
Expand All @@ -78,7 +80,7 @@ async function createCheck(
head_sha: sha,
name,
status: 'completed' as const,
conclusion: numErrors === 0 ? ('success' as const) : ('neutral' as const),
conclusion: numErrors === 0 ? ('success' as const) : failOnViolations ? ('failure' as const) : ('neutral' as const),
output: {
title,
summary: `${numErrors} violation(s) found`,
Expand All @@ -94,7 +96,7 @@ async function createCheck(
...context.repo,
check_run_id,
status: 'completed' as const,
conclusion: numErrors === 0 ? ('success' as const) : ('neutral' as const),
conclusion: numErrors === 0 ? ('success' as const) : failOnViolations ? ('failure' as const) : ('neutral' as const),
output: {
title,
summary: `${numErrors} violation(s) found`,
Expand Down

0 comments on commit eedc67b

Please sign in to comment.