Skip to content

Commit

Permalink
Merge pull request #2021 from PaulWoitaschek/review_remote_config
Browse files Browse the repository at this point in the history
Use remote config for the review feature
  • Loading branch information
PaulWoitaschek authored Jul 1, 2023
2 parents cd94ad1 + a870a8f commit 2485c32
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 108 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/release.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/test.yml

This file was deleted.

90 changes: 90 additions & 0 deletions .github/workflows/voice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI/CD

on:
push:
branches:
- main
tags:
- '*'
pull_request:
branches:
- main

env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -XX:MaxMetaspaceSize=1g -Xms512m -XX:+HeapDumpOnOutOfMemoryError"
ANDROID_PUBLISHER_CREDENTIALS: ${{ secrets.ANDROID_PUBLISHER_CREDENTIALS }}
SIGNING_KEYSTORE_PLAY: ${{ secrets.SIGNING_KEYSTORE }}
SIGNING_PROPERTIES_PLAY: ${{ secrets.SIGNING_PROPERTIES }}
SIGNING_KEYSTORE_GITHUB: ${{ secrets.SIGNING_KEYSTORE_GITHUB }}
SIGNING_PROPERTIES_GITHUB: ${{ secrets.SIGNING_PROPERTIES_GITHUB }}
GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
VOICE_USE_PROPRIETARY_LIBRARIES: "true"

jobs:
test:
if: github.event_name == 'push' || github.event_name == 'pull_request'
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: 17

- name: Setup Signing
run: ./ci_signing_setup.sh

- name: Test
run: ./gradlew testDebugUnitTest lintKotlin app:lintDebug app:assembleDebug

- uses: actions/upload-artifact@v3
if: always()
with:
name: "Artifacts"
path: |
artifacts/
app/build/reports/*.html
app/build/outputs/apk/debug/app-debug.apk
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/test-results/**/TEST-*.xml'

release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Setup Signing
run: ./ci_signing_setup.sh

- name: Publish to Google Play
run: ./gradlew app:publishReleaseBundle -Pvoice.signing.play=true

- name: Build Github APK
run: ./gradlew app:assembleRelease -Pvoice.signing.play=false

- name: Github Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: app/build/outputs/apk/release/app-release.apk
17 changes: 7 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ plugins {
alias(libs.plugins.playPublish)
}

