diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a349cd5d..8eff82b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -186,6 +186,46 @@ jobs: with: cache-default-branch-only: true + detekt: + permission: + contents: read + security-events: write + runs-on: ubuntu-latest + steps: + # Free GitHub Actions Environment Disk Space + - name: Maximize Build Space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + large-packages: false + + # Check out the current repository + - name: Fetch Sources + uses: actions/checkout@v4 + + # Set up Java environment for the next steps + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + gradle-home-cache-cleanup: true + + - name: Run Detekt + run: ./gradlew detektMain detektTest detektReportMergeSarif --continue + + - name: Upload Detekt Report + uses: github/codeql-action/upload-sarif@v3 + if: success() || failure() + with: + sarif_file: 'build/reports/detekt/merge.sarif.json' + + # Run plugin structure verification along with IntelliJ Plugin Verifier verify: name: Verify plugin @@ -235,4 +275,3 @@ jobs: with: name: pluginVerifier-result path: ${{ github.workspace }}/build/reports/pluginVerifier - diff --git a/build.gradle.kts b/build.gradle.kts index 0e2de323..a6f7e454 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +import io.gitlab.arturbosch.detekt.Detekt +import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask +import io.gitlab.arturbosch.detekt.report.ReportMergeTask import org.jetbrains.changelog.Changelog import org.jetbrains.changelog.markdownToHTML import org.jetbrains.intellij.platform.gradle.Constants.Constraints @@ -13,6 +16,7 @@ plugins { alias(libs.plugins.changelog) // Gradle Changelog Plugin alias(libs.plugins.qodana) // Gradle Qodana Plugin alias(libs.plugins.kover) // Gradle Kover Plugin + alias(libs.plugins.detekt) // Gradle Detekt Plugin } group = providers.gradleProperty("pluginGroup").get() @@ -138,6 +142,48 @@ tasks { } } +val detektReportMergeSarif by tasks.registering(ReportMergeTask::class) { + output = layout.buildDirectory.file("reports/detekt/merge.sarif.json") +} + +allprojects { + apply(plugin = "io.gitlab.arturbosch.detekt") + + detekt { + buildUponDefaultConfig = true + baseline = file("$rootDir/config/detekt/baseline.xml") + } + + dependencies { + detekt("io.gitlab.arturbosch.detekt:detekt-cli:${rootProject.libs.versions.detekt.get()}") + detekt("io.gitlab.arturbosch.detekt:detekt-formatting:${rootProject.libs.versions.detekt.get()}") + detekt(project(":mise-core")) + detekt(project(":mise-products-goland")) + detekt(project(":mise-products-gradle")) + detekt(project(":mise-products-idea")) + detekt(project(":mise-products-nodejs")) + detekt(project(":mise-products-rider")) + detekt(project(":mise-products-toml")) + } + + tasks.withType().configureEach { + jvmTarget = "17" + reports { + xml.required = true + html.required = true + sarif.required = true + md.required = true + } + basePath = rootDir.absolutePath + } + detektReportMergeSarif { + input.from(tasks.withType().map { it.reports.sarif.outputLocation }) + } + tasks.withType().configureEach { + jvmTarget = "17" + } +} + val runIdeForUnitTests by intellijPlatformTesting.runIde.registering { task { jvmArgumentProviders += diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cb959fc7..d89b60da 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,6 +8,7 @@ gradleIdeaExt = "1.1.9" kotlin = "2.1.0" kover = "0.9.0" qodana = "2024.2.6" +detekt = "1.23.7" [libraries] junit = { group = "junit", name = "junit", version.ref = "junit" } @@ -18,3 +19,4 @@ gradleIdeaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "gr kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }