Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions .github/workflows/_detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Detekt Static Analysis

on:
workflow_call:

permissions:
contents: read

jobs:
detekt:
name: Run Detekt Analysis
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Grant execute permission for Gradle wrapper
run: chmod +x gradlew

- name: Run Detekt
run: ./gradlew detekt
8 changes: 8 additions & 0 deletions .github/workflows/_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ jobs:
mkdir -p openmapview/build/dokka/html/licenses
cp openmapview/build/reports/licenses/licenses.html openmapview/build/dokka/html/licenses/index.html

- name: Run Detekt Analysis
run: ./gradlew detekt --no-daemon

- name: Copy Detekt Report to Docs
run: |
mkdir -p openmapview/build/dokka/html/detekt
cp openmapview/build/reports/detekt/detekt.html openmapview/build/dokka/html/detekt/index.html

- name: Upload documentation artifact
uses: actions/upload-artifact@v4
with:
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@ jobs:
name: Check Copyright Headers
uses: ./.github/workflows/_copyright.yml

detekt:
name: Static Analysis
uses: ./.github/workflows/_detekt.yml

test:
name: Unit Tests
needs: [format, copyright]
needs: [format, copyright, detekt]
uses: ./.github/workflows/_test.yml

coverage:
name: Test Coverage
needs: [format, copyright]
needs: [format, copyright, detekt]
uses: ./.github/workflows/_coverage.yml

docs:
name: Documentation
needs: [format, copyright]
needs: [format, copyright, detekt]
uses: ./.github/workflows/_docs.yml

build-library:
name: Build Library
needs: [format, copyright, test, coverage, docs]
needs: [format, copyright, detekt, test, coverage, docs]
uses: ./.github/workflows/_build-library.yml

build-examples:
name: Build Examples
needs: [format, copyright, test, coverage, docs]
needs: [format, copyright, detekt, test, coverage, docs]
uses: ./.github/workflows/_build-examples.yml

instrumented-test:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- 'openmapview/src/**/*.kt'
- 'README.md'
- 'config/detekt/detekt.yml'
- '.github/workflows/_docs.yml'
- '.github/workflows/docs-deploy.yml'

Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ jobs:
name: Check Formatting
uses: ./.github/workflows/_format.yml

detekt:
name: Static Analysis
uses: ./.github/workflows/_detekt.yml

test:
name: Unit Tests
needs: format
needs: [format, detekt]
uses: ./.github/workflows/_test.yml

build-library:
name: Build Library
needs: [format, test]
needs: [format, detekt, test]
uses: ./.github/workflows/_build-library.yml

build-examples:
name: Build Examples
needs: [format, test]
needs: [format, detekt, test]
uses: ./.github/workflows/_build-examples.yml

publish:
name: Publish to Maven Central
runs-on: ubuntu-latest
needs: [format, test, build-library, build-examples]
needs: [format, detekt, test, build-library, build-examples]

steps:
- name: Checkout repository
Expand Down
22 changes: 22 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.nmcp)
}

Expand All @@ -37,3 +38,24 @@ nmcpAggregation {
publishAllProjectsProbablyBreakingProjectIsolation()
}

subprojects {
afterEvaluate {
if (plugins.hasPlugin("org.jetbrains.kotlin.android")) {
apply(plugin = "io.gitlab.arturbosch.detekt")

extensions.configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {
buildUponDefaultConfig = true
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
}

tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
reports {
html.required.set(true)
xml.required.set(true)
sarif.required.set(true)
}
}
}
}
}

63 changes: 63 additions & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
build:
maxIssues: 0

complexity:
active: true
LongMethod:
threshold: 200
LongParameterList:
functionThreshold: 10
constructorThreshold: 12
CyclomaticComplexMethod:
threshold: 50
TooManyFunctions:
thresholdInClasses: 100
thresholdInObjects: 20
LargeClass:
threshold: 3000
ComplexCondition:
threshold: 5
NestedBlockDepth:
threshold: 8

style:
active: true
MagicNumber:
active: false
MaxLineLength:
maxLineLength: 140
ReturnCount:
max: 15
FunctionOnlyReturningConstant:
active: false
LoopWithTooManyJumpStatements:
active: false
UseRequire:
active: true
UnusedPrivateMember:
active: false

naming:
active: true
FunctionNaming:
ignoreAnnotated:
- Composable

empty-blocks:
active: true

comments:
active: false

performance:
active: true

coroutines:
active: true

exceptions:
active: true
SwallowedException:
active: false
TooGenericExceptionCaught:
active: false
41 changes: 34 additions & 7 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,28 @@ Running `./gradlew spotlessApply` automatically adds this header to any files mi

The CI pipeline includes a copyright check that will fail if any `.kt` files are missing the required header.

### 3. Dependency Management
### 3. Static Code Analysis

All code must pass Detekt static analysis checks. Detekt analyzes code for:
- Code complexity and potential bugs
- Naming conventions
- Performance issues
- Code smells

**Run static analysis:**

```bash
./gradlew detekt
```

The CI pipeline will fail if Detekt finds any issues. View the HTML report at:
```
openmapview/build/reports/detekt/detekt.html
```

The Detekt report is also published at https://afarber.github.io/OpenMapView/detekt/

### 4. Dependency Management

Before adding new dependencies to OpenMapView, verify the following:

Expand Down Expand Up @@ -98,8 +119,8 @@ From the repository root, run:
This installs a pre-commit hook that automatically:
1. Checks code formatting with `./scripts/check-format.sh`
2. Checks copyright headers with `./scripts/check-copyright.sh`
3. Blocks the commit if any issues are found
4. Provides instructions to run `./gradlew spotlessApply` to fix issues
3. Runs Detekt static analysis with `./scripts/check-detekt.sh`
4. Blocks the commit if any issues are found

### What Happens on Commit

Expand All @@ -112,6 +133,8 @@ Running pre-commit checks...
Code formatting: OK
2. Checking copyright headers...
Copyright headers: OK
3. Running Detekt static analysis...
Static analysis: OK

All pre-commit checks passed!
```
Expand Down Expand Up @@ -190,10 +213,11 @@ The CI pipeline runs automatically on all pull requests and includes:

1. **Format Check** - Verifies Spotless formatting
2. **Copyright Check** - Verifies MIT license headers
3. **Unit Tests** - Runs all JVM unit tests
4. **Test Coverage** - Ensures minimum 20% code coverage
5. **Build Library** - Builds the OpenMapView AAR
6. **Build Examples** - Builds all example applications
3. **Static Analysis** - Runs Detekt code analysis
4. **Unit Tests** - Runs all JVM unit tests
5. **Test Coverage** - Ensures minimum 20% code coverage
6. **Build Library** - Builds the OpenMapView AAR
7. **Build Examples** - Builds all example applications

All checks must pass before merging.

Expand All @@ -206,6 +230,9 @@ All checks must pass before merging.
# Check formatting
./gradlew spotlessCheck

# Run static analysis
./gradlew detekt

# Run unit tests
./gradlew :openmapview:test

Expand Down
Loading