Skip to content

Commit 557b020

Browse files
committed
feat: add script to populate local.properties from environment variables
This commit introduces a shell script `before-ci.sh`. The script reads keys from `local.properties.example` and for each key, it retrieves the corresponding value from the environment variables. If a value is found, the key-value pair is appended to the `local.properties` file. This allows for dynamic configuration of build properties based on the CI environment.
1 parent b76e09b commit 557b020

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

app/build.gradle

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,24 @@ static def getBuildDate() {
1111
return formattedDate
1212
}
1313

14-
1514
def localProperties = new Properties()
1615
def localPropertiesFile = rootProject.file("local.properties")
1716
if (localPropertiesFile.exists()) {
1817
localProperties.load(new FileInputStream(localPropertiesFile))
18+
} else {
19+
localProperties.setProperty("KEYSTORE_FILE", "keystore-qrbarcode.jks")
20+
localProperties.setProperty("KEYSTORE_PASSWORD", System.getenv("KEYSTORE_PASSWORD"))
21+
localProperties.setProperty("KEY_ALIAS", System.getenv("KEY_ALIAS"))
22+
localProperties.setProperty("KEY_PASSWORD", System.getenv("KEY_PASSWORD"))
1923
}
2024

21-
def debugKeystoreFile = localProperties["KEYSTORE_FILE"]
22-
def debugKeystorePassword = localProperties["KEYSTORE_PASSWORD"]
23-
def debugKeyAlias = localProperties["KEY_ALIAS"]
24-
def debugKeyPassword = localProperties["KEY_PASSWORD"]
25-
26-
27-
def releaseKeystoreFilePath = System.getenv("KEYSTORE_FILE")
28-
def releaseKeystorePassword = System.getenv("KEYSTORE_PASSWORD")
29-
def releaseKeyAlias = System.getenv("KEY_ALIAS")
30-
def releaseKeyPassword = System.getenv("KEY_PASSWORD")
31-
32-
def hasKeystore = releaseKeystoreFilePath != null && !releaseKeystoreFilePath.trim().isEmpty()
33-
3425
android {
3526
signingConfigs {
36-
if (hasKeystore) {
37-
release {
38-
storeFile file(releaseKeystoreFilePath)
39-
storePassword releaseKeystorePassword
40-
keyAlias releaseKeyAlias
41-
keyPassword releaseKeyPassword
42-
}
43-
} else {
44-
debug {
45-
storeFile file(debugKeystoreFile)
46-
storePassword debugKeystorePassword
47-
keyAlias debugKeyAlias
48-
keyPassword debugKeyPassword
49-
}
27+
release {
28+
storeFile file(localProperties.getProperty("KEYSTORE_FILE"))
29+
storePassword localProperties.getProperty("KEYSTORE_PASSWORD")
30+
keyAlias localProperties.getProperty("KEY_ALIAS")
31+
keyPassword localProperties.getProperty("KEY_PASSWORD")
5032
}
5133
}
5234

@@ -68,7 +50,7 @@ android {
6850
minifyEnabled true
6951
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
7052
versionNameSuffix " build:" + BUILD_DATE
71-
signingConfig hasKeystore ? signingConfigs.release : signingConfigs.debug
53+
signingConfig signingConfigs.release
7254
}
7355
debug {
7456
debuggable true

scripts/before-ci.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
api_properties_file="local.properties.example"
4+
5+
local_properties_file="local.properties"
6+
7+
echo "# The following entries are automatically generated by a script" >> $local_properties_file
8+
9+
while IFS='=' read -r key _; do
10+
if [[ -n "$key" ]]; then
11+
value=$(printenv $key)
12+
13+
if [[ -n "$value" ]]; then
14+
echo "$key=$value" >> $local_properties_file
15+
fi
16+
fi
17+
done < $api_properties_file
18+
19+
echo "Selected environment variables have been appended to $local_properties_file."

0 commit comments

Comments
 (0)