Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup detekt #17

Closed
wants to merge 28 commits into from
Closed
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
51 changes: 3 additions & 48 deletions .github/workflows/android.yml → .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
name: Android CI
name: Merge

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: set up JDK 17
Expand All @@ -35,50 +31,9 @@ jobs:
name: app
path: app/build/outputs/apk/

test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4.1.0
- name: Set up JDK 17
uses: actions/setup-java@v3.13.0
with:
distribution: 'adopt'
java-version: '17'

- name: Grant execute permissions for gradlew
run: chmod +x ./gradlew

- name: Run Tests with Gradle
run: ./gradlew test

lint:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4.1.0
- name: Set up JDK 17
uses: actions/setup-java@v3.13.0
with:
distribution: 'temurin'
java-version: '17'
cache: gradle

- name: Grant execute permissions for gradlew
run: chmod +x ./gradlew
- name: Run Lint with Gradle
run: ./gradlew lint
- name: Upload lint results
uses: actions/upload-artifact@v2
with:
name: lint-results
path: '**/build/reports/lint-results-*.html'

dokka:
runs-on: ubuntu-latest
needs: [ build, test ]
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4.1.0
Expand All @@ -99,4 +54,4 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: build/dokka/htmlMultiModule
folder: build/dokka/htmlMultiModule
58 changes: 58 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Pull Request

on:
pull_request:
branches: [ "main" ]

concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
detekt:
name: Detekt review
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
ref: ${{ github.head_ref }}

- name: detekt-pr-check
uses: alaegin/Detekt-Action@v1.23.6
with:
reviewdog_reporter: github-pr-check
github_token: ${{ secrets.github_token }}
detekt_config: internal/detekt-config.yml
- name: detekt-evaluate
run: |
if grep -qE "(Analysis failed|conclusion=failure)" <(echo "$GITHUB_JOB_LOG"); then
echo "Detekt analysis failed" >&2
exit 1
fi

check:
name: Build and test
needs: [detekt]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4.1.0

- name: Set up JDK 17
uses: actions/setup-java@v3.13.0
with:
distribution: 'temurin'
java-version: '17'
cache: gradle

