Skip to content

Commit 4945b06

Browse files
committed
Add detekt script and workflow
1 parent 98daa6c commit 4945b06

File tree

9 files changed

+190
-89
lines changed

9 files changed

+190
-89
lines changed

.github/workflows/_detekt.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Detekt Static Analysis
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
detekt:
11+
name: Run Detekt Analysis
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up JDK 17
19+
uses: actions/setup-java@v4
20+
with:
21+
distribution: temurin
22+
java-version: 17
23+
24+
- name: Cache Gradle
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.gradle/caches
29+
~/.gradle/wrapper
30+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
31+
restore-keys: |
32+
${{ runner.os }}-gradle-
33+
34+
- name: Grant execute permission for Gradle wrapper
35+
run: chmod +x gradlew
36+
37+
- name: Run Detekt
38+
run: ./gradlew detekt

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,33 @@ jobs:
1818
name: Check Copyright Headers
1919
uses: ./.github/workflows/_copyright.yml
2020

21+
detekt:
22+
name: Static Analysis
23+
uses: ./.github/workflows/_detekt.yml
24+
2125
test:
2226
name: Unit Tests
23-
needs: [format, copyright]
27+
needs: [format, copyright, detekt]
2428
uses: ./.github/workflows/_test.yml
2529

2630
coverage:
2731
name: Test Coverage
28-
needs: [format, copyright]
32+
needs: [format, copyright, detekt]
2933
uses: ./.github/workflows/_coverage.yml
3034

3135
docs:
3236
name: Documentation
33-
needs: [format, copyright]
37+
needs: [format, copyright, detekt]
3438
uses: ./.github/workflows/_docs.yml
3539

3640
build-library:
3741
name: Build Library
38-
needs: [format, copyright, test, coverage, docs]
42+
needs: [format, copyright, detekt, test, coverage, docs]
3943
uses: ./.github/workflows/_build-library.yml
4044

4145
build-examples:
4246
name: Build Examples
43-
needs: [format, copyright, test, coverage, docs]
47+
needs: [format, copyright, detekt, test, coverage, docs]
4448
uses: ./.github/workflows/_build-examples.yml
4549

4650
instrumented-test:

.github/workflows/release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,29 @@ jobs:
1313
name: Check Formatting
1414
uses: ./.github/workflows/_format.yml
1515

16+
detekt:
17+
name: Static Analysis
18+
uses: ./.github/workflows/_detekt.yml
19+
1620
test:
1721
name: Unit Tests
18-
needs: format
22+
needs: [format, detekt]
1923
uses: ./.github/workflows/_test.yml
2024

2125
build-library:
2226
name: Build Library
23-
needs: [format, test]
27+
needs: [format, detekt, test]
2428
uses: ./.github/workflows/_build-library.yml
2529

2630
build-examples:
2731
name: Build Examples
28-
needs: [format, test]
32+
needs: [format, detekt, test]
2933
uses: ./.github/workflows/_build-examples.yml
3034

3135
publish:
3236
name: Publish to Maven Central
3337
runs-on: ubuntu-latest
34-
needs: [format, test, build-library, build-examples]
38+
needs: [format, detekt, test, build-library, build-examples]
3539

3640
steps:
3741
- name: Checkout repository

build.gradle.kts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ plugins {
2424
alias(libs.plugins.kotlin.compose) apply false
2525
alias(libs.plugins.spotless) apply false
2626
alias(libs.plugins.dokka) apply false
27+
alias(libs.plugins.detekt) apply false
2728
alias(libs.plugins.nmcp)
2829
}
2930

@@ -37,3 +38,24 @@ nmcpAggregation {
3738
publishAllProjectsProbablyBreakingProjectIsolation()
3839
}
3940

41+
subprojects {
42+
afterEvaluate {
43+
if (plugins.hasPlugin("org.jetbrains.kotlin.android")) {
44+
apply(plugin = "io.gitlab.arturbosch.detekt")
45+
46+
extensions.configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {
47+
buildUponDefaultConfig = true
48+
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
49+
}
50+
51+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
52+
reports {
53+
html.required.set(true)
54+
xml.required.set(true)
55+
sarif.required.set(true)
56+
}
57+
}
58+
}
59+
}
60+
}
61+

