Skip to content

Commit

Permalink
Merge pull request #75 from stslex/dev
Browse files Browse the repository at this point in the history
Refactor feature builder. Update ci - auto publish
  • Loading branch information
stslex authored Apr 23, 2024
2 parents f4b2f04 + f32c1be commit 21720be
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 73 deletions.
38 changes: 38 additions & 0 deletions .github/scripts/update_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Define the initial script directory
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_dir="$(dirname "$script_dir")"
project_dir="$(dirname "$project_dir")"
echo "Project script directory: $project_dir"

# Define the path to the target file
version_file="$project_dir/gradle/libs.versions.toml"

# Check if the target file exists
if [ -f "$version_file" ]; then
echo "Target file found: $version_file"
else
echo "Target file not found"
exit 1 # Exit the script if the target file is not found
fi

# Read versionName and versionCode from the file
version_name=$(awk -F '"' '/versionName = "/{print $2}' "$version_file")
version_code=$(awk -F '"' '/versionCode = "/{print $2}' "$version_file")

# Increment versionCode by 1
((version_code++))

# Increment versionName by 0.01
version_name=$(echo "$version_name + 0.01" | bc)

# Update the file with the new version information
sed "s/versionName = \".*\"/versionName = \"$version_name\"/" "$version_file" > "$version_file.tmp"
mv "$version_file.tmp" "$version_file"

sed "s/versionCode = \".*\"/versionCode = \"$version_code\"/" "$version_file" > "$version_file.tmp"
mv "$version_file.tmp" "$version_file"

echo "Updated versionName to $version_name and versionCode to $version_code in $version_file"

2 changes: 1 addition & 1 deletion .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:

- name: Checkout branch
uses: actions/checkout@v2
uses: actions/checkout@v4
- run: |
echo "${{ secrets.KEYSTORE }}" > keystore.jks.asc
gpg -d --passphrase "${{ secrets.KEYSTORE_PASSPHRASE }}" --batch keystore.jks.asc > keystore.jks
Expand Down
21 changes: 19 additions & 2 deletions .github/workflows/android_deploy_beta.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Android Deploy Beta

on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
Expand All @@ -10,12 +12,15 @@ jobs:
timeout-minutes: 60

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- run: |
echo "${{ secrets.KEYSTORE }}" > keystore.jks.asc
gpg -d --passphrase "${{ secrets.KEYSTORE_PASSPHRASE }}" --batch keystore.jks.asc > keystore.jks
- name: Update Version
run: bash ./.github/scripts/update_versions.sh

- uses: ruby/[email protected]
with:
ruby-version: '2.7.0'
Expand Down Expand Up @@ -79,4 +84,16 @@ jobs:
base64 -d -i play_config.json.b64 > play_config.json
- name: Distribute app to Beta track 🚀
run: bundle exec fastlane beta
run: bundle exec fastlane beta

- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "update version"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PUSH_TOKEN }}
branch: ${{ github.ref }}
19 changes: 17 additions & 2 deletions .github/workflows/android_deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ jobs:
timeout-minutes: 60

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- run: |
echo "${{ secrets.KEYSTORE }}" > keystore.jks.asc
gpg -d --passphrase "${{ secrets.KEYSTORE_PASSPHRASE }}" --batch keystore.jks.asc > keystore.jks
- name: Update Version
run: bash ./.github/scripts/update_versions.sh

- uses: ruby/[email protected]
with:
ruby-version: '2.7.0'
Expand Down Expand Up @@ -79,4 +82,16 @@ jobs:
base64 -d -i play_config.json.b64 > play_config.json
- name: Distribute app to Beta track 🚀
run: bundle exec fastlane deploy
run: bundle exec fastlane deploy

- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "update version"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PUSH_TOKEN }}
branch: ${{ github.ref }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import AppExt.currentLibs
import AppExt.findVersionInt
import AppExt.findVersionString
import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -12,6 +15,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
val libs = currentLibs
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
Expand All @@ -22,12 +26,11 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)

namespace = "st.slex.csplashscreen"

