From ae51fa826c80988379d16a497d648bf9f8e27808 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 15 Dec 2023 18:47:27 +0300 Subject: [PATCH 01/19] Finish migration to 2.0 ### What's done: - removed extra parameters - removed documentation for cli - fixed link to docs about cli - fixed version in docs --- README.adoc | 100 ++++++-------------------------------- action.yml | 32 ++++--------- docs/diktat-cli.adoc | 111 ------------------------------------------- 3 files changed, 23 insertions(+), 220 deletions(-) delete mode 100644 docs/diktat-cli.adoc 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..c305ab1 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) @@ -83,6 +71,12 @@ outputs: runs: using: "composite" steps: + - id: validate-inputs-reporter + if: ${{ inputs.reporter != 'sarif' && inputs.reporter != 'checkstyle' }} + run: | + echo "`reporter` should be set to `sarif` or `checkstyle`" + exit 1 + shell: bash - id: setup-java if: ${{ inputs.java-version != null }} uses: actions/setup-java@v4 @@ -93,8 +87,8 @@ runs: - id: download-diktat uses: robinraju/release-downloader@v1.8 with: - repository: "saveourtool/diktat" - tag: "v2.0.0" + repository: "nulls/diktat" + tag: "v2.0.1" fileName: "diktat" # GitHub seems to set `-e` internally, so don't fail immediately if diKTat @@ -106,18 +100,10 @@ runs: - id: diktat run: | DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') - if [[ '${{ inputs.color }}' != 'false' ]] - then - DIKTAT_ARGS+=('--color-name') - fi if [[ '${{ inputs.debug }}' == 'true' ]] then DIKTAT_ARGS+=('--log-level DEBUG') fi - if [[ '${{ inputs.relative-paths }}' != 'false' ]] - then - DIKTAT_ARGS+=('--relative') - fi set -o pipefail IFS=$'\n' diff --git a/docs/diktat-cli.adoc b/docs/diktat-cli.adoc deleted file mode 100644 index 8c5c4d7..0000000 --- a/docs/diktat-cli.adoc +++ /dev/null @@ -1,111 +0,0 @@ -= _diktat-cli_, the command-line client for https://github.com/saveourtool/diktat[_diKTat_] -:toc: - -[#features] -== Features - -* Written in _UNIX Shell_ (~500 lines of code) -* BSD-compatible -* Also works in Windows (_Git Bash_, _Cygwin_, or _MSys2_) -* Automatically downloads `ktlint` and `diktat` far JARs -* Accepts all essential `ktlint` command-line arguments - -[#usage] -== Usage - -[source,bash] ----- -diktat [OPTION]... [FILE]... ----- - -[#options] -== Option summary - -.Options -[cols="1,3"] -|=== -| Command-line switch | Meaning - -| `-c CONFIG`, `--config=CONFIG` -| Specify the location of the YAML configuration file. By default, -`diktat-analysis.yml` in the current directory is used. - -| `-r REPORTER`, `--reporter=REPORTER` -| The reporter to use, one of: `plain` (the default), `plain?group_by_file`, -`json`, `sarif`, `checkstyle`, `html`. - -| `-o OUTPUT`, `--output=OUTPUT` -| Redirect the reporter output to a file. Use `-o -` to force using the standard -output. - -| `--color` -| Colorize the output. - -| `--relative` -| Relativize file paths with respect to the working directory. By default, -absolute file paths get reported. - -| `--no-download-progress` -| Do not show the progress bar as the binaries get downloaded. - -| `-d`, `--debug` -| Enable the debug output. - -| `-h`, `--help` -| Display the help text and exit. - -| `-l`, `--license` -| Display the license and exit. - -| `-v`, `--verbose` -|Enable the verbose output. - -| `-V`, `--version` -|Output version information and exit. -|=== - -[#exit-codes] -== Exit codes - -.Exit codes -[cols="1,3,1"] -|=== -| Exit code | Meaning | Treated as a failure - -| 0 -| _diKTat_ found no errors in your code -| **No** - -| 1 -| _diKTat_ reported some errors in your code -| Depends on the `fail-on-error` input parameter, the default is **Yes** - -| 2 -| The JVM was not found (probably, you need to set up the JVM explicitly, using -the `java-distribution` and `java-version` input parameters) -| **Yes** - -| 3 -| Failure while downloading dependencies -| **Yes** - -| 4 -| Unsupported command-line switch -| **Yes** - -| 5 -| _diKTat_ JAR was not found -| **Yes** - -| 6 -| A command-line switch requires an argument -| **Yes** - -| 7 -| No source files to check were found -| **Yes** - -| 8 -| Incompatible _Bash_ version -| **Yes** -|=== From d8d6c391b8676cb72ebb48548dd99c4e2bf1eabb Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 10:38:04 +0300 Subject: [PATCH 02/19] upgrade test version + set output for reporter --- action.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index c305ab1..e0c3477 100644 --- a/action.yml +++ b/action.yml @@ -71,12 +71,6 @@ outputs: runs: using: "composite" steps: - - id: validate-inputs-reporter - if: ${{ inputs.reporter != 'sarif' && inputs.reporter != 'checkstyle' }} - run: | - echo "`reporter` should be set to `sarif` or `checkstyle`" - exit 1 - shell: bash - id: setup-java if: ${{ inputs.java-version != null }} uses: actions/setup-java@v4 @@ -88,7 +82,7 @@ runs: uses: robinraju/release-downloader@v1.8 with: repository: "nulls/diktat" - tag: "v2.0.1" + tag: "v2.0.2" fileName: "diktat" # GitHub seems to set `-e` internally, so don't fail immediately if diKTat @@ -100,6 +94,16 @@ runs: - id: diktat run: | DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') + if [[ '${{ inputs.reporter }}' == 'sarif' ]] + then + DIKTAT_ARGS+=('--output report.sarif') + elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] + then + DIKTAT_ARGS+=('--output checkstyle-report.xml') + else + echo "`reporter` should be set to `sarif` or `checkstyle`" + exit 1 + fi if [[ '${{ inputs.debug }}' == 'true' ]] then DIKTAT_ARGS+=('--log-level DEBUG') From 5c2b431b3a7a567d9103b917fcf520f78e2cc899 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 10:58:34 +0300 Subject: [PATCH 03/19] update 2.0.3 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e0c3477..45e75a6 100644 --- a/action.yml +++ b/action.yml @@ -82,7 +82,7 @@ runs: uses: robinraju/release-downloader@v1.8 with: repository: "nulls/diktat" - tag: "v2.0.2" + tag: "v2.0.3" fileName: "diktat" # GitHub seems to set `-e` internally, so don't fail immediately if diKTat From deaa1b092592246b1691a0a1fecfb9e539cb153b Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 11:22:05 +0300 Subject: [PATCH 04/19] set a full path to reporters --- action.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 45e75a6..eec64a5 100644 --- a/action.yml +++ b/action.yml @@ -96,10 +96,10 @@ runs: DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then - DIKTAT_ARGS+=('--output report.sarif') + DIKTAT_ARGS+=('--output ${GITHUB_WORKSPACE}/report.sarif') elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--output checkstyle-report.xml') + DIKTAT_ARGS+=('--output ${GITHUB_WORKSPACE}/checkstyle-report.xml') else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 @@ -170,9 +170,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} # Alternatively, when in Checkstyle reporting mode, upload Checkstyle XML # using `reviewdog`. @@ -195,7 +195,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}" Date: Mon, 18 Dec 2023 11:31:45 +0300 Subject: [PATCH 05/19] set debug logging --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index eec64a5..06bb8a3 100644 --- a/action.yml +++ b/action.yml @@ -93,6 +93,7 @@ runs: # `steps.diktat.outputs.exit-code` variable. - id: diktat run: | + set -x DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then From ebd0cf61265705b839874408ff79ae2764d67f10 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 11:42:18 +0300 Subject: [PATCH 06/19] bash's array don't need a comma --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 06bb8a3..5424f11 100644 --- a/action.yml +++ b/action.yml @@ -94,20 +94,20 @@ runs: - id: diktat run: | set -x - DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}') + DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then - DIKTAT_ARGS+=('--output ${GITHUB_WORKSPACE}/report.sarif') + DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/report.sarif') elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--output ${GITHUB_WORKSPACE}/checkstyle-report.xml') + DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/checkstyle-report.xml') else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 fi if [[ '${{ inputs.debug }}' == 'true' ]] then - DIKTAT_ARGS+=('--log-level DEBUG') + DIKTAT_ARGS+=('--log-level' 'DEBUG') fi set -o pipefail From 7e985b1e841af0bd9b8a4dcfe1d6b1643c3f5ad3 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 11:53:31 +0300 Subject: [PATCH 07/19] updated summary --- action.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 5424f11..d911f34 100644 --- a/action.yml +++ b/action.yml @@ -93,7 +93,10 @@ runs: # `steps.diktat.outputs.exit-code` variable. - id: diktat run: | - set -x + if [[ '${{ inputs.debug }}' == 'true' ]] + then + set -x + fi DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then @@ -116,7 +119,9 @@ 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=$(grep -n 'Summary error count (descending) by rule:' diktat.log | cut -d: -f1) + echo "summary-line=$(tail -n $((total_lines - summary_line + 1)) diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT rm -f diktat.log echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT env: From 81655a761852d3391352d429a2d1d74618c69b99 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 11:56:50 +0300 Subject: [PATCH 08/19] type " instead of ' --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d911f34..df9ad4c 100644 --- a/action.yml +++ b/action.yml @@ -100,10 +100,10 @@ runs: DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then - DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/report.sarif') + DIKTAT_ARGS+=('--output' "${GITHUB_WORKSPACE}/report.sarif") elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/checkstyle-report.xml') + DIKTAT_ARGS+=('--output' "${GITHUB_WORKSPACE}/checkstyle-report.xml") else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 From 874fc7cdd778a26780e9f2da564da2d62c463920 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 12:14:12 +0300 Subject: [PATCH 09/19] return only a single line for now --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index df9ad4c..e258528 100644 --- a/action.yml +++ b/action.yml @@ -121,7 +121,8 @@ runs: { ${DIKTAT_CMD} "${DIKTAT_ARGS[@]}" "${INPUT_PATHS[@]}" | tee diktat.log; } && exit_code=$? || exit_code=$? total_lines=$(wc -l diktat.log | cut -d ' ' -f1) summary_line=$(grep -n 'Summary error count (descending) by rule:' diktat.log | cut -d: -f1) - echo "summary-line=$(tail -n $((total_lines - summary_line + 1)) diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT +# echo "summary-line=$(tail -n $((total_lines - summary_line)) diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT + echo "summary-line=$(tail -n1 diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT rm -f diktat.log echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT env: From 9ed27ed0e4e6dd39f8756d5ab694f4abda6b542f Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 12:40:37 +0300 Subject: [PATCH 10/19] fixed a single line as summary --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index e258528..92a1d3a 100644 --- a/action.yml +++ b/action.yml @@ -120,9 +120,9 @@ runs: chmod +x ${DIKTAT_CMD} { ${DIKTAT_CMD} "${DIKTAT_ARGS[@]}" "${INPUT_PATHS[@]}" | tee diktat.log; } && exit_code=$? || exit_code=$? total_lines=$(wc -l diktat.log | cut -d ' ' -f1) - summary_line=$(grep -n 'Summary error count (descending) by rule:' diktat.log | cut -d: -f1) -# echo "summary-line=$(tail -n $((total_lines - summary_line)) diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT - echo "summary-line=$(tail -n1 diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT + 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) } END { printf "\n" }' | sed -e 's/,$//g') + echo "summary-line=${summary_line} >>$GITHUB_OUTPUT rm -f diktat.log echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT env: @@ -156,7 +156,7 @@ runs: if (( ${{ steps.diktat.outputs.exit-code }} != 0 )) then echo '```console' >>${GITHUB_STEP_SUMMARY} - echo "${{ steps.diktat.outputs.summary-line }}" >>${GITHUB_STEP_SUMMARY} + ${{ steps.diktat.outputs.summary-line }} | xargs -d ',' -n1 echo >>${GITHUB_STEP_SUMMARY} echo '```' >>${GITHUB_STEP_SUMMARY} fi From f30f015b776cda70c6492a192632d666e868b879 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 12:47:35 +0300 Subject: [PATCH 11/19] forgot a " --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 92a1d3a..5be5c37 100644 --- a/action.yml +++ b/action.yml @@ -122,7 +122,7 @@ runs: 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) } END { printf "\n" }' | sed -e 's/,$//g') - echo "summary-line=${summary_line} >>$GITHUB_OUTPUT + echo "summary-line=${summary_line}" >>$GITHUB_OUTPUT rm -f diktat.log echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT env: From 09bc9a9bc991357245599ab9ed7eef874d574851 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 12:54:59 +0300 Subject: [PATCH 12/19] removed a new line at the end --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5be5c37..f9a3582 100644 --- a/action.yml +++ b/action.yml @@ -121,7 +121,7 @@ runs: { ${DIKTAT_CMD} "${DIKTAT_ARGS[@]}" "${INPUT_PATHS[@]}" | tee diktat.log; } && exit_code=$? || exit_code=$? 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) } END { printf "\n" }' | sed -e 's/,$//g') + 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 From 0fa226511b8491bdb9a71408473b8aee29524ab7 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 12:57:27 +0300 Subject: [PATCH 13/19] added an echo --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f9a3582..e0714a5 100644 --- a/action.yml +++ b/action.yml @@ -156,7 +156,7 @@ runs: if (( ${{ steps.diktat.outputs.exit-code }} != 0 )) then echo '```console' >>${GITHUB_STEP_SUMMARY} - ${{ steps.diktat.outputs.summary-line }} | xargs -d ',' -n1 echo >>${GITHUB_STEP_SUMMARY} + echo "${{ steps.diktat.outputs.summary-line }}" | xargs -d ',' -n1 echo >>${GITHUB_STEP_SUMMARY} echo '```' >>${GITHUB_STEP_SUMMARY} fi From 9c79f3ae03d722e399112bd1bb16450e830814ff Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:02:07 +0300 Subject: [PATCH 14/19] a full path to sarif report --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index e0714a5..fd153a9 100644 --- a/action.yml +++ b/action.yml @@ -100,10 +100,10 @@ runs: DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then - DIKTAT_ARGS+=('--output' "${GITHUB_WORKSPACE}/report.sarif") + DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/report.sarif') elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--output' "${GITHUB_WORKSPACE}/checkstyle-report.xml") + DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/checkstyle-report.xml') else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 @@ -179,7 +179,7 @@ runs: if: ${{ always() && steps.diktat.outputs.exit-code == 1 && inputs.reporter == 'sarif' }} 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`. From ff3fedd600793a3a40853fecd577feb7e847f204 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:12:55 +0300 Subject: [PATCH 15/19] resolving report_file --- action.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index fd153a9..e540457 100644 --- a/action.yml +++ b/action.yml @@ -100,10 +100,12 @@ runs: DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}') if [[ '${{ inputs.reporter }}' == 'sarif' ]] then - DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/report.sarif') + report_file=${GITHUB_WORKSPACE}/report.sarif + DIKTAT_ARGS+=('--output' report_file) elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then - DIKTAT_ARGS+=('--output' '${GITHUB_WORKSPACE}/checkstyle-report.xml') + report_file=${GITHUB_WORKSPACE}/checkstyle-report.xml + DIKTAT_ARGS+=('--output' report_file) else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 From 9f6eaf3beecb4519d90def3a43053df9e84221cc Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:15:46 +0300 Subject: [PATCH 16/19] resolving report_file --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e540457..58f7082 100644 --- a/action.yml +++ b/action.yml @@ -101,15 +101,15 @@ runs: if [[ '${{ inputs.reporter }}' == 'sarif' ]] then report_file=${GITHUB_WORKSPACE}/report.sarif - DIKTAT_ARGS+=('--output' report_file) elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]] then report_file=${GITHUB_WORKSPACE}/checkstyle-report.xml - DIKTAT_ARGS+=('--output' report_file) else echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 fi + DIKTAT_ARGS+=('--output' '${report_file}') + if [[ '${{ inputs.debug }}' == 'true' ]] then DIKTAT_ARGS+=('--log-level' 'DEBUG') From 7ea1e03f681760f2aaf3662ebcee4d39329e474c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:21:31 +0300 Subject: [PATCH 17/19] try " instead of ' --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 58f7082..c8d51b3 100644 --- a/action.yml +++ b/action.yml @@ -108,7 +108,7 @@ runs: echo "`reporter` should be set to `sarif` or `checkstyle`" exit 1 fi - DIKTAT_ARGS+=('--output' '${report_file}') + DIKTAT_ARGS+=('--output' "${report_file}") if [[ '${{ inputs.debug }}' == 'true' ]] then From 75a406eba337b2f5796cd00b780fd2d8c782e49f Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:51:36 +0300 Subject: [PATCH 18/19] set release version --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index c8d51b3..d639753 100644 --- a/action.yml +++ b/action.yml @@ -81,8 +81,8 @@ runs: - id: download-diktat uses: robinraju/release-downloader@v1.8 with: - repository: "nulls/diktat" - tag: "v2.0.3" + repository: "saveourtool/diktat" + tag: "v2.0.0" fileName: "diktat" # GitHub seems to set `-e` internally, so don't fail immediately if diKTat From 6db2ace095da79a9d2a1b0f2692bd6a2944fac56 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 18 Dec 2023 13:53:41 +0300 Subject: [PATCH 19/19] fixed log message --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d639753..52f9589 100644 --- a/action.yml +++ b/action.yml @@ -105,7 +105,7 @@ runs: then report_file=${GITHUB_WORKSPACE}/checkstyle-report.xml else - echo "`reporter` should be set to `sarif` or `checkstyle`" + echo " should be set to or " exit 1 fi DIKTAT_ARGS+=('--output' "${report_file}")