- name: Change permissions
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Test with Gradle
run: ./gradlew test
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ dependencies {
implementation(libs.hilt.navigation.compose)

implementation(project(":core:bluetooth"))
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/kotlin/edu/stanford/spezi/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
SpeziTheme {
BluetoothScreen()
BluetoothScreen()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class MainApplication : Application() {

SpeziLogger.setLoggingEnabled(enabled = BuildConfig.DEBUG)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ class BluetoothViewModel @Inject internal constructor(
object EnableBluetooth : Event
data class RequestPermissions(val permissions: List<String>) : Event
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class BluetoothUiStateMapper @Inject constructor() {
}

private fun format(value: Number?): String = String.format(Locale.US, "%.2f", value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ data class DeviceUiModel(
val address: String,
val measurementsCount: Int,
val summary: String,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private fun AdditionalInfo(uiState: BluetoothUiState) {
Text(text = text)
}


@Composable
fun DeviceComposable(device: DeviceUiModel) {
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
Expand Down Expand Up @@ -102,4 +101,4 @@ private fun BluetoothEvents(events: Flow<BluetoothViewModel.Event>) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ class BluetoothViewModelTest {
uiStateMapper = uiStateMapper
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ class BluetoothUiStateMapperTest {
const val WEIGHT = 4.56
const val ADDRESS = "some device address"
}
}
}
2 changes: 1 addition & 1 deletion build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ gradlePlugin {
conventionPlugin(id = "hilt", className = "HiltConventionPlugin")
conventionPlugin(id = "library", className = "SpeziLibraryConventionPlugin")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ internal fun DependencyHandler.debugImplementation(dependency: Any) {

internal fun DependencyHandler.androidTestImplementation(dependency: Any) {
add("androidTestImplementation", dependency)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ internal fun Project.commonExtensions(configBlock: CommonExtension<*,*,*,*,*,*>.
isLibrary() -> extension<LibraryExtension>(configBlock)
else -> error("commonExtensions was called before setting the module type plugin")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ enum class PluginId(val id: String) {
HILT(id = "com.google.dagger.hilt.android"),
KSP(id = "com.google.devtools.ksp"),
COMPOSE_COMPILER("org.jetbrains.kotlin.plugin.compose")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class HiltConventionPlugin : Plugin<Project> {
enableAggregatingTask = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ abstract class SpeziAbstractConfigPlugin(private val modulePlugin: PluginId) : P
testImplementation(project(":core:testing"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package edu.stanford.spezi.build.logic.convention.plugins

import edu.stanford.spezi.build.logic.convention.model.PluginId

class SpeziApplicationConventionPlugin : SpeziAbstractConfigPlugin(modulePlugin = PluginId.ANDROID_APPLICATION)
class SpeziApplicationConventionPlugin : SpeziAbstractConfigPlugin(modulePlugin = PluginId.ANDROID_APPLICATION)
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class SpeziBaseConfigConventionPlugin : Plugin<Project> {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class SpeziComposeConventionPlugin : Plugin<Project> {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package edu.stanford.spezi.build.logic.convention.plugins

import edu.stanford.spezi.build.logic.convention.model.PluginId

class SpeziLibraryConventionPlugin : SpeziAbstractConfigPlugin(modulePlugin = PluginId.ANDROID_LIBRARY)
class SpeziLibraryConventionPlugin : SpeziAbstractConfigPlugin(modulePlugin = PluginId.ANDROID_LIBRARY)
2 changes: 1 addition & 1 deletion build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencyResolutionManagement {
}

rootProject.name = "build-logic"
include(":convention")
include(":convention")
46 changes: 38 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.dokka.gradle.DokkaTaskPartial

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.hilt.android) version libs.versions.hiltVersion apply false
alias(libs.plugins.google.devtools.ksp) version libs.versions.kspVersion apply false
alias(libs.plugins.compose.compiler) version libs.versions.kotlin apply false
alias(libs.plugins.detekt) version libs.versions.detekt
alias(libs.plugins.dokka) version libs.versions.dokka
alias(libs.plugins.google.devtools.ksp) version libs.versions.kspVersion apply false
alias(libs.plugins.hilt.android) version libs.versions.hiltVersion apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
}

subprojects {
apply(plugin = "org.jetbrains.dokka")
setupDokka()
setupDetekt()
}

tasks.dokkaHtmlMultiModule {
moduleName.set("Spezi Documentation")
}

fun Project.setupDokka() {
apply(plugin = rootProject.libs.plugins.dokka.get().pluginId)

if (this != rootProject) {
rootProject.tasks.named("dokkaHtmlMultiModule") {
Expand All @@ -26,7 +36,7 @@ subprojects {
skipDeprecated.set(true)
skipEmptyPackages.set(true)
includeNonPublic.set(false)
jdkVersion.set(17)
jdkVersion.set(JavaVersion.VERSION_17.majorVersion.toInt())
if (file("README.md").exists()) {
includes.from("README.md")
}
Expand All @@ -42,6 +52,26 @@ subprojects {
}
}

tasks.dokkaHtmlMultiModule {
moduleName.set("Spezi Documentation")
}
fun Project.setupDetekt() {
val libs = rootProject.libs
apply(plugin = libs.plugins.detekt.get().pluginId)
detekt {
toolVersion = libs.versions.detekt.get()
config.setFrom("$rootDir/internal/detekt-config.yml")
autoCorrect = true
ignoreFailures = false
}

dependencies {
detektPlugins(libs.detekt.formatting)
}

tasks.withType<Detekt> {
reports {
xml.required.set(true)
html.required.set(true)
txt.required.set(true)
sarif.required.set(true)
}
}
}
2 changes: 1 addition & 1 deletion core/bluetooth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ android {
dependencies {
implementation(project(":core:utils"))
implementation(project(":core:coroutines"))
}
}
Loading
Loading