defaultConfig.apply {
applicationId = "st.slex.csplashscreen"
targetSdk = 34
versionName = AppVersions.VERSION_NAME
versionCode = AppVersions.VERSION_CODE
targetSdk = libs.findVersionInt("targetSdk")
versionName = libs.findVersionString("versionName")
versionCode = libs.findVersionInt("versionCode")

configureSigning(target)
}
Expand Down
24 changes: 24 additions & 0 deletions build-logic/dependencies/src/main/kotlin/AppVersions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

object AppVersions {
const val VERSION_NAME = "1.71"
const val VERSION_CODE = 17
}

object AppExt {

/**
* Get the version catalog for the project
* */
val Project.currentLibs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")

/**
* Find the version of the library
*/
fun VersionCatalog.findVersionInt(name: String) = findVersionString(name).toInt()

/**
* Find the version of the library
*/
fun VersionCatalog.findVersionString(name: String) = findVersion(name).get().toString()
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package st.slex.csplashscreen

import AppExt.currentLibs
import AppExt.findVersionString
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -14,15 +14,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
val libs = currentLibs

commonExtension.apply {

buildFeatures.compose = true
composeOptions.kotlinCompilerExtensionVersion = libs
.findVersion("composeCompiler")
.get()
.toString()
composeOptions.kotlinCompilerExtensionVersion = libs.findVersionString("composeCompiler")

dependencies {
val composeBom = libs.findLibrary("androidx-compose-bom").get()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package st.slex.csplashscreen

import AppExt.currentLibs
import AppExt.findVersionInt
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.DefaultConfig
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
Expand All @@ -21,12 +21,14 @@ import org.jetbrains.kotlin.konan.properties.Properties
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = currentLibs

commonExtension.apply {

compileSdk = 34
compileSdk = libs.findVersionInt("compileSdk")

defaultConfig {
minSdk = 28
minSdk = libs.findVersionInt("minSdk")
buildFeatures.buildConfig = true

gradleLocalProperties(
Expand All @@ -48,8 +50,6 @@ internal fun Project.configureKotlinAndroid(

configureKotlin()

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
add("coreLibraryDesugaring", libs.findLibrary("android-desugarJdkLibs").get())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import st.slex.csplashscreen.core.navigation.AppDestination
import st.slex.csplashscreen.core.ui.di.MainUiProvider
import st.slex.csplashscreen.core.ui.di.builder.Feature
import st.slex.csplashscreen.core.ui.di.builder.FeatureBuilder
import st.slex.csplashscreen.core.ui.di.mainUiApi

@Composable
inline fun <reified T : ViewModel> daggerViewModel(
Expand All @@ -24,27 +24,37 @@ inline fun <reified T : ViewModel> daggerViewModel(
)

@Composable
inline fun <reified VM : ViewModel, F : Feature> setupComponent(
inline fun <reified VM : ViewModel, reified F : Feature> setupComponent(
builder: FeatureBuilder<F>,
key: String? = null,
featureKey: Any? = null
): VM {
val context = LocalContext.current
val mainUiApi = checkNotNull(context as? MainUiProvider) {
"MainUiProvider is not implemented in $context"
}.api

DisposableEffect(Unit) {
builder.create(context.mainUiApi)
builder.setup(
mainUiApi = mainUiApi,
key = featureKey
)
onDispose {
builder.clear()
}
}

return daggerViewModel(key) {
builder
.build(context.mainUiApi)
.build<F>(
mainUiApi = mainUiApi,
key = featureKey
)
.viewModelFactory
}
}

inline fun <reified VM : ViewModel, F : Feature> NavGraphBuilder.createScreen(
inline fun <reified VM : ViewModel, reified F : Feature> NavGraphBuilder.createScreen(
appDestination: AppDestination,
featureBuilder: FeatureBuilder<F>,
crossinline content: @Composable (VM, List<String>) -> Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package st.slex.csplashscreen.core.ui.di

import android.content.Context

interface MainUiProvider {

val api: MainUiApi
}

val Context.mainUiApi: MainUiApi
get() = (this as MainUiProvider).api
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ import androidx.lifecycle.ViewModelProvider

interface Feature {

/**
* This property is used to get the ViewModelFactory of the feature
* @return ViewModelProvider.Factory
* */
val viewModelFactory: ViewModelProvider.Factory
}
Loading

0 comments on commit 21720be

Please sign in to comment.