Skip to content

Commit b80b0a3

Browse files
authored
Merge pull request #23 from saveourtool/feature/remove-extra-parameters
Finish migration to 2.0
2 parents bf9b672 + 6db2ace commit b80b0a3

File tree

3 files changed

+38
-222
lines changed

3 files changed

+38
-222
lines changed

README.adoc

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rule set configuration with an alternate name or at a non-default location.
3535
* Customizable JVM xref:#java-setup[vendor and version]. You can run _diKTat_
3636
using a default JVM, or you can set up your own one.
3737

38-
* Customizable xref:#reporter[reporters] (_SARIF_, _JSON_, _Checkstyle_ XML).
38+
* Customizable xref:#reporter[reporter] (_SARIF_ or _Checkstyle_ XML).
3939

4040
* Allows multiple xref:#input-paths[input paths]. If you have a multi-module
4141
project and only wish to check certain directories or modules, you can configure
@@ -61,7 +61,7 @@ jobs:
6161
steps:
6262
- uses: actions/checkout@v4
6363
64-
- uses: saveourtool/benedikt@v1
64+
- uses: saveourtool/benedikt@v2
6565
----
6666

6767
== Configuration
@@ -77,15 +77,15 @@ You can override the name or the path of your YAML configuration file using the
7777

7878
[source,yaml]
7979
----
80-
- uses: saveourtool/benedikt@v1
80+
- uses: saveourtool/benedikt@v2
8181
with:
8282
config: path/to/diktat-analysis-custom.yml
8383
----
8484

