Skip to content

saveourtool/benedikt

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

A GitHub Action to check your code with diKTat

License: MIT
GitHub release
Ubuntu Linux
macOS
Windows
💡

An always updated version of this document is available here as a PDF e-book.

Features

  • Customizable diktat-analysis.yml location. You can use the rule set configuration with an alternate name or at a non-default location.

  • Customizable JVM vendor and version. You can run diKTat using a default JVM, or you can set up your own one.

  • Customizable reporter (SARIF or Checkstyle XML).

  • Allows multiple input paths. If you have a multi-module project and only wish to check certain directories or modules, you can configure the action accordingly.

  • The summary page contains statistic about detected errors:

    diKTat Check summary

Usage

In the simplest scenario, the action can be used without input parameters; you just need to check out your code first, using actions/checkout:

jobs:
  diktat_check:
    name: 'diKTat Check'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: saveourtool/benedikt@v2

Configuration

config: custom configuration file

  • Default: diktat-analysis.yml

  • Required: no

You can override the name or the path of your YAML configuration file using the config input parameter, e. g.:

      - uses: saveourtool/benedikt@v2
        with:
          config: path/to/diktat-analysis-custom.yml

reporter: requesting a type of reporter

If you wish, you can report errors in a different format.

  • Default: sarif

  • Required: no

  • Possible values: any of the following.

    • sarif: report errors in the SARIF format. The output file will be named report.sarif and automatically uploaded to GitHub using the upload-sarif action. This will enable the check results to be shown as annotations in the pull request:

      diKTat SARIF reporting (Pull Request)

      as well as in the Code scanning alerts section of your repository:

      diKTat SARIF reporting (Code scanning alerts)
    • checkstyle: this is the reporter of choice if you ever encounter issues with the sarif reporter. Errors are reported in the Checkstyle-XML format to the file named checkstyle-report.xml. The report is then consumed by the reviewdog tool and uploaded to GitHub, resulting in code annotations similar to those produced by the sarif reporter:

      Checkstyle-XML reporting assisted by reviewdog

input-paths: custom source sets

  • Default: none

  • Required: no

One or more patterns which indicate the files or directories to check. Use a multiline string to specify multiple inputs.

  • If an input is a path to a file, it is passed to diKTat as-is:

          - uses: saveourtool/benedikt@v2
            with:
              input-paths: |
                path/to/file.kt
  • If an input is a path to a directory, the directory is recursively traversed, and all *.kt and *.kts files are passed to diKTat.

          - uses: saveourtool/benedikt@v2
            with:
              input-paths: |
                src/main/kotlin
                src/test/kotlin
  • If an input is an Ant-style path pattern (such as **/*.kt), diKTat expands it into the list of files that match the path pattern. Path patterns may be negated, e. g.: !src/**/*Test.kt or !src/**/generated/**.

          - uses: saveourtool/benedikt@v2
            with:
              input-paths: |
                **/*.kt
                **/*.kts
                !**/generated/**

If this input parameter is not specified, this is equivalent to setting it to ., meaning diKTat will check all *.kt and *.kts files in the project directory unless configured otherwise.

java-distribution and java-version: running diKTat using a custom JVM

It’s possible to run diKTat with a custom JVM using the actions/setup-java action. The following input parameters may be specified:

Note
Setting just the java-distribution property in order to use a custom JDK is not sufficient: you’ll need to set both java-distribution and java-version:
      - uses: saveourtool/benedikt@v2
        with:
          java-distribution: 'temurin'
          java-version: 17

fail-on-error: suppressing lint errors

  • Default: true

  • Required: no

If false, the errors are still reported, but the step completes successfully. If true (the default), then lint errors reported by diKTat are considered fatal (i.e. the current step terminates with a failure):

      - uses: saveourtool/benedikt@v2
        with:
          fail-on-error: true
Note
This flag only affects the case when diKTat exits with code 1. Higher exit codes are always fatal.

debug: enabling debug logging

  • Default: false

  • Required: no

Debug logging can be enabled by setting the debug input parameter to true:

      - uses: saveourtool/benedikt@v2
        with:
          debug: true

Outputs

The action returns the exit code of the command-line client using the exit-code output parameter, e. g.:

jobs:
  diktat_check:
    name: 'diKTat Check'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - id: diktat
        uses: saveourtool/benedikt@v2

      - name: 'Read the exit code of diKTat'
        if: ${{ always() }}
        run: echo "diKTat exited with code ${{ steps.diktat.outputs.exit-code }}"
        shell: bash

The exit codes are documented here.