Skip to content

Commit

Permalink
add firebase distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Masdorp committed May 9, 2024
1 parent 659884e commit 641a0fd
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 49 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Build & distribute'

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v3

- name: "Setup Java"
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: "Validate gradle wrapper"
uses: gradle/wrapper-validation-action@v1

- name: "Use cached gradle wrapper"
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: "Build"
run: ./gradlew app:assQa

# We need to do this at some point:
# https://github.com/wzieba/Firebase-Distribution-Github-Action/wiki/FIREBASE_TOKEN-migration

- name: "Distribute"
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{ secrets.FIREBASE_APP_ID_ANDROID }}
token: ${{ secrets.FIREBASE_TOKEN_ANDROID }}
groups: testers
file: app/build/outputs/apk/qa/app-qa.apk
releaseNotesFile: app/release-notes.txt
65 changes: 57 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlinx-serialization'
id "com.starter.easylauncher" version "$easy_launcher_version"
id 'com.google.firebase.appdistribution'
}

repositories {
mavenCentral()
Expand All @@ -14,13 +18,44 @@ android {
minSdkVersion 26
//noinspection OldTargetApi
targetSdkVersion 34
versionCode 201
versionName "2.3.7"
versionCode project.getVersionCode()
versionName "2.3.7" + project.getVersionCode()
}

signingConfigs {
firebase {
storeFile file("firebase.jks")
storePassword 'password'
keyAlias 'alias'
keyPassword 'password'
}
}

buildTypes {
release {
debug {
applicationIdSuffix ".debug"
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
qa {
applicationIdSuffix = ".qa"
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

signingConfig signingConfigs.firebase
firebaseAppDistribution {
artifactType = "APK"
groups = "testers"
releaseNotesFile = "app/release-notes.txt"
}
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

Expand Down Expand Up @@ -51,9 +86,19 @@ android {
namespace 'com.nielsmasdorp.nederadio'
}

easylauncher {
buildTypes {
qa {
filters = redRibbonFilter()
}
}
}

dependencies {
implementation project(':domain')

implementation platform('com.google.firebase:firebase-bom:32.5.0')

// Google
implementation "com.google.android.material:material:$material_version"

Expand All @@ -76,7 +121,11 @@ dependencies {

// Koin
implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-androidx-compose:$koin_compose_version"
implementation "io.insert-koin:koin-androidx-compose:$koin_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"

// Ktor
implementation "io.ktor:ktor-client-android:$ktor_version"
Expand Down
29 changes: 29 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "576626084592",
"project_id": "nederadio-4611a",
"storage_bucket": "nederadio-4611a.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:576626084592:android:725f5fa27712251dc85035",
"android_client_info": {
"package_name": "com.nielsmasdorp.nederadio.qa"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCY8N_LYcO6fYd-993AXN5EQG4mkWC3RlU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
1 change: 1 addition & 0 deletions app/release-notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add firebase distribution
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package com.nielsmasdorp.nederadio.data.network
import android.util.Log
import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
import io.ktor.client.features.*
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.client.features.logging.LogLevel
import io.ktor.client.features.logging.Logger
import io.ktor.client.features.logging.Logging
import io.ktor.client.features.observer.ResponseObserver
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.client.plugins.DefaultRequest
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.plugins.logging.DEFAULT
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.observer.ResponseObserver
import io.ktor.client.request.header
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.URLProtocol
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json

private const val TIME_OUT = 60_000
Expand All @@ -28,8 +32,8 @@ val ktorHttpClient = HttpClient(Android) {
}
}

install(JsonFeature) {
serializer = KotlinxSerializer(
install(ContentNegotiation) {
json(
Json {
prettyPrint = true
isLenient = true
Expand All @@ -44,11 +48,7 @@ val ktorHttpClient = HttpClient(Android) {
}

install(Logging) {
logger = object : Logger {
override fun log(message: String) {
Log.v("Logger Ktor =>", message)
}
}
logger = Logger.DEFAULT
level = LogLevel.ALL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.nielsmasdorp.nederadio.data.network

import com.nielsmasdorp.nederadio.data.network.reponse.StreamResponse
import io.ktor.client.*
import io.ktor.client.call.body
import io.ktor.client.request.*

/**
* @author Niels Masdorp (NielsMasdorp)
*/
class StreamApi(private val client: HttpClient) {

suspend fun getStreams(): List<StreamResponse> = client.get("/data.json")
suspend fun getStreams(): List<StreamResponse> = client.get("/data.json").body()
}
20 changes: 5 additions & 15 deletions app/src/main/java/com/nielsmasdorp/nederadio/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.nielsmasdorp.nederadio.util
import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import androidx.annotation.OptIn
import androidx.core.net.toUri
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
Expand All @@ -19,7 +20,9 @@ import com.nielsmasdorp.nederadio.R
import com.nielsmasdorp.nederadio.domain.stream.Failure
import com.nielsmasdorp.nederadio.domain.stream.PlayerControls
import com.nielsmasdorp.nederadio.domain.stream.Stream
import io.ktor.client.features.*
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.plugins.RedirectResponseException
import io.ktor.client.plugins.ServerResponseException

/**
* @author Niels Masdorp
Expand Down Expand Up @@ -99,18 +102,5 @@ fun CastContext.castingSubtitle(context: Context): String {
}
}

@OptIn(UnstableApi::class)
fun PlayerControls<*>.view(): PlayerControlView = getView() as PlayerControlView

/**
* Move an item that matches a given predicate to the front of the list
* If no element is found, the list remains untouched
*/
fun <T> MutableList<T>.moveToFront(predicate: (T) -> Boolean): MutableList<T> {
return this.apply {
val item = find(predicate)
item?.let {
remove(it)
add(0, it)
}
}
}
38 changes: 29 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {

//google
ext.material_version = '1.11.0'
ext.material_version = '1.12.0'
ext.app_distribution_plugin_version = '4.0.0'

//kotlin
ext.kotlin_version = '1.9.10'
ext.kotlinx_coroutines_android_version = '1.6.4'
ext.kotlinx_coroutines_android_version = '1.8.0'
ext.kotlinx_coroutines_core_version = '1.6.4'
ext.kotlinx_serialization_version = '1.3.2'
ext.kotlinx_guava_version = '1.6.4'

//androidx
ext.androidx_media3_version = '1.2.1'
ext.androidx_media3_version = '1.3.1'
ext.androidx_compose_version = '1.5.4'
ext.androidx_compose_material3_version = '1.1.2'
ext.androidx_compose_material3_version = '1.2.1'

//koin
ext.koin_version = '3.4.2'
ext.koin_compose_version = '3.4.2'
ext.koin_version = '3.5.3'

//ktor
ext.ktor_version = '1.6.8'
ext.ktor_version = '2.3.9'

//accompanist
ext.accompanist_version = '0.32.0'

//misc
ext.landscapist_glide_version = '2.2.2'
ext.lottie_version = '6.1.0'
ext.lottie_version = '6.4.0'
ext.vico_version = '1.6.5'
ext.easy_launcher_version = '6.2.0'

//test
ext.junit_version = "4.13.2"
Expand All @@ -52,9 +53,10 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.1'
classpath 'com.android.tools.build:gradle:8.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.google.firebase:firebase-appdistribution-gradle:$app_distribution_plugin_version"
}
}

Expand All @@ -70,6 +72,24 @@ detekt {
buildUponDefaultConfig = true
}

ext.getVersionCode = { ->
try {
def runNumber = System.getenv('GITHUB_RUN_NUMBER')
if (runNumber) {
return Integer.parseInt(runNumber)
}
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--first-parent', '--count', 'origin/main'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
}
catch (ignored) {
return 1
}
}

/**
* @return List of source directories from all subprojects.
*/
Expand Down

0 comments on commit 641a0fd

Please sign in to comment.