Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to fail check on violations #158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading