From a2370c4d6dfe12c8f5e6428a614cc3186b30480e Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Fri, 9 Jun 2023 13:08:16 +0300 Subject: [PATCH] Github action for snapshot diktat --- .github/workflows/diktat.yml | 49 +++++++++++++++++++ .github/workflows/diktat_snapshot.yml | 24 +++++++++ README.md | 2 +- gradle/libs.versions.toml | 2 + gradle/plugins/build.gradle.kts | 4 ++ .../code-quality-convention.gradle.kts | 4 ++ ...diktat-convention-configuration.gradle.txt | 26 ++++++++++ 7 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/diktat.yml create mode 100644 gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.txt diff --git a/.github/workflows/diktat.yml b/.github/workflows/diktat.yml new file mode 100644 index 0000000000..1e92f65d1d --- /dev/null +++ b/.github/workflows/diktat.yml @@ -0,0 +1,49 @@ +name: Run diKTat (release) + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + diktat_check: + runs-on: ubuntu-latest + permissions: + # required for all workflows + security-events: write + + steps: + - name: This action is disabled until the release 2.0.0 + run: | + echo "This action is disabled until the release 2.0.0" +# - uses: actions/checkout@v3 +# - name: Set up JDK 11 +# uses: actions/setup-java@v3 +# with: +# java-version: 11 +# distribution: temurin +# - uses: gradle/gradle-build-action@v2 +# with: +# gradle-version: wrapper +# arguments: | +# diktatCheck +# mergeDiktatReports +# -Pdiktat.githubActions=true +# -Pdetekt.multiplatform.disabled=true +# --build-cache +# --continue +# -PgprUser=${{ github.actor }} +# -PgprKey=${{ secrets.GITHUB_TOKEN }} +# - name: Upload SARIF report to Github +# uses: github/codeql-action/upload-sarif@v2 +# if: ${{ always() }} +# with: +# sarif_file: build/reports/diktat/diktat-merged.sarif +# - name: Upload SARIF artifacts +# uses: actions/upload-artifact@v3 +# if: ${{ failure() }} +# with: +# name: sarif-reports +# path: "**/build/reports/diktat" +# retention-days: 1 diff --git a/.github/workflows/diktat_snapshot.yml b/.github/workflows/diktat_snapshot.yml index 484378df23..dad1cb6a57 100644 --- a/.github/workflows/diktat_snapshot.yml +++ b/.github/workflows/diktat_snapshot.yml @@ -61,6 +61,30 @@ jobs: mv gradle/libs.versions.toml gradle/libs.versions.toml_current mv build/diktat-snapshot/libs.versions.toml_snapshot gradle/libs.versions.toml + # FixMe: remove after 2.0.0 + - name: 'Small hack to inject implementation and to run diktat properly from snapshot' + run: | + #!/bin/bash + line_number=26 + file_path=gradle/plugins/build.gradle.kts + string_to_insert='implementation(libs.diktat.gradle.plugin) { + exclude("io.github.detekt.sarif4k", "sarif4k") + }' + + # Escape the special characters in the string + escaped_string=$(sed 's/[\/&]/\\&/g' <<< "$string_to_insert") + + # Create a temporary file + tmp_file=$(mktemp) + + # Insert the string as multiple lines after the specified line number + sed "${line_number}r /dev/stdin" "$file_path" <<< "$escaped_string" > "$tmp_file" + + # Move the temporary file to overwrite the original file + mv "$tmp_file" "$file_path" + + echo "String inserted successfully." + # copied from .github/workflows/diktat.yml - uses: gradle/gradle-build-action@v2 with: diff --git a/README.md b/README.md index f20c72fe3b..e76eadc70c 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Main features of diktat are the following: **OR** use `curl`: ```console - $ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.5/diktat-1.2.5.jar + $ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.5/diktat-1.2.5.jar && chmod a+x diktat ``` ### Run diKTat diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1d8e5032d1..555fd505c6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -41,6 +41,7 @@ okio = "3.3.0" kotlinx-datetime = "0.4.0" kotlinx-coroutines = "1.6.4" assertj = "3.24.2" +diktat = "2.0.0" jgit = "6.5.0.202303070854-r" mockito = "5.2.0" mockito-kotlin = "4.1.0" @@ -166,6 +167,7 @@ validation-api = { module = "jakarta.validation:jakarta.validation-api"} annotation-api = { module = "jakarta.annotation:jakarta.annotation-api"} # code quality +diktat-gradle-plugin = { module = "org.cqfn.diktat:diktat-gradle-plugin", version.ref = "diktat" } detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } gradle-plugin-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" } reckon-gradle-plugin = { module = "org.ajoberstar.reckon:reckon-gradle", version.ref = "reckon" } diff --git a/gradle/plugins/build.gradle.kts b/gradle/plugins/build.gradle.kts index c3383a38f3..07b3ca911c 100644 --- a/gradle/plugins/build.gradle.kts +++ b/gradle/plugins/build.gradle.kts @@ -24,6 +24,10 @@ dependencies { implementation(libs.detekt.gradle.plugin) { exclude("io.github.detekt.sarif4k", "sarif4k") } + // FixMe: return after 2.0.0 + /* implementation(libs.diktat.gradle.plugin) { + exclude("io.github.detekt.sarif4k", "sarif4k") + }*/ implementation(libs.sarif4k) implementation(libs.gradle.plugin.spotless) implementation(libs.publish.gradle.plugin) diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/code-quality-convention.gradle.kts b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/code-quality-convention.gradle.kts index 5f5d1764d8..c08fad2fdd 100644 --- a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/code-quality-convention.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/code-quality-convention.gradle.kts @@ -2,4 +2,8 @@ package com.saveourtool.diktat.buildutils plugins { id("com.saveourtool.diktat.buildutils.detekt-convention-configuration") + // FixMe: remove after 2.0.0 + if (System.getenv("DIKTAT_SNAPSHOT") != null) { + id("com.saveourtool.diktat.buildutils.diktat-convention-configuration") + } } diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.txt b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.txt new file mode 100644 index 0000000000..bdaf039821 --- /dev/null +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.txt @@ -0,0 +1,26 @@ +package org.cqfn.diktat.buildutils + + +plugins { + id("org.cqfn.diktat.diktat-gradle-plugin") +} + +diktat { + diktatConfigFile = rootProject.file("diktat-analysis.yml") + githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false + inputs { + // using `Project#path` here, because it must be unique in gradle's project hierarchy + if (path == rootProject.path) { + include("gradle/plugins/src/**/*.kt", "*.kts", "gradle/plugins/**/*.kts") + exclude("gradle/plugins/build/**") + } else { + include("src/**/*.kt", "**/*.kts") + exclude( + "src/test/**/*.kt", + "src/test/**/*.kts", + "src/*Test/**/*.kt", + "build/**/*.kts", + ) + } + } +}