Skip to content

Commit

Permalink
Merge pull request #73 from futuredapp/feature/product-flavors
Browse files Browse the repository at this point in the history
Extract ProductFlavor configuration
  • Loading branch information
matejsemancik authored Jun 10, 2024
2 parents e2daedd + 1a0dd31 commit ec9f00a
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 55 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/android_enterprise_release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Android Enterprise Release

on:
push:
branches:
- develop
# TODO uncomment trigger on client project

#on:
# push:
# branches:
# - develop

concurrency:
group: ${{ github.workflow }}-${{ github.repository }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/android_google_play_release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Android Google Play Release

on:
release:
types: [ published ]
# TODO uncomment trigger on client project

#on:
# release:
# types: [ published ]

jobs:
release:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ios_build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: iOS Build

on:
push:
branches:
- develop
# TODO uncomment trigger on client project

#on:
# push:
# branches:
# - develop

jobs:
build:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/ios_release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: iOS Release

on:
release:
types: [published]
# TODO uncomment trigger on client project

#on:
# release:
# types: [published]

jobs:
release:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.futured.kmptemplate.gradle.configuration

/**
* Defines all flavor-specific values provided to KMP during compilation.
*/
interface ProductFlavor {
val name: String
val apolloApiUrl: String
val restApiUrl: String
}

object ProductFlavors {

val DEFAULT = Dev

object Dev : ProductFlavor {
override val name: String = "dev"
override val apolloApiUrl: String = "https://rickandmortyapi.com/graphql"
override val restApiUrl: String = "https://swapi.dev/api/"
}

object Prod : ProductFlavor {
override val name: String = "prod"
override val apolloApiUrl: String = "https://rickandmortyapi.com/graphql"
override val restApiUrl: String = "https://swapi.dev/api/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@ object ProjectSettings {
}

object Kotlin {

const val JvmToolchainVersion = 17

object ProductFlavors {
object Dev {
const val NAME = "dev"
const val ApolloApiUrl = "https://rickandmortyapi.com/graphql"
const val RestApiUrl = "https://swapi.dev/api/"
}

object Prod {
const val NAME = "prod"
const val ApolloApiUrl = "https://rickandmortyapi.com/graphql"
const val RestApiUrl = "https://swapi.dev/api/"
}
}
}

object Android {
Expand Down
21 changes: 10 additions & 11 deletions shared/network/graphql/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import app.futured.kmptemplate.gradle.configuration.ProductFlavors
import app.futured.kmptemplate.gradle.configuration.ProjectSettings
import app.futured.kmptemplate.gradle.ext.iosTargets
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
Expand Down Expand Up @@ -74,20 +75,18 @@ apollo {

buildkonfig {
packageName = libs.versions.project.shared.network.graphql.packageName.get()
objectName = "FlavorConstants"

with(ProjectSettings.Kotlin.ProductFlavors.Dev) {
defaultConfigs {
buildConfigField(STRING, "apiUrl", ApolloApiUrl)
}

defaultConfigs(flavor = NAME) {
buildConfigField(STRING, "apiUrl", ApolloApiUrl)
}
defaultConfigs {
buildConfigField(STRING, "apiUrl", ProductFlavors.DEFAULT.apolloApiUrl)
}

with(ProjectSettings.Kotlin.ProductFlavors.Prod) {
defaultConfigs(flavor = NAME) {
buildConfigField(STRING, "apiUrl", ApolloApiUrl)
listOf(
ProductFlavors.Dev,
ProductFlavors.Prod,
).forEach {
defaultConfigs(flavor = it.name) {
buildConfigField(STRING, "apiUrl", it.apolloApiUrl)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app.futured.kmptemplate.network.graphql.tools

import app.futured.kmptemplate.network.graphql.BuildKonfig
import app.futured.kmptemplate.network.graphql.FlavorConstants
import kotlin.time.Duration.Companion.seconds

internal object Constants {

object Configuration {
val API_URL = BuildKonfig.apiUrl
val API_URL = FlavorConstants.apiUrl
val REQUEST_TIMEOUT = 20.seconds
}
}
21 changes: 10 additions & 11 deletions shared/network/rest/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import app.futured.kmptemplate.gradle.configuration.ProductFlavors
import app.futured.kmptemplate.gradle.configuration.ProjectSettings
import app.futured.kmptemplate.gradle.ext.iosTargets
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
Expand Down Expand Up @@ -71,20 +72,18 @@ android {

buildkonfig {
packageName = libs.versions.project.shared.network.rest.packageName.get()
objectName = "FlavorConstants"

with(ProjectSettings.Kotlin.ProductFlavors.Dev) {
defaultConfigs {
buildConfigField(STRING, "apiUrl", RestApiUrl)
}

defaultConfigs(flavor = NAME) {
buildConfigField(STRING, "apiUrl", RestApiUrl)
}
defaultConfigs {
buildConfigField(STRING, "apiUrl", ProductFlavors.DEFAULT.restApiUrl)
}

with(ProjectSettings.Kotlin.ProductFlavors.Prod) {
defaultConfigs(flavor = NAME) {
buildConfigField(STRING, "apiUrl", RestApiUrl)
listOf(
ProductFlavors.Dev,
ProductFlavors.Prod,
).forEach {
defaultConfigs(flavor = it.name) {
buildConfigField(STRING, "apiUrl", it.restApiUrl)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.futured.kmptemplate.network.rest.injection

import app.futured.kmptemplate.network.rest.BuildKonfig
import app.futured.kmptemplate.network.rest.FlavorConstants
import app.futured.kmptemplate.network.rest.api.StarWarsApi
import app.futured.kmptemplate.network.rest.logging.KtorKermitLogger
import app.futured.kmptemplate.network.rest.result.NetworkResultConverterFactory
Expand All @@ -23,7 +23,7 @@ class NetworkRestModule {

@Single
@Named("apiUrl")
fun apiUrl(): String = BuildKonfig.apiUrl
fun apiUrl(): String = FlavorConstants.apiUrl

@Single
@Named("restApiJson")
Expand Down

0 comments on commit ec9f00a

Please sign in to comment.