Skip to content

Commit af68da7

Browse files
committed
fix: update release signing configuration to read from local .env file if environment variables are not set
1 parent 8b48f5a commit af68da7

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

app/build.gradle.kts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,37 @@ android {
2020
}
2121

2222
signingConfigs {
23-
create("release") {
24-
// Read signing details from environment variables (populated by GitHub Secrets)
25-
val keyStorePath = System.getenv("SIGNING_KEY_STORE_PATH")
26-
val keyAlias = System.getenv("SIGNING_KEY_ALIAS")
27-
val keyStorePassword = System.getenv("SIGNING_KEY_STORE_PASSWORD")
28-
val keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
23+
// Read from environment first; if missing, read from a local .env file (ignored by Git)
24+
val env = System.getenv()
25+
val dotEnvFile = rootProject.file(".env")
26+
val dotEnv: Map<String, String> = if (dotEnvFile.exists()) {
27+
dotEnvFile.readLines()
28+
.map { it.trim() }
29+
.filter { it.isNotEmpty() && !it.startsWith("#") && it.contains('=') }
30+
.associate { line ->
31+
val idx = line.indexOf('=')
32+
val key = line.substring(0, idx).trim()
33+
var value = line.substring(idx + 1).trim()
34+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''))) {
35+
value = value.substring(1, value.length - 1)
36+
}
37+
key to value
38+
}
39+
} else emptyMap()
2940

30-
if (keyStorePath != null && keyAlias != null && keyStorePassword != null && keyPassword != null) {
31-
storeFile = file(keyStorePath)
32-
storePassword = keyStorePassword
33-
this.keyAlias = keyAlias
34-
this.keyPassword = keyPassword
35-
} else {
36-
println("Release signing configuration not found. Using debug signing.")
37-
// Fallback to debug signing if env vars are not set (e.g., local builds)
38-
// Or handle this case as needed, e.g., throw an error
41+
fun readSecret(name: String): String? = env[name] ?: dotEnv[name]
42+
43+
val ksPath = readSecret("SIGNING_KEY_STORE_PATH")
44+
val ksAlias = readSecret("SIGNING_KEY_ALIAS")
45+
val ksStorePassword = readSecret("SIGNING_KEY_STORE_PASSWORD")
46+
val ksKeyPassword = readSecret("SIGNING_KEY_PASSWORD")
47+
48+
if (!ksPath.isNullOrEmpty() && !ksAlias.isNullOrEmpty() && !ksStorePassword.isNullOrEmpty() && !ksKeyPassword.isNullOrEmpty()) {
49+
create("release") {
50+
storeFile = (ksPath as Any?)?.let { file(it) }
51+
storePassword = ksStorePassword
52+
keyAlias = ksAlias
53+
keyPassword = ksKeyPassword
3954
}
4055
}
4156
}

0 commit comments

Comments
 (0)