Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added singing config for generating bundle #8

Merged
merged 16 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Publish to Play Store and Bump Version

on:
push:
branches:
- master

jobs:
publish_and_version_bump:
runs-on: ubuntu-latest

steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.GITHUB_APP_ID }}
private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}

- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}

- name: Set up JDK 20
uses: actions/setup-java@v4
with:
java-version: '20'
distribution: 'zulu'

- name: Create Keystore file
run: |
echo "${{ secrets.KEYSTORE_AS_BASE64 }}" | base64 --decode > app/keystore.jks

- name: Build Release AAB
run: ./gradlew bundleProdRelease
env:
SIGNING_STORE_FILE: app/keystore.jks
SIGNING_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}

- name: Deploy to Google Play Internal Testing
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_ACCOUNT_AS_BASE64 }}
packageName: "rees46.demo_shop"
releaseFiles: "app/build/outputs/bundle/prodRelease/app-prod-release.aab"
track: "internal"

- name: Bump version
run: ./gradlew incrementVersion
env:
PROPERTIES_FILE: version.properties

- name: Retrieve new version
id: versionName
run: |
version=$(grep "VERSION_NAME=" version.properties | cut -d'=' -f2)
echo "versionName=$version" >> $GITHUB_ENV
echo "versionName=$version" >> $GITHUB_OUTPUT

- name: Commit changes
id: committer
uses: planetscale/ghcommit-action@v0.1.44
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
with:
repo: ${{ github.repository }}
branch: master
commit_message: 'chore: bump version to ${{ steps.versionName.outputs.versionName }}'
file_pattern: 'version.properties'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ render.experimental.xml

# Google Services (e.g. APIs or Firebase)
google-services.json
play-account.json

# Android Profiling
*.hprof
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REES46 Demo Android - application to demonstrate working with SDK.

Versions:
- REES46 SDK 2.0.20
- Java 22
- Java 20
- Kotlin 2.0.0
- Gradle 8.8
- Android Gradle Plugin 8.5.2
Expand Down
13 changes: 9 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ plugins {
id("com.example.build.config")
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.triplet.plugin)
id("com.google.gms.google-services")
id("androidx.navigation.safeargs.kotlin")
}

play {
serviceAccountCredentials = file("play-account.json")
track = "internal"
defaultToAppBundles = true
}

android {
namespace = "rees46.demo_android.app"

defaultConfig {
applicationId = "rees46.demo_android"
applicationId = "rees46.demo_shop"
}
}