config/detekt/detekt.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
build:
2+
maxIssues: 0
3+
4+
formatting:
5+
active: false
6+
7+
complexity:
8+
active: true
9+
LongMethod:
10+
threshold: 60
11+
LongParameterList:
12+
threshold: 6
13+
ComplexMethod:
14+
threshold: 15
15+
16+
style:
17+
active: true
18+
MagicNumber:
19+
ignoreNumbers:
20+
- '-1'
21+
- '0'
22+
- '1'
23+
- '2'
24+
ignorePropertyDeclaration: true
25+
ignoreAnnotation: true
26+
27+
naming:
28+
active: true
29+
30+
potential-bugs:
31+
active: true
32+
33+
performance:
34+
active: true

docs/GITHUB_WORKFLOWS.md

Lines changed: 43 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Located in `.github/workflows/`:
3838
- **Usage**: Called by CI and Release workflows
3939
- **Fast**: ~30 seconds
4040

41+
#### `_detekt.yml`
42+
- **Purpose**: Run Detekt static code analysis
43+
- **Runs**: `./gradlew detekt`
44+
- **Usage**: Called by CI and Release workflows
45+
- **Duration**: ~1-2 minutes
46+
- **Reports**: HTML, XML, and SARIF reports generated
47+
4148
#### `_coverage.yml`
4249
- **Purpose**: Check test coverage meets minimum threshold
4350
- **Runs**: `./scripts/check-coverage.sh` (minimum threshold defined in [Contributing Guide](CONTRIBUTING.md#test-coverage))
@@ -89,41 +96,26 @@ Located in `.github/workflows/`:
8996

9097
**Execution Flow**:
9198
```
92-
format (Check formatting)
93-
|
94-
v
95-
copyright (Check headers)
96-
|
97-
v
98-
+----------------+----------------+----------------+
99-
| | |
100-
v v v
101-
test docs coverage
102-
(Unit tests) (Build API docs) (Test coverage)
103-
| | |
104-
+----------------+----------------+----------------+
105-
|
106-
+--------------------------+-------------------------+
107-
| |
108-
v v
109-
build-library build-examples
110-
(Build AAR) (Build 3 APKs)
99+
format ────┐
100+
101+
copyright ─┼──→ test/coverage/docs ──→ build-library
102+
│ │
103+
detekt ────┘ └──→ build-examples
111104
112105
For Pull Requests only:
113-
v
114-
instrumented-test (Phone + Automotive)
115-
(Runs in parallel, not blocking)
106+
instrumented-test (Phone + Automotive) runs in parallel
116107
```
117108

118109
**Jobs**:
119110
1. **format** - Runs Spotless formatting check
120111
2. **copyright** - Verifies MIT license headers
121-
3. **test** - Runs unit tests (depends on format + copyright)
122-
4. **docs** - Builds API documentation with Dokka (depends on format + copyright)
123-
5. **coverage** - Checks test coverage meets 20% minimum (depends on format + copyright)
124-
6. **build-library** - Builds library AAR (depends on format + copyright + test + docs + coverage, runs in parallel with build-examples)
125-
7. **build-examples** - Builds example APKs (depends on format + copyright + test + docs + coverage, runs in parallel with build-library)
126-
8. **instrumented-test** - Runs instrumentation tests on phone and automotive emulators (PR only, required status check)
112+
3. **detekt** - Runs Detekt static code analysis
113+
4. **test** - Runs unit tests (depends on format + copyright + detekt)
114+
5. **docs** - Builds API documentation with Dokka (depends on format + copyright + detekt)
115+
6. **coverage** - Checks test coverage meets 20% minimum (depends on format + copyright + detekt)
116+
7. **build-library** - Builds library AAR (depends on all above, runs in parallel with build-examples)
117+
8. **build-examples** - Builds example APKs (depends on all above, runs in parallel with build-library)
118+
9. **instrumented-test** - Runs instrumentation tests on phone and automotive emulators (PR only)
127119

128120
**Total Duration**:
129121
- **Maintainer pushes to main**: ~3-4 minutes (no instrumentation tests)
@@ -143,30 +135,19 @@ instrumented-test (Phone + Automotive)
143135

144136
**Execution Flow**:
145137
```
146-
format (Check formatting)
147-
|
148-
v
149-
test (Run unit tests)
150-
|
151-
v
152-
+----------------+----------------+
153-
| |
154-
v v
155-
build-library build-examples
156-
| |
157-
+-----------------+---------------+
158-
|
159-
v
160-
publish
161-
(Maven Central + GitHub Release)
138+
format ────┐
139+
├──→ test ──→ build-library ──┐
140+
detekt ────┘ │ ├──→ publish
141+
└──→ build-examples ──┘
162142
```
163143

164144
**Jobs**:
165145
1. **format** - Runs Spotless formatting check
166-
2. **test** - Runs unit tests (depends on format)
167-
3. **build-library** - Builds library AAR (depends on format + test)
168-
4. **build-examples** - Builds example APKs (depends on format + test)
169-
5. **publish** - Publishes to Maven Central and creates GitHub Release (depends on all above)
146+
2. **detekt** - Runs Detekt static code analysis
147+
3. **test** - Runs unit tests (depends on format + detekt)
148+
4. **build-library** - Builds library AAR (depends on format + detekt + test)
149+
5. **build-examples** - Builds example APKs (depends on format + detekt + test)
150+
6. **publish** - Publishes to Maven Central and creates GitHub Release (depends on all above)
170151

171152
**Publish Job Details**:
172153
- Validates tag format (must be `vMAJOR.MINOR.PATCH`)
@@ -310,6 +291,9 @@ Before pushing, developers can run the same checks locally:
310291
# Auto-fix formatting
311292
./gradlew spotlessApply
312293

294+
# Static analysis
295+
./gradlew detekt
296+
313297
# Run unit tests
314298
./gradlew :openmapview:test
315299

@@ -375,6 +359,7 @@ Artifacts are retained for 30 days.
375359

376360
**Common Failures**:
377361
- **Format check fails**: Run `./gradlew spotlessApply` locally and commit
362+
- **Detekt fails**: Run `./gradlew detekt` locally to see issues
378363
- **Test fails**: Run `./gradlew :openmapview:test` locally to debug
379364
- **Build fails**: Check for compilation errors in logs
380365
- **Publish fails**: Verify GitHub Secrets are configured correctly
@@ -390,34 +375,19 @@ Developer creates PR with code changes
390375
GitHub triggers ci.yml workflow
391376
|
392377
v
393-
format job: Check Spotless formatting (30 sec) - PASS
378+
format/copyright/detekt jobs run in parallel (30-60 sec each) - PASS
394379
|
395380
v
396-
copyright job: Check license headers (30 sec) - PASS
381+
test/coverage/docs jobs run (1-2 min each) - PASS
382+
|
383+
v
384+
build-library + build-examples run in parallel (2-3 min) - PASS
397385
|
398386
v
399-
+-------------+--------------+
400-
| |
401-
v v
402-
test job: Unit tests coverage job: Test coverage
403-
(1 min) - PASS (1 min) - PASS (>20%)
404-
| |
405-
+-------------+--------------+
406-
|
407-
+-------------+--------------+
408-
| |
409-
v v
410-
build-library: Build AAR build-examples: Build 3 APKs
411-
(2 min) - PASS (3 min) - PASS
412-
| |
413-
+-------------+--------------+
414-
|
415-
v
416387
All core checks pass (3-4 min)
417388
418389
Meanwhile (in parallel, PR only):
419-
instrumented-test: Phone + Automotive tests
420-
(10-15 min) - PASS
390+
instrumented-test: Phone + Automotive tests (10-15 min) - PASS
421391
|
422392
v
423393
All checks complete -> PR is ready to merge
@@ -432,21 +402,15 @@ Developer tags v0.2.0 and pushes
432402
GitHub triggers release.yml workflow
433403
|
434404
v
435-
format job: Check Spotless formatting - PASS
405+
format + detekt jobs run in parallel - PASS
436406
|
437407
v
438408
test job: Run unit tests - PASS
439409
|
440410
v
441-
+-------------+--------------+
442-
| |
443-
v v
444-
build-library: Build AAR build-examples: Build 3 APKs
445-
- PASS - PASS
446-
| |
447-
+-------------+--------------+
448-
|
449-
v
411+
build-library + build-examples run in parallel - PASS
412+
|
413+
v
450414
publish job:
451415
- Validate tag format - PASS
452416
- Sign artifacts with GPG - PASS

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ kotlinx-coroutines = "1.10.2"
3636
# Code Quality
3737
ktlint = "1.3.1"
3838
license-report = "3.0.1"
39+
detekt = "1.23.7"
3940

4041
[libraries]
4142
# AndroidX Core
@@ -80,6 +81,7 @@ spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
8081
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
8182
nmcp = { id = "com.gradleup.nmcp.aggregation", version.ref = "nmcp" }
8283
license-report = { id = "com.github.jk1.dependency-license-report", version.ref = "license-report" }
84+
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
8385

8486
[bundles]
8587
# Common dependencies for example apps

0 commit comments

Comments
 (0)