Skip to content

Latest commit

 

History

History
154 lines (123 loc) · 3.98 KB

README.adoc

File metadata and controls

154 lines (123 loc) · 3.98 KB

This is a template Gradle project (Groovy DSL flavour) which uses DiKTat to check the style of your code.

If your project has multiple modules, be sure to pass the --continue flag to Gradle:

./gradlew --continue diktatCheck

Here’s a sample DiKTat configuration. Depending on whether you pass the -Pdiktat.githubActions=true property to Gradle, the output will be written either in plain text format to the standard output, or in the SARIF format to a report file:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'org.cqfn.diktat', name: 'diktat-gradle-plugin', version: 1.2.3
    }
}

apply plugin: 'org.cqfn.diktat.diktat-gradle-plugin'

diktat {
    inputs {
        it.include("src/**/*.kt", "*.kts", "src/**/*.kts")
        it.exclude("build/**")
    }

    def sarifOutput = Boolean.parseBoolean(project.findProperty("diktat.githubActions"))

    reporter = sarifOutput ? "sarif" : "plain"

    output = sarifOutput ? "build/reports/diktat/diktat.sarif" : ""

    debug = false
}

reporter can be one of:

  • html,

  • json,

  • plain (the default), and

  • sarif.

If the output field is empty, reports will be written to the standard output.

While it’s possible to configure reporter and output independently, you may consider using the githubActions flag instead. This configuration is effectively equivalent to the one above:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'org.cqfn.diktat', name: 'diktat-gradle-plugin', version: 1.2.3
    }
}

apply plugin: 'org.cqfn.diktat.diktat-gradle-plugin'

diktat {
    inputs {
        it.include("src/**/*.kt", "*.kts", "src/**/*.kts")
        it.exclude("build/**")
    }

    githubActions = Boolean.parseBoolean(project.findProperty("diktat.githubActions"))

    debug = false
}

You can integrate with GitHub Actions and make code scanning results (e.g.: after a pull request) immediately available by adding a YAML file of the following content under .github/workflows (uses github/codeql-action/upload-sarif@v2):

name: Run diKTat

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  GRADLE_OPTS: -Dorg.gradle.daemon=false

jobs:
  diktat_check:
    runs-on: ubuntu-20.04

    permissions:
      security-events: write

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'zulu'
          java-package: jdk+fx
          cache: gradle
      - uses: gradle/gradle-build-action@v2
        with:
          gradle-version: wrapper
          arguments: |
            --continue
            diktatCheck
            -Pdiktat.githubActions=true
      - name: Copy SARIF reports into a single directory
        if: ${{ always() }}
        run: |
          mkdir -p build/diktat-sarif-reports
          i=0
          find -path '*/build/reports/diktat/*.sarif' | while read -r f; do cp "$f" "build/diktat-sarif-reports/diktat-$((i++)).sarif"; done
      - name: Upload SARIF reports to GitHub
        if: ${{ always() }}
        uses: github/codeql-action/upload-sarif@v2
        with:
          sarif_file: build/diktat-sarif-reports

The shell script fragment:

mkdir -p build/diktat-sarif-reports
i=0
find -path '*/build/reports/diktat/*.sarif' | while read -r f; \
do \
    cp "$f" "build/diktat-sarif-reports/diktat-$((i++)).sarif"; \
done

 — merely copies all the generated SARIF reports into a single directory, so that they can be read by GitHub.