diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b770f52..da02891 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: androidTest +name: tests on: pull_request: @@ -9,6 +9,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + OPEN_API_KEY: ${{ secrets.OPEN_API_KEY }} steps: - name: Checkout diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 14b99d2..ecf2e0d 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,9 +1,11 @@ +import com.android.build.api.dsl.ApplicationDefaultConfig import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig import org.jlleitschuh.gradle.ktlint.reporter.ReporterType +import java.util.Properties plugins { alias(libs.plugins.kotlinMultiplatform) @@ -118,6 +120,9 @@ android { targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 versionName = "1.0" + + val properties = getLocalProperties() + setupBuildConfigFields(properties = properties) } packaging { resources { @@ -133,6 +138,9 @@ android { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } + buildFeatures { + buildConfig = true + } } dependencies { @@ -149,4 +157,25 @@ compose.desktop { packageVersion = "1.0.0" } } +} + +fun ApplicationDefaultConfig.setupBuildConfigFields( + properties: Properties, +) { + fun secret(key: String): String = System.getenv(key) ?: properties.getProperty(key, "") + + if (secret("OPEN_API_KEY").isEmpty()) { + error("OPEN_API_KEY not set in local.properties") + } + + buildConfigField(type = "String", name = "OPEN_API_KEY", value = "\"${secret("OPEN_API_KEY")}\"") +} + +fun getLocalProperties(): Properties { + return Properties().apply { + val file = rootProject.file("local.properties") + if (file.exists()) { + file.inputStream().use { load(it) } + } + } } \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.android.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.android.kt index 7565f0e..23a9971 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.android.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.android.kt @@ -6,4 +6,6 @@ class AndroidPlatform : Platform { override val name: String = "Android ${Build.VERSION.SDK_INT}" } -actual fun getPlatform(): Platform = AndroidPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = AndroidPlatform() + +actual fun getOpenApiKey() = BuildConfig.OPEN_API_KEY \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.kt index 6729819..d745d07 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.kt @@ -4,4 +4,6 @@ interface Platform { val name: String } -expect fun getPlatform(): Platform \ No newline at end of file +expect fun getPlatform(): Platform + +expect fun getOpenApiKey(): String \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/network/ApiKey.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/network/ApiKey.kt deleted file mode 100644 index ffac234..0000000 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/network/ApiKey.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.developersbreach.kotlindictionarymultiplatform.core.network - -const val API_KEY = "" \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/repository/DetailRepository.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/repository/DetailRepository.kt index d95ce29..f618f10 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/repository/DetailRepository.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/repository/DetailRepository.kt @@ -1,14 +1,14 @@ package com.developersbreach.kotlindictionarymultiplatform.data.detail.repository import arrow.core.Either -import com.developersbreach.kotlindictionarymultiplatform.core.network.API_KEY import com.developersbreach.kotlindictionarymultiplatform.core.network.KtorHttpClient import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.KotlinTopicDetails +import com.developersbreach.kotlindictionarymultiplatform.getOpenApiKey class DetailRepository { suspend fun fetchTopic(topicId: String): Either = Either.catch { - KtorHttpClient.generateTopicDetails(topicId, API_KEY) + KtorHttpClient.generateTopicDetails(topicId, getOpenApiKey()) } } \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.desktop.kt b/composeApp/src/desktopMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.desktop.kt new file mode 100644 index 0000000..99f944f --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.desktop.kt @@ -0,0 +1,3 @@ +package com.developersbreach.kotlindictionarymultiplatform + +actual fun getOpenApiKey(): String = "" \ No newline at end of file diff --git a/composeApp/src/nativeMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.native.kt b/composeApp/src/nativeMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.native.kt new file mode 100644 index 0000000..99f944f --- /dev/null +++ b/composeApp/src/nativeMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.native.kt @@ -0,0 +1,3 @@ +package com.developersbreach.kotlindictionarymultiplatform + +actual fun getOpenApiKey(): String = "" \ No newline at end of file diff --git a/composeApp/src/wasmJsMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.wasmJs.kt b/composeApp/src/wasmJsMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.wasmJs.kt index a14e747..290ebf6 100644 --- a/composeApp/src/wasmJsMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.wasmJs.kt +++ b/composeApp/src/wasmJsMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.wasmJs.kt @@ -4,4 +4,6 @@ class WasmPlatform : Platform { override val name: String = "Web with Kotlin/Wasm" } -actual fun getPlatform(): Platform = WasmPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = WasmPlatform() + +actual fun getOpenApiKey(): String = "" \ No newline at end of file