Skip to content

Commit 499b736

Browse files
committed
build: improve CI release build and signing config
Update CI workflow to support automated release builds with decoded keystore and add conditional signing configuration in Gradle for safer local and remote builds.
1 parent 6a7377c commit 499b736

2 files changed

Lines changed: 40 additions & 33 deletions

File tree

.github/workflows/android.yml

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ "main", "master" ]
66
pull_request:
77
branches: [ "main", "master" ]
8+
workflow_dispatch:
89

910
jobs:
1011
build:
@@ -19,26 +20,42 @@ jobs:
1920
with:
2021
java-version: '17'
2122
distribution: 'temurin'
22-
cache: gradle
2323

24-
- name: Create .env from GitHub Secrets
24+
- name: Setup Gradle
25+
uses: gradle/actions/setup-gradle@v3
26+
27+
- name: Create .env File
28+
run: |
29+
touch .env
30+
if [ -n "${{ secrets.GEMINI_API_KEY }}" ]; then
31+
echo "GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" >> .env
32+
else
33+
echo "GEMINI_API_KEY=placeholder_key" >> .env
34+
fi
35+
36+
- name: Decode Keystore
37+
if: ${{ secrets.KEYSTORE_BASE64 != '' }}
2538
run: |
26-
echo "GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}" >> .env
39+
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > release.keystore
2740
28-
- name: Grant Execute Permission for Gradle Wrapper
41+
- name: Grant Execute Permissions
2942
run: |
3043
if [ -f "./gradlew" ]; then
3144
chmod +x gradlew
3245
fi
3346
34-
- name: Build Debug APK
47+
- name: Build Debug & Release APKs
3548
env:
49+
KEYSTORE_PATH: ${{ github.workspace }}/release.keystore
50+
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
51+
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
52+
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
3653
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
3754
run: |
3855
if [ -f "./gradlew" ]; then
39-
./gradlew assembleDebug --no-daemon
56+
./gradlew assembleDebug assembleRelease --no-daemon
4057
else
41-
gradle assembleDebug --no-daemon
58+
gradle assembleDebug assembleRelease --no-daemon
4259
fi
4360
4461
- name: Run Unit Tests
@@ -49,36 +66,18 @@ jobs:
4966
gradle testDebugUnitTest --no-daemon
5067
fi
5168
52-
- name: Decode Keystore (Optional for Release)
53-
if: ${{ secrets.KEYSTORE_BASE64 != '' }}
54-
run: |
55-
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > release.keystore
56-
57-
- name: Build Release APK
58-
if: ${{ secrets.KEYSTORE_BASE64 != '' }}
59-
env:
60-
KEYSTORE_PATH: ${{ github.workspace }}/release.keystore
61-
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
62-
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
63-
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
64-
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
65-
run: |
66-
if [ -f "./gradlew" ]; then
67-
./gradlew assembleRelease --no-daemon
68-
else
69-
gradle assembleRelease --no-daemon
70-
fi
71-
7269
- name: Upload Debug APK Artifact
70+
if: always()
7371
uses: actions/upload-artifact@v4
7472
with:
7573
name: app-debug-apk
7674
path: app/build/outputs/apk/debug/app-debug.apk
75+
if-no-files-found: ignore
7776

7877
- name: Upload Release APK Artifact
79-
if: ${{ secrets.KEYSTORE_BASE64 != '' }}
78+
if: always()
8079
uses: actions/upload-artifact@v4
8180
with:
8281
name: app-release-apk
8382
path: app/build/outputs/apk/release/app-release.apk
84-
83+
if-no-files-found: ignore

app/build.gradle.kts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ android {
2626
signingConfigs {
2727
create("release") {
2828
val keystorePath = System.getenv("KEYSTORE_PATH") ?: "${rootDir}/my-upload-key.jks"
29-
storeFile = file(keystorePath)
30-
storePassword = System.getenv("STORE_PASSWORD")
31-
keyAlias = "upload"
32-
keyPassword = System.getenv("KEY_PASSWORD")
29+
val kFile = file(keystorePath)
30+
if (kFile.exists()) {
31+
storeFile = kFile
32+
storePassword = System.getenv("STORE_PASSWORD")
33+
keyAlias = System.getenv("KEY_ALIAS") ?: "upload"
34+
keyPassword = System.getenv("KEY_PASSWORD")
35+
} else {
36+
storeFile = file("${rootDir}/debug.keystore")
37+
storePassword = "android"
38+
keyAlias = "androiddebugkey"
39+
keyPassword = "android"
40+
}
3341
}
3442
create("debugConfig") {
3543
storeFile = file("${rootDir}/debug.keystore")

0 commit comments

Comments
 (0)