val enableCrashlytics = project.hasProperty("enableCrashlytics")
if (enableCrashlytics) {
val useProprietaryLibraries = providers.environmentVariable("VOICE_USE_PROPRIETARY_LIBRARIES").orNull == "true"
if (useProprietaryLibraries) {
pluginManager.apply(libs.plugins.crashlytics.get().pluginId)
pluginManager.apply(libs.plugins.googleServices.get().pluginId)
}
Expand Down Expand Up @@ -80,7 +80,6 @@ android {
getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
applicationIdSuffix = ".debug"
}
all {
signingConfig = signingConfigs.getByName("release")
Expand Down Expand Up @@ -158,12 +157,6 @@ dependencies {
implementation(projects.documentfile)
implementation(projects.onboarding)

if (hasProperty("foss")) {
implementation(projects.review.noop)
} else {
implementation(project(":review:play"))
}

implementation(libs.appCompat)
implementation(libs.recyclerView)
implementation(libs.material)
Expand All @@ -177,10 +170,14 @@ dependencies {
implementation(libs.materialDialog.input)
implementation(libs.coil)

if (enableCrashlytics) {
if (useProprietaryLibraries) {
implementation(libs.firebase.crashlytics)
implementation(libs.firebase.analytics)
implementation(libs.firebase.remoteconfig)
implementation(projects.logging.crashlytics)
implementation(project(":review:play"))
} else {
implementation(projects.review.noop)
}

debugImplementation(projects.logging.debug)
Expand Down
17 changes: 17 additions & 0 deletions ci_signing_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [ ! -d "signing/play" ]; then
mkdir -p signing/play
echo "$SIGNING_KEYSTORE_PLAY" | base64 --decode >signing/play/signing.keystore
echo "$SIGNING_PROPERTIES_PLAY" | base64 --decode >signing/play/signing.properties
fi

if [ ! -d "signing/github" ]; then
mkdir -p signing/github
echo "$SIGNING_KEYSTORE_GITHUB" | base64 --decode >signing/github/signing.keystore
echo "$SIGNING_PROPERTIES_GITHUB" | base64 --decode >signing/github/signing.properties
fi

if [ ! -f "app/google-services.json" ]; then
echo "$GOOGLE_SERVICES" | base64 --decode >app/google-services.json
fi
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava",
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }

firebase-crashlytics = "com.google.firebase:firebase-crashlytics-ktx:18.3.7"
firebase-analytics = "com.google.firebase:firebase-analytics-ktx:21.3.0"
firebase-bom = "com.google.firebase:firebase-bom:32.1.1"
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" }
firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
firebase-remoteconfig = { module = "com.google.firebase:firebase-config-ktx" }

serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"

Expand Down
3 changes: 3 additions & 0 deletions plugins/src/main/kotlin/baseSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ fun Project.baseSetup() {
add("implementation", project(":logging:core"))
}
add("implementation", platform(libs.findLibrary("compose-bom").get()))
if (providers.environmentVariable("VOICE_USE_PROPRIETARY_LIBRARIES").orNull == "true") {
add("implementation", platform(libs.findLibrary("firebase-bom").get()))
}
add("androidTestImplementation", platform(libs.findLibrary("compose-bom").get()))

listOf(
Expand Down
1 change: 1 addition & 0 deletions review/play/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dependencies {
api(libs.review)
implementation(libs.lottie)
implementation(libs.dagger.core)
implementation(libs.firebase.remoteconfig)
}
6 changes: 6 additions & 0 deletions review/play/src/main/kotlin/voice/review/ReviewModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.datastore.core.DataStore
import com.google.android.play.core.review.ReviewManager
import com.google.android.play.core.review.ReviewManagerFactory
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
Expand All @@ -28,6 +29,11 @@ object ReviewModule {
fun reviewManager(context: Context): ReviewManager {
return ReviewManagerFactory.create(context)
}

@Provides
fun remoteConfig(): FirebaseRemoteConfig {
return FirebaseRemoteConfig.getInstance()
}
}

@Qualifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package voice.review

import androidx.datastore.core.DataStore
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.flow.first
import voice.data.repo.BookRepository
import voice.playback.playstate.PlayStateManager
Expand All @@ -21,10 +22,12 @@ class ShouldShowReviewDialog
private val bookRepository: BookRepository,
private val playStateManager: PlayStateManager,
private val reviewTranslated: ReviewTranslated,
private val remoteConfig: FirebaseRemoteConfig,
) {

internal suspend fun shouldShow(): Boolean {
return reviewTranslated.translated() &&
return enabledInRemoteConfig() &&
reviewTranslated.translated() &&
isNotPlaying() &&
enoughTimeElapsedSinceInstallation() &&
reviewDialogNotShown() &&
Expand All @@ -35,6 +38,10 @@ class ShouldShowReviewDialog
reviewDialogShown.updateData { true }
}

private fun enabledInRemoteConfig(): Boolean {
return remoteConfig.getBoolean("review_enabled")
}

private fun enoughTimeElapsedSinceInstallation(): Boolean {
val timeSinceInstallation = ChronoUnit.MINUTES.between(
installationTimeProvider.installationTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ShouldShowReviewDialogTest {
reviewTranslated = mockk {
every { translated() } returns true
},
remoteConfig = mockk {
every { getBoolean("review_enabled") } returns true
},
)
val showsReviewDialog = runBlocking {
shouldShowReviewDialog.shouldShow()
Expand Down

0 comments on commit 2485c32

Please sign in to comment.