Expand All @@ -26,10 +33,8 @@ dependencies {
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.core.splashscreen)
implementation(libs.dagger)
implementation(libs.rees46.sdk)
annotationProcessor(libs.dagger.compiler)
implementation(project(":core"))
implementation(project(":feature"))
implementation(project(":navigation"))
}
}
115 changes: 87 additions & 28 deletions buildConfig/src/main/kotlin/AppBuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.Properties
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -11,7 +15,7 @@ class AppBuildConfig : Plugin<Project> {

override fun apply(project: Project) {
project.plugins.withId(ANDROID_APPLICATION_LIB) {
configureAppExtension(project.extensions.getByType(AppExtension::class.java))
configureAppExtension(project.extensions.getByType(AppExtension::class.java), project)
}

project.plugins.withId(ANDROID_LIB) {
Expand All @@ -21,37 +25,73 @@ class AppBuildConfig : Plugin<Project> {
configureKotlinCompile(project)
}

private fun configureAppExtension(androidExtension: AppExtension) {
private fun configureAppExtension(androidExtension: AppExtension, project: Project) {
val versionPropsFile = File(project.rootProject.projectDir, "version.properties")
val versionProps = Properties()
if (versionPropsFile.exists()) {
versionProps.load(FileInputStream(versionPropsFile))
}

val currentVersionCode = versionProps[VERSION_CODE]?.toString()?.toInt() ?: 1
val currentVersionName = versionProps[VERSION_NAME]?.toString() ?: "1.0.0"

androidExtension.apply {
compileSdkVersion(TARGET_SDK)
configureDefaultConfig()
defaultConfig {
applicationId = APPLICATION_ID
minSdk = MIN_SDK
targetSdk = TARGET_SDK
versionCode = currentVersionCode
versionName = currentVersionName
viewBinding {
enable = true
}
}
flavorDimensions(DIMENSION_FLAVORS)
configureProductFlavors()
configureSigningConfigs()
configureSigningConfigs(project)
configureBuildTypes()
configurePackagingOptions()
configureJavaAndKotlinOptions()

project.tasks.register(PUBLISH_TO_ITERNAL_TESTING) {
dependsOn(RELEASE_BUNDLE)
finalizedBy(PUBLISH_RELEASE_BUNDLE)
}

project.tasks.register(INCREMENT_VERSION) {
doLast {
incrementVersion(versionProps, versionPropsFile)
}
}
}
}

private fun AppExtension.configureDefaultConfig() {
defaultConfig {
applicationId = APPLICATION_ID
minSdk = MIN_SDK
targetSdk = TARGET_SDK
versionCode = VERSION_CODE
versionName = VERSION_NAME
viewBinding {
enable = true
}
private fun incrementVersion(versionProps: Properties, versionPropsFile: File) {
val currentVersionCode = versionProps[VERSION_CODE]?.toString()?.toInt() ?: 1
val newVersionCode = currentVersionCode + 1

val currentVersionName = versionProps[VERSION_NAME]?.toString() ?: "1.0.0"
val versionNameParts = currentVersionName.split(".").toMutableList()

if (versionNameParts.size == 3) {
val patchVersion = versionNameParts[2].toIntOrNull() ?: 0
versionNameParts[2] = (patchVersion + 1).toString()
}

val newVersionName = versionNameParts.joinToString(".")

versionProps[VERSION_CODE] = newVersionCode.toString()
versionProps[VERSION_NAME] = newVersionName
versionProps.store(FileOutputStream(versionPropsFile), null)

println("Version updated to: versionCode=$newVersionCode, versionName=$newVersionName")
}

private fun AppExtension.configureProductFlavors() {
productFlavors {
create(DEV_FLAVOR) {
dimension = DIMENSION_FLAVORS
// applicationIdSuffix = APPLICATION_DEV_SUFFIX
}
create(STAGE_FLAVOR) {
dimension = DIMENSION_FLAVORS
Expand All @@ -63,13 +103,21 @@ class AppBuildConfig : Plugin<Project> {
}
}

private fun AppExtension.configureSigningConfigs() {
private fun AppExtension.configureSigningConfigs(project: Project) {
val localProperties = Properties()
val localPropertiesFile = project.rootProject.file(LOCAL_PROPERTIES_FILE)
if (localPropertiesFile.exists()) {
localProperties.load(FileInputStream(localPropertiesFile))
}

signingConfigs {
create(RELEASE_CONFIG) {
// Configuration for releaseConfig
storeFile = File(localProperties.getProperty(RELEASE_STORE_FILE))
storePassword = localProperties.getProperty(RELEASE_STORE_PASSWORD)
keyAlias = localProperties.getProperty(RELEASE_KEY_ALIAS)
keyPassword = localProperties.getProperty(RELEASE_KEY_PASSWORD)
}
create(DEBUG_CONFIG) {
// Configuration for debugConfig
}
}
}
Expand Down Expand Up @@ -149,26 +197,37 @@ class AppBuildConfig : Plugin<Project> {
}

companion object {
private const val APPLICATION_ID = "rees46.demo_android"
private const val PUBLISH_TO_ITERNAL_TESTING = "publishProdReleaseToPlay"
private const val PUBLISH_RELEASE_BUNDLE = "publishProdReleaseBundle"
private const val LOCAL_PROPERTIES_FILE = "local.properties"
private const val INCREMENT_VERSION = "incrementVersion"
private const val RELEASE_BUNDLE = "bundleProdRelease"

private const val VERSION_NAME = "VERSION_NAME"
private const val VERSION_CODE = "VERSION_CODE"

private const val RELEASE_STORE_PASSWORD = "RELEASE_STORE_PASSWORD"
private const val RELEASE_KEY_PASSWORD = "RELEASE_KEY_PASSWORD"
private const val RELEASE_STORE_FILE = "RELEASE_STORE_FILE"
private const val RELEASE_KEY_ALIAS = "RELEASE_KEY_ALIAS"

private const val ANDROID_APPLICATION_LIB = "com.android.application"
private const val APPLICATION_ID = "rees46.demo_android"
private const val ANDROID_LIB = "com.android.library"
private const val MIN_SDK = 24
private const val TARGET_SDK = 34
private const val VERSION_CODE = 1
private const val VERSION_NAME = "1.0.0"
private const val JVM_TARGET = "20"
private const val TARGET_SDK = 34
private const val MIN_SDK = 24

private const val RELEASE_TYPE = "release"
private const val RELEASE_CONFIG = "releaseConfig"
private const val DEBUG_TYPE = "debug"
private const val DEBUG_CONFIG = "debugConfig"
private const val RELEASE_TYPE = "release"
private const val DEBUG_TYPE = "debug"

private const val DEV_FLAVOR = "dev"
private const val STAGE_FLAVOR = "stage"
private const val PROD_FLAVOR = "prod"
private const val DIMENSION_FLAVORS = "medical"
private const val APPLICATION_DEV_SUFFIX = ".debug"
private const val DEV_FLAVOR = "dev"
private const val APPLICATION_STAGE_SUFFIX = ".test"
private const val DIMENSION_FLAVORS = "demoShop"

private const val PROGUARD_ANDROID_TXT = "proguard-android-optimize.txt"
private const val PROGUARD_RULES = "proguard-rules.pro"
Expand Down
2 changes: 0 additions & 2 deletions feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ android {
}

dependencies {
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.ui)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
Expand Down
Loading