diff --git a/README.adoc b/README.adoc index efd170d..6aeaf47 100644 --- a/README.adoc +++ b/README.adoc @@ -35,7 +35,7 @@ rule set configuration with an alternate name or at a non-default location. * Customizable JVM xref:#java-setup[vendor and version]. You can run _diKTat_ using a default JVM, or you can set up your own one. -* Customizable xref:#reporter[reporters] (_SARIF_, _JSON_, _Checkstyle_ XML). +* Customizable xref:#reporter[reporter] (_SARIF_ or _Checkstyle_ XML). * Allows multiple xref:#input-paths[input paths]. If you have a multi-module project and only wish to check certain directories or modules, you can configure @@ -61,7 +61,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 ---- == Configuration @@ -77,15 +77,15 @@ You can override the name or the path of your YAML configuration file using the [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: config: path/to/diktat-analysis-custom.yml ---- [#reporter] -=== `reporter`: requesting a custom reporter +=== `reporter`: requesting a type of reporter -If you wish, you can report errors in a custom format. +If you wish, you can report errors in a different format. * Default: `sarif` * Required: **no** @@ -114,35 +114,6 @@ reporter: + image::checkstyle-xml-reporting.png[Checkstyle-XML reporting assisted by reviewdog] -** `plain`: report errors in the plain-text format, e. g.: -+ -[source] ----- -C.kt:1:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: C (cannot be auto-corrected) (diktat-ruleset:kdoc-comments) -C.kt:1:1: [FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: C.kt (diktat-ruleset:file-naming) -C.kt:1:1: [PACKAGE_NAME_MISSING] no package name declared in a file: C.kt (diktat-ruleset:package-naming) -C.kt:1:7: [CLASS_NAME_INCORRECT] class/enum/interface name should be in PascalCase and should contain only latin (ASCII) letters or numbers: C (diktat-ruleset:identifier-naming) -C.kt:1:7: [IDENTIFIER_LENGTH] identifier's length is incorrect, it should be in range of [2, 64] symbols: C (cannot be auto-corrected) (diktat-ruleset:identifier-naming) ----- -+ -The errors, if any, are printed on the standard output. - -** `plain?group_by_file`: same as above, but group errors by file, e. g.: -+ -[source] ----- -C.kt - 1:1 [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: C (cannot be auto-corrected) - 1:1 [FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: C.kt - 1:1 [PACKAGE_NAME_MISSING] no package name declared in a file: C.kt - 1:7 [CLASS_NAME_INCORRECT] class/enum/interface name should be in PascalCase and should contain only latin (ASCII) letters or numbers: C - 1:7 [IDENTIFIER_LENGTH] identifier's length is incorrect, it should be in range of [2, 64] symbols: C (cannot be auto-corrected) ----- - -** `json`: report errors in the JSON format to the file named `report.json`. - -** `html`: report errors in the HTML format to the file named `report.html`. - [#input-paths] === `input-paths`: custom source sets @@ -156,7 +127,7 @@ multiline string to specify multiple inputs. + [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: input-paths: | path/to/file.kt @@ -167,7 +138,7 @@ and all `\*.kt` and `*.kts` files are passed to _diKTat_. + [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: input-paths: | src/main/kotlin @@ -180,7 +151,7 @@ that match the path pattern. Path patterns may be negated, e. g.: + [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: input-paths: | **/*.kt @@ -220,7 +191,7 @@ JDK is not sufficient: you'll need to set **both** `java-distribution` **and** [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: java-distribution: 'temurin' java-version: 17 @@ -237,7 +208,7 @@ fatal (i.e. the current step terminates with a failure): [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: fail-on-error: true ---- @@ -245,45 +216,9 @@ fatal (i.e. the current step terminates with a failure): [NOTE] This flag only affects the case when _diKTat_ exits with code **1**. Higher -link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html#exit-codes[exit +link:https://diktat.saveourtool.com/diktat-cli/#exit-codes[exit codes] are _always_ fatal. -=== `relative-paths`: relative or absolute paths - -* Default: `true` -* Required: **no** - -If `true`, file paths get relativized with respect to the project directory. -Otherwise, absolute file paths get reported. Example: - -[source,yaml] ----- - - uses: saveourtool/benedikt@v1 - with: - relative-paths: true ----- - -[NOTE] - -When _SARIF_ xref:#reporter[reporter] is used, this flag has no effect: in -_SARIF_ mode, paths reported are always absolute. - -=== `color`: colorizing the plain-text output - -* Default: `true` -* Required: **no** - -Setting this flag enables the console output to be colorized. This is only -useful if the xref:#reporter[reporter] is set to `plain` or `plain?group_by_file`: - -[source,yaml] ----- - - uses: saveourtool/benedikt@v1 - with: - reporter: plain - color: true ----- - === `debug`: enabling debug logging * Default: `false` @@ -293,7 +228,7 @@ Debug logging can be enabled by setting the `debug` input parameter to `true`: [source,yaml] ---- - - uses: saveourtool/benedikt@v1 + - uses: saveourtool/benedikt@v2 with: debug: true ---- @@ -314,7 +249,7 @@ jobs: - uses: actions/checkout@v4 - id: diktat - uses: saveourtool/benedikt@v1 + uses: saveourtool/benedikt@v2 - name: 'Read the exit code of diKTat' if: ${{ always() }} @@ -323,11 +258,4 @@ jobs: ---- The exit codes are documented -link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html#exit-codes[here]. - -[#diktat-cli] -== Using the command-line client - -Alternatively, if you wish to run _diKTat_ locally (e. g.: as a _Vim_ plug-in), -or you're using a different CI/CD server, you can try the -link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html[command-line client]. +link:https://diktat.saveourtool.com/diktat-cli/#exit-codes[here]. diff --git a/action.yml b/action.yml index ed5bb0c..52f9589 100644 --- a/action.yml +++ b/action.yml @@ -18,8 +18,7 @@ inputs: required: false reporter: description: > - The reporter to use, one of: "plain", "plain?group_by_file", "json", - "sarif" (the default), "checkstyle", "html". + The reporter to use, one of: "sarif" (the default) or "checkstyle". default: 'sarif' required: false input-paths: @@ -53,22 +52,11 @@ inputs: examples of supported syntax at . required: false - color: - description: > - Colorize the output - default: ${{ true }} - required: false debug: description: > Whether debug logging should be enabled default: ${{ false }} required: false - relative-paths: - description: > - Relativize file paths with respect to the working directory (if false, - absolute file paths get reported) - default: ${{ true }} - required: false fail-on-error: description: > Whether linter errors are considered fatal (the default is true) @@ -105,18 +93,26 @@ runs: # `steps.diktat.outputs.exit-code` variable. - id: diktat run: | - DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') - if [[ '${{ inputs.color }}' != 'false' ]] + if [[ '${{ inputs.debug }}' == 'true' ]] then - DIKTAT_ARGS+=('--color-name') + set -x fi - if [[ '${{ inputs.debug }}' == 'true' ]] + DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') + if [[ '${{ inputs.reporter }}' == 'sarif' ]] + then + report_file=${GITHUB_WORKSPACE}/report.sarif + elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--log-level DEBUG') + report_file=${GITHUB_WORKSPACE}/checkstyle-report.xml + else + echo " should be set to or " + exit 1 fi - if [[ '${{ inputs.relative-paths }}' != 'false' ]] + DIKTAT_ARGS+=('--output' "${report_file}") + + if [[ '${{ inputs.debug }}' == 'true' ]] then - DIKTAT_ARGS+=('--relative') + DIKTAT_ARGS+=('--log-level' 'DEBUG') fi set -o pipefail @@ -125,7 +121,10 @@ runs: DIKTAT_CMD=${GITHUB_WORKSPACE}/diktat chmod +x ${DIKTAT_CMD} { ${DIKTAT_CMD} "${DIKTAT_ARGS[@]}" "${INPUT_PATHS[@]}" | tee diktat.log; } && exit_code=$? || exit_code=$? - echo "summary-line=$(tail -n1 diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT + total_lines=$(wc -l diktat.log | cut -d ' ' -f1) + summary_line_number=$(grep -n 'Summary error count (descending) by rule:' diktat.log | cut -d: -f1) + summary_line=$(tail -n $((total_lines - summary_line_number)) diktat.log | sed -e 's/^ //g' | awk '{ printf("%s,", $0) }' | sed -e 's/,$//g') + echo "summary-line=${summary_line}" >>$GITHUB_OUTPUT rm -f diktat.log echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT env: @@ -159,7 +158,7 @@ runs: if (( ${{ steps.diktat.outputs.exit-code }} != 0 )) then echo '```console' >>${GITHUB_STEP_SUMMARY} - echo "${{ steps.diktat.outputs.summary-line }}" >>${GITHUB_STEP_SUMMARY} + echo "${{ steps.diktat.outputs.summary-line }}" | xargs -d ',' -n1 echo >>${GITHUB_STEP_SUMMARY} echo '```' >>${GITHUB_STEP_SUMMARY} fi @@ -180,9 +179,9 @@ runs: # When in SARIF reporting mode, upload SARIF reports to GitHub. - id: upload-sarif if: ${{ always() && steps.diktat.outputs.exit-code == 1 && inputs.reporter == 'sarif' }} - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: ${{ github.workspace }} + sarif_file: ${{ github.workspace }}/report.sarif # Alternatively, when in Checkstyle reporting mode, upload Checkstyle XML # using `reviewdog`. @@ -205,7 +204,7 @@ runs: reviewdog_reporter='github-check' fi - reviewdog -f=checkstyle -fail-on-error=false -level=info -name='diKTat errors reported by reviewdog' -reporter="${reviewdog_reporter}"