Skip to content

Commit 794159f

Browse files
authored
Merge pull request #258 from modelix/feature/detekt-integration
ci: include detekt with GitHub code security analysis
2 parents 6084aa6 + e2ee65c commit 794159f

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

.detekt.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
style:
2+
# handled by ktlint
3+
MaxLineLength:
4+
active: false
5+
ModifierOrder:
6+
active: false
7+
8+
# No need for this
9+
ReturnCount:
10+
active: false
11+
ThrowsCount:
12+
active: false

.github/workflows/build.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
arguments: |
2929
--build-cache
3030
build
31+
detekt
3132
-PciBuild=true
3233
- name: Archive test report
3334
uses: actions/upload-artifact@v3
@@ -37,6 +38,17 @@ jobs:
3738
path: |
3839
*/build/test-results
3940
*/build/reports
41+
# In theory, the upload action should take care of stripping the GitHub
42+
# runner workspace path from the file paths. But somehow that doesn't
43+
# work. So do it manually.
44+
- name: relativize SARIF file paths
45+
run: |
46+
sed -i 's#${{ github.workspace }}/##' build/reports/detekt/*.sarif
47+
- name: Upload SARIF file
48+
uses: github/codeql-action/upload-sarif@v2
49+
with:
50+
sarif_file: 'build/reports/detekt/'
51+
category: detekt
4052

4153
test-model-api-gen-gradle:
4254
runs-on: ubuntu-latest

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import com.github.gradle.node.NodeExtension
22
import com.github.gradle.node.NodePlugin
3+
import io.gitlab.arturbosch.detekt.Detekt
34
import kotlinx.html.FlowContent
45
import kotlinx.html.a
56
import kotlinx.html.body
@@ -44,6 +45,7 @@ plugins {
4445
alias(libs.plugins.tasktree)
4546
alias(libs.plugins.dokka)
4647
alias(libs.plugins.node) apply false
48+
alias(libs.plugins.detekt) apply false
4749
}
4850

4951
group = "org.modelix"
@@ -65,11 +67,14 @@ dependencies {
6567
dokkaPlugin(libs.dokka.versioning)
6668
}
6769

70+
val parentProject = project
71+
6872
subprojects {
6973
val subproject = this
7074
apply(plugin = "maven-publish")
7175
apply(plugin = "org.jetbrains.dokka")
7276
apply(plugin = "org.jlleitschuh.gradle.ktlint")
77+
apply(plugin = "io.gitlab.arturbosch.detekt")
7378

7479
version = rootProject.version
7580
group = rootProject.group
@@ -85,6 +90,22 @@ subprojects {
8590
version.set("0.50.0")
8691
}
8792

93+
tasks.withType<Detekt> {
94+
parallel = true
95+
// For now, we only use the results here as hints
96+
ignoreFailures = true
97+
98+
buildUponDefaultConfig = true
99+
config.setFrom(parentProject.projectDir.resolve(".detekt.yml"))
100+
101+
reports {
102+
sarif.required.set(true)
103+
// This is required for the GitHub upload action to easily find all sarif files in a single directory.
104+
sarif.outputLocation.set(parentProject.buildDir.resolve("reports/detekt/${project.name}.sarif"))
105+
html.required.set(true)
106+
}
107+
}
108+
88109
val kotlinApiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6
89110
subproject.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
90111
if (!name.lowercase().contains("test")) {

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tasktree = { id = "com.dorongold.task-tree", version = "2.1.1" }
1717
modelix-mps-buildtools = { id = "org.modelix.mps.build-tools", version = "1.1.0" }
1818
dokka = {id = "org.jetbrains.dokka", version = "1.9.0"}
1919
node = {id = "com.github.node-gradle.node", version = "7.0.1"}
20+
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.1" }
2021

2122
[versions]
2223
kotlin = "1.9.10"

0 commit comments

Comments
 (0)