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

Support reviewdog command line argument changes (--fail-level) #72

Merged
merged 5 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,22 @@ See [reviewdog documentation for filter mode](https://github.com/reviewdog/revie

### `fail_on_error`

**Deprecated**. This option is no longer recommended for use and will be removed in future versions.

Optional. Exit code for reviewdog when errors are found [`true`, `false`].

The default is `false`.

See [reviewdog documentation for exit codes](https://github.com/reviewdog/reviewdog/tree/master#exit-codes) for details.

### `fail_level`

Optional. The level of failures that will cause the action to fail [any,info,warning,error].

The default is `error`.
nayuta marked this conversation as resolved.
Show resolved Hide resolved

See [reviewdog documentation for fail level](https://github.com/reviewdog/reviewdog/tree/master?tab=readme-ov-file#fail-level) for details.

### `flags`

Optional. Additional reviewdog flags. Useful for debugging errors, when it can be set to `-tee`.
Expand Down Expand Up @@ -139,6 +149,7 @@ jobs:
reporter: github-pr-review # Change reviewdog reporter
filter_mode: nofilter # Check all files, not just the diff
fail_on_error: true # Fail action if errors are found
fail_level: any # Fail action if any level of failures are found
flags: -tee # Add debug flag to reviewdog
trivy_flags: "" # Optional
```
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ inputs:
Default is added.
default: 'added'
required: false
fail_level:
description: |
The level of failures that will cause the action to fail [any,info,warning,error]
Default is error.
default: ''
nayuta marked this conversation as resolved.
Show resolved Hide resolved
required: false
fail_on_error:
description: |
**Deprecated**. This option is no longer recommended for use and will be removed in future versions.
Exit code for reviewdog when errors are found [true,false]
Default is `false`.
default: 'false'
required: false
deprecated: true
nayuta marked this conversation as resolved.
Show resolved Hide resolved
flags:
description: 'Additional reviewdog flags'
default: ''
Expand Down Expand Up @@ -94,6 +102,7 @@ runs:
INPUT_TOOL_NAME: ${{ inputs.tool_name }}
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
INPUT_FAIL_LEVEL: ${{ inputs.fail_level }}
INPUT_FLAGS: ${{ inputs.flags }}
INPUT_TRIVY_VERSION: ${{ inputs.trivy_version }}
INPUT_TRIVY_COMMAND: ${{ inputs.trivy_command }}
Expand Down
12 changes: 11 additions & 1 deletion script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ echo '::endgroup::'
echo '::group:: Running trivy with reviewdog 🐶 ...'
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

if [[ -n "${INPUT_FAIL_LEVEL}" ]]; then
fail_level="--fail-level=${INPUT_FAIL_LEVEL}"
elif [[ "${INPUT_FAIL_ON_ERROR}" = "true" ]]; then
# For backward compatibility, default to any if fail-on-error is true
# Deprecated
fail_level="--fail-level=any"
else
fail_level=""
fi
Copy link
Member

@shmokmt shmokmt Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it makes sense for reviewdog users to include conditional branching based on options.
The reviewdog code seems to include code to take care when fail-on-error is true. You can just pass the two options as is and there will be no problem.

func failLevel(opt *option) reviewdog.FailLevel {
	if opt.failOnError {
		slog.Warn("reviewdog: -fail-on-error is deprecated. Use -fail-level=any, or -fail-level=error for github-[pr-]check reporter instead. See also https://github.com/reviewdog/reviewdog/blob/master/CHANGELOG.md")
		if opt.failLevel == reviewdog.FailLevelDefault {
			switch opt.reporter {
			default:
				return reviewdog.FailLevelAny
			case "github-check", "github-pr-check":
				return reviewdog.FailLevelError
			}
		}
	}
	return opt.failLevel
}

reviewdog/reviewdog#1854
https://github.com/reviewdog/action-rubocop/blob/master/script.sh#L135-L136

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Fixed!


# Allow failures now, as reviewdog handles them
set +Eeuo pipefail

Expand All @@ -108,7 +118,7 @@ echo '::group:: Running trivy with reviewdog 🐶 ...'
-name="${INPUT_TOOL_NAME}" \
-reporter="${INPUT_REPORTER}" \
-level="${INPUT_LEVEL}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
${fail_level} \
-filter-mode="${INPUT_FILTER_MODE}" \
${INPUT_FLAGS}

Expand Down
Loading