Skip to content

Commit

Permalink
fix detekt merged report name; Use sarif format
Browse files Browse the repository at this point in the history
  • Loading branch information
uzzu committed Dec 17, 2023
1 parent 575e24f commit 61dd802
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run reviewdog
if: always()
run: |
find . -type f -name "ktlint*Check.xml" -exec sh -c "cat {} | reviewdog -f=checkstyle -name='ktlint' -reporter=github-pr-review" \;
cat build/reports/detekt/detekt-merged-report.sarif | reviewdog -f=sarif -name="detekt" -reporter="github-check" -level="error" -filter-mode="nofilter" -fail-on-error
- name: Gradle publish to mavenLocal
run: |
./gradlew publishToMavenLocal
Expand Down
24 changes: 14 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,33 @@ plugins {
alias(libs.plugins.gradle.plugin.publish) apply false
}

detektConfigurationRoot()
val reportMerge by tasks.registering(ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/detekt-merged-report.sarif"))
}

detektConfigurationRoot(reportMerge)

subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
detektConfigurationShared()
detektConfigurationShared(reportMergeTask = reportMerge)
}

// region detekt configuration

fun Project.detektConfigurationRoot() {
fun Project.detektConfigurationRoot(
reportMergeTask: TaskProvider<ReportMergeTask>,
) {
val allKtsFiles = allKtsFiles()
detektConfigurationShared(
reportMergeTask = reportMergeTask,
source = allKtsFiles
+ allBuildSrcKtFiles()
+ files("src"),
)
}

fun Project.detektConfigurationShared(
reportMergeTask: TaskProvider<ReportMergeTask>,
source: List<Any> = listOf(files("src")),
detektConfig: File = rootProject.file("./gradle/detekt.yml"),
) {
Expand All @@ -45,17 +53,13 @@ fun Project.detektConfigurationShared(
parallel = true
}

val reportMerge by tasks.registering(ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/merge.xml"))
}

tasks.withType<Detekt>().configureEach {
finalizedBy(reportMerge)
reports.xml.required = true
reports.sarif.required = true
}

reportMerge {
input.from(tasks.withType<Detekt>().map { it.xmlReportFile })
reportMergeTask {
input.from(tasks.withType<Detekt>().map { it.sarifReportFile })
}
}

Expand Down
1 change: 0 additions & 1 deletion gradle/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ output-reports:
- 'TxtOutputReport'
- 'HtmlOutputReport'
- 'MdOutputReport'
- 'SarifOutputReport'

comments:
active: true
Expand Down

0 comments on commit 61dd802

Please sign in to comment.