8585
[#reporter]
86-
=== `reporter`: requesting a custom reporter
86+
=== `reporter`: requesting a type of reporter
8787

88-
If you wish, you can report errors in a custom format.
88+
If you wish, you can report errors in a different format.
8989

9090
* Default: `sarif`
9191
* Required: **no**
@@ -114,35 +114,6 @@ reporter:
114114
+
115115
image::checkstyle-xml-reporting.png[Checkstyle-XML reporting assisted by reviewdog]
116116

117-
** `plain`: report errors in the plain-text format, e. g.:
118-
+
119-
[source]
120-
----
121-
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)
122-
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)
123-
C.kt:1:1: [PACKAGE_NAME_MISSING] no package name declared in a file: C.kt (diktat-ruleset:package-naming)
124-
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)
125-
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)
126-
----
127-
+
128-
The errors, if any, are printed on the standard output.
129-
130-
** `plain?group_by_file`: same as above, but group errors by file, e. g.:
131-
+
132-
[source]
133-
----
134-
C.kt
135-
1:1 [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: C (cannot be auto-corrected)
136-
1:1 [FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: C.kt
137-
1:1 [PACKAGE_NAME_MISSING] no package name declared in a file: C.kt
138-
1:7 [CLASS_NAME_INCORRECT] class/enum/interface name should be in PascalCase and should contain only latin (ASCII) letters or numbers: C
139-
1:7 [IDENTIFIER_LENGTH] identifier's length is incorrect, it should be in range of [2, 64] symbols: C (cannot be auto-corrected)
140-
----
141-
142-
** `json`: report errors in the JSON format to the file named `report.json`.
143-
144-
** `html`: report errors in the HTML format to the file named `report.html`.
145-
146117
[#input-paths]
147118
=== `input-paths`: custom source sets
148119

@@ -156,7 +127,7 @@ multiline string to specify multiple inputs.
156127
+
157128
[source,yaml]
158129
----
159-
- uses: saveourtool/benedikt@v1
130+
- uses: saveourtool/benedikt@v2
160131
with:
161132
input-paths: |
162133
path/to/file.kt
@@ -167,7 +138,7 @@ and all `\*.kt` and `*.kts` files are passed to _diKTat_.
167138
+
168139
[source,yaml]
169140
----
170-
- uses: saveourtool/benedikt@v1
141+
- uses: saveourtool/benedikt@v2
171142
with:
172143
input-paths: |
173144
src/main/kotlin
@@ -180,7 +151,7 @@ that match the path pattern. Path patterns may be negated, e. g.:
180151
+
181152
[source,yaml]
182153
----
183-
- uses: saveourtool/benedikt@v1
154+
- uses: saveourtool/benedikt@v2
184155
with:
185156
input-paths: |
186157
**/*.kt
@@ -220,7 +191,7 @@ JDK is not sufficient: you'll need to set **both** `java-distribution` **and**
220191

221192
[source,yaml]
222193
----
223-
- uses: saveourtool/benedikt@v1
194+
- uses: saveourtool/benedikt@v2
224195
with:
225196
java-distribution: 'temurin'
226197
java-version: 17
@@ -237,53 +208,17 @@ fatal (i.e. the current step terminates with a failure):
237208

238209
[source,yaml]
239210
----
240-
- uses: saveourtool/benedikt@v1
211+
- uses: saveourtool/benedikt@v2
241212
with:
242213
fail-on-error: true
243214
----
244215

245216
[NOTE]
246217

247218
This flag only affects the case when _diKTat_ exits with code **1**. Higher
248-
link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html#exit-codes[exit
219+
link:https://diktat.saveourtool.com/diktat-cli/#exit-codes[exit
249220
codes] are _always_ fatal.
250221

251-
=== `relative-paths`: relative or absolute paths
252-
253-
* Default: `true`
254-
* Required: **no**
255-
256-
If `true`, file paths get relativized with respect to the project directory.
257-
Otherwise, absolute file paths get reported. Example:
258-
259-
[source,yaml]
260-
----
261-
- uses: saveourtool/benedikt@v1
262-
with:
263-
relative-paths: true
264-
----
265-
266-
[NOTE]
267-
268-
When _SARIF_ xref:#reporter[reporter] is used, this flag has no effect: in
269-
_SARIF_ mode, paths reported are always absolute.
270-
271-
=== `color`: colorizing the plain-text output
272-
273-
* Default: `true`
274-
* Required: **no**
275-
276-
Setting this flag enables the console output to be colorized. This is only
277-
useful if the xref:#reporter[reporter] is set to `plain` or `plain?group_by_file`:
278-
279-
[source,yaml]
280-
----
281-
- uses: saveourtool/benedikt@v1
282-
with:
283-
reporter: plain
284-
color: true
285-
----
286-
287222
=== `debug`: enabling debug logging
288223

289224
* Default: `false`
@@ -293,7 +228,7 @@ Debug logging can be enabled by setting the `debug` input parameter to `true`:
293228

294229
[source,yaml]
295230
----
296-
- uses: saveourtool/benedikt@v1
231+
- uses: saveourtool/benedikt@v2
297232
with:
298233
debug: true
299234
----
@@ -314,7 +249,7 @@ jobs:
314249
- uses: actions/checkout@v4
315250
316251
- id: diktat
317-
uses: saveourtool/benedikt@v1
252+
uses: saveourtool/benedikt@v2
318253
319254
- name: 'Read the exit code of diKTat'
320255
if: ${{ always() }}
@@ -323,11 +258,4 @@ jobs:
323258
----
324259

325260
The exit codes are documented
326-
link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html#exit-codes[here].
327-
328-
[#diktat-cli]
329-
== Using the command-line client
330-
331-
Alternatively, if you wish to run _diKTat_ locally (e. g.: as a _Vim_ plug-in),
332-
or you're using a different CI/CD server, you can try the
333-
link:https://saveourtool.github.io/benedikt/docs/diktat-cli.html[command-line client].
261+
link:https://diktat.saveourtool.com/diktat-cli/#exit-codes[here].

action.yml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ inputs:
1818
required: false
1919
reporter:
2020
description: >
21-
The reporter to use, one of: "plain", "plain?group_by_file", "json",
22-
"sarif" (the default), "checkstyle", "html".
21+
The reporter to use, one of: "sarif" (the default) or "checkstyle".
2322
default: 'sarif'
2423
required: false
2524
input-paths:
@@ -53,22 +52,11 @@ inputs:
5352
examples of supported syntax at
5453
<https://github.com/actions/setup-java/blob/main/README.md#supported-version-syntax>.
5554
required: false
56-
color:
57-
description: >
58-
Colorize the output
59-
default: ${{ true }}
60-
required: false
6155
debug:
6256
description: >
6357
Whether debug logging should be enabled
6458
default: ${{ false }}
6559
required: false
66-
relative-paths:
67-
description: >
68-
Relativize file paths with respect to the working directory (if false,
69-
absolute file paths get reported)
70-
default: ${{ true }}
71-
required: false
7260
fail-on-error:
7361
description: >
7462
Whether linter errors are considered fatal (the default is true)
@@ -105,18 +93,26 @@ runs:
10593
# `steps.diktat.outputs.exit-code` variable.
10694
- id: diktat
10795
run: |
108-
DIKTAT_ARGS=('--config', '${{ inputs.config }}', '--reporter', '${{ inputs.reporter }}')
109-
if [[ '${{ inputs.color }}' != 'false' ]]
96+
if [[ '${{ inputs.debug }}' == 'true' ]]
11097
then
111-
DIKTAT_ARGS+=('--color-name')
98+
set -x
11299
fi
113-
if [[ '${{ inputs.debug }}' == 'true' ]]
100+
DIKTAT_ARGS=('--config' '${{ inputs.config }}' '--reporter' '${{ inputs.reporter }}')
101+
if [[ '${{ inputs.reporter }}' == 'sarif' ]]
102+
then
103+
report_file=${GITHUB_WORKSPACE}/report.sarif
104+
elif [[ '${{ inputs.reporter }}' == 'checkstyle' ]]
114105
then
115-
DIKTAT_ARGS+=('--log-level DEBUG')
106+
report_file=${GITHUB_WORKSPACE}/checkstyle-report.xml
107+
else
108+
echo "<reporter> should be set to <sarif> or <checkstyle>"
109+
exit 1
116110
fi
117-
if [[ '${{ inputs.relative-paths }}' != 'false' ]]
111+
DIKTAT_ARGS+=('--output' "${report_file}")
112+
113+
if [[ '${{ inputs.debug }}' == 'true' ]]
118114
then
119-
DIKTAT_ARGS+=('--relative')
115+
DIKTAT_ARGS+=('--log-level' 'DEBUG')
120116
fi
121117
122118
set -o pipefail
@@ -125,7 +121,10 @@ runs:
125121
DIKTAT_CMD=${GITHUB_WORKSPACE}/diktat
126122
chmod +x ${DIKTAT_CMD}
127123
{ ${DIKTAT_CMD} "${DIKTAT_ARGS[@]}" "${INPUT_PATHS[@]}" | tee diktat.log; } && exit_code=$? || exit_code=$?
128-
echo "summary-line=$(tail -n1 diktat.log 2>/dev/null)" >>$GITHUB_OUTPUT
124+
total_lines=$(wc -l diktat.log | cut -d ' ' -f1)
125+
summary_line_number=$(grep -n 'Summary error count (descending) by rule:' diktat.log | cut -d: -f1)
126+
summary_line=$(tail -n $((total_lines - summary_line_number)) diktat.log | sed -e 's/^ //g' | awk '{ printf("%s,", $0) }' | sed -e 's/,$//g')
127+
echo "summary-line=${summary_line}" >>$GITHUB_OUTPUT
129128
rm -f diktat.log
130129
echo "exit-code=${exit_code}" >>$GITHUB_OUTPUT
131130
env:
@@ -159,7 +158,7 @@ runs:
159158
if (( ${{ steps.diktat.outputs.exit-code }} != 0 ))
160159
then
161160
echo '```console' >>${GITHUB_STEP_SUMMARY}
162-
echo "${{ steps.diktat.outputs.summary-line }}" >>${GITHUB_STEP_SUMMARY}
161+
echo "${{ steps.diktat.outputs.summary-line }}" | xargs -d ',' -n1 echo >>${GITHUB_STEP_SUMMARY}
163162
echo '```' >>${GITHUB_STEP_SUMMARY}
164163
fi
165164
@@ -180,9 +179,9 @@ runs:
180179
# When in SARIF reporting mode, upload SARIF reports to GitHub.
181180
- id: upload-sarif
182181
if: ${{ always() && steps.diktat.outputs.exit-code == 1 && inputs.reporter == 'sarif' }}
183-
uses: github/codeql-action/upload-sarif@v2
182+
uses: github/codeql-action/upload-sarif@v3
184183
with:
185-
sarif_file: ${{ github.workspace }}
184+
sarif_file: ${{ github.workspace }}/report.sarif
186185

187186
# Alternatively, when in Checkstyle reporting mode, upload Checkstyle XML
188187
# using `reviewdog`.
@@ -205,7 +204,7 @@ runs:
205204
reviewdog_reporter='github-check'
206205
fi
207206
208-
reviewdog -f=checkstyle -fail-on-error=false -level=info -name='diKTat errors reported by reviewdog' -reporter="${reviewdog_reporter}" <checkstyle-report.xml
207+
reviewdog -f=checkstyle -fail-on-error=false -level=info -name='diKTat errors reported by reviewdog' -reporter="${reviewdog_reporter}" <${GITHUB_WORKSPACE}/checkstyle-report.xml
209208
env:
210209
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
211210
shell: bash

0 commit comments

Comments
 (0)