Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ jobs:
with:
category: "KTlint"

detekt:
needs: [lockfiles, yamllint]
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- uses: ./.github/actions/setup-build-env
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
mock-google-services: "true"

# Since `build-logic` is added with `includeBuild` we have to call detekt explicitly on `:convention`.
- name: Validate Detekt
run: ./gradlew detekt :build-logic:convention:detekt --continue

- uses: ./.github/actions/upload-sarif-results
if: always()
with:
category: "Detekt"

lint:
needs: [lockfiles, ktlint]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -191,7 +215,7 @@ jobs:

screenshot_test:
name: "Screenshot Tests"
needs: [lint, lockfiles, ktlint]
needs: [detekt, lint, lockfiles, ktlint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
Expand Down Expand Up @@ -298,7 +322,7 @@ jobs:

unit_tests:
name: "Unit Tests"
needs: [lint, lockfiles, ktlint]
needs: [detekt, lint, lockfiles, ktlint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
Expand All @@ -321,7 +345,7 @@ jobs:

build_emulator_wtf_apks:
name: "Build Emulator.wtf APKs"
needs: [lint, lockfiles, ktlint]
needs: [detekt, lint, lockfiles, ktlint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
Expand Down Expand Up @@ -361,7 +385,7 @@ jobs:

instrumentation_test:
name: "Instrumentation Tests"
needs: [lint, lockfiles, ktlint]
needs: [detekt, lint, lockfiles, ktlint]
runs-on: ubuntu-latest
strategy:
# We want the result of each device to be reported, so we can't fail-fast
Expand Down
25 changes: 25 additions & 0 deletions .idea/runConfigurations/Detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 53 additions & 10 deletions app/gradle.lockfile

Large diffs are not rendered by default.

63 changes: 53 additions & 10 deletions automotive/gradle.lockfile

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import dev.detekt.gradle.Detekt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

plugins {
`kotlin-dsl`
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}

group = "io.homeassistant.companion.android.buildlogic"

allprojects {
apply(plugin = rootProject.libs.plugins.detekt.get().pluginId)
apply(plugin = rootProject.libs.plugins.ktlint.get().pluginId)

ktlint {
Expand All @@ -24,6 +27,17 @@ allprojects {
exclude { it.file.path.contains("build${File.separator}generated-sources") }
}
}

detekt {
baseline = rootProject.file("../config/detekt/baseline-build-logic-$name.xml")
}
Comment thread
loganrosen marked this conversation as resolved.
Outdated

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
sarif.required.set(true)
}
}
}

// Configure the build-logic plugins to target JDK 17 and is not related to what is running on device.
Expand Down
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import dev.detekt.gradle.Detekt
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

val kotlinVersion = libs.versions.kotlin.get()

plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)

alias(libs.plugins.aboutlibraries).apply(false)
Expand All @@ -20,8 +22,11 @@ plugins {
}

allprojects {
apply(plugin = rootProject.libs.plugins.detekt.get().pluginId)
apply(plugin = rootProject.libs.plugins.ktlint.get().pluginId)

val detektBaselineName = if (path == ":") "root" else path.removePrefix(":").replace(':', '-')
Comment thread
jpelgrom marked this conversation as resolved.
Outdated

// TODO this has been added until https://youtrack.jetbrains.com/issue/KT-87220/Kotlin-Gradle-plugin-resolves-kotlinAbiValidationCompatClasspath-to-newer-beta-Kotlin-artifacts-during-dependency-locking is addressed
configurations.matching { it.name == "kotlinAbiValidationCompatClasspath" }.configureEach {
resolutionStrategy.eachDependency {
Expand Down Expand Up @@ -54,6 +59,17 @@ allprojects {
}
}

detekt {
baseline = rootProject.file("config/detekt/baseline-$detektBaselineName.xml")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the initial PR I did I added basic rule file https://github.com/home-assistant/android/pull/5312/changes#diff-ea29de1180303564fca0c4eddb30f7da4b596754f2c139fc252ae290e3d201e2 to match Ktlint line length constraint. Having the file is important to override some rules that we don't want to apply to the project and I think setting up this file should be part of this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added config/detekt/detekt.yml, wired it into both Gradle builds, and enabled buildUponDefaultConfig. The initial override keeps MaxLineLength aligned with ktlint at 120 characters while retaining Detekt defaults for the other rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After comparing the actual findings with ktlint and current project conventions, the shared configuration now disables MaxLineLength, FunctionNaming, and TooGenericExceptionCaught while building on the remaining Detekt defaults.

}

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
sarif.required.set(true)
}
}

dependencyLocking {
lockAllConfigurations()
}
Expand Down
Loading
Loading