Skip to content

Commit

Permalink
Add custom RuleSet support (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
berhram committed Apr 3, 2023
1 parent 6355501 commit 4d5f4b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ The default value is `ktlint`.
Optional. Defines a file glob to identify files to be checked.
The default value is an empty string.

### `custom_rule_path`

Optional. Provides path to JAR file with custom rules. The default value is an empty string.

## Example usage

```yml
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ inputs:
description: Optionally defines a file glob to identify files to be checked
required: false
default: ''
custom_rule_path:
description: Path to custom rule set JAR
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -66,6 +70,7 @@ runs:
- ${{ inputs.baseline }}
- ${{ inputs.ktlint_version }}
- ${{ inputs.name }}
- ${{ inputs.custom_rule_path }}
branding:
icon: 'edit'
color: 'blue'
7 changes: 6 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export RELATIVE=
export ANDROID=
export BASELINE=
export CUSTOM_RULE_PATH=

if [ "$INPUT_KTLINT_VERSION" = "latest" ]; then
curl -sSL https://api.github.com/repos/pinterest/ktlint/releases/latest --header "authorization: Bearer ${INPUT_GITHUB_TOKEN}" |
Expand Down Expand Up @@ -30,6 +31,10 @@ if [ "$INPUT_ANDROID" = true ]; then
export ANDROID=--android
fi

if [ "$INPUT_CUSTOM_RULE_PATH" ]; then
export CUSTOM_RULE_PATH="--ruleset=${INPUT_CUSTOM_RULE_PATH}"
fi

cd "$GITHUB_WORKSPACE"

git config --global --add safe.directory $GITHUB_WORKSPACE
Expand All @@ -38,7 +43,7 @@ export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

echo ktlint version: "$(ktlint --version)"

ktlint --reporter=checkstyle $RELATIVE $ANDROID $BASELINE $INPUT_FILE_GLOB |
ktlint --reporter=checkstyle $CUSTOM_RULE_PATH $RELATIVE $ANDROID $BASELINE $INPUT_FILE_GLOB |
reviewdog -f=checkstyle \
-name="${INPUT_NAME}" \
-reporter="${INPUT_REPORTER}" \
Expand Down

0 comments on commit 4d5f4b5

Please sign in to comment.