-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcodemagic.yaml
More file actions
318 lines (288 loc) · 13.5 KB
/
codemagic.yaml
File metadata and controls
318 lines (288 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
scripts:
- &set_android_sdk_location
name: "Set Android SDK location"
script: |
echo "sdk.dir=$ANDROID_SDK_ROOT" > "$CM_BUILD_DIR/local.properties"
- &get_app_version
name: "Get RIA DigiDoc version"
script: |
echo "APP_VERSION_NAME=$(sed -n 's/^versionName = "\(.*\)"/\1/p' gradle/libs.versions.toml)" >> $CM_ENV
- &get_google_services_json
name: "Get Google Services configuration"
script: |
echo $GOOGLE_SERVICES_JSON | base64 --decode > $CM_BUILD_DIR/app/google-services.json
workflows:
debug:
name: RIA DigiDoc Android - Debug configuration
max_build_duration: 120
instance_type: linux_x2
environment:
ubuntu: 24.04
java: 17
groups:
- "google_services"
- "repo_ria"
- "debug"
vars:
PACKAGE_NAME: "ee.ria.DigiDoc"
android_signing:
- RIA DigiDoc (debug) (MOPP)
inputs:
defaultCentralConfigurationUrl_input:
description: Default Central Configuration URL
type: choice
default: http://10.1.24.31/config/mobile
options:
- http://10.1.24.31/config/mobile
- https://repo.ria/config
- https://id.eesti.ee
- https://id-test.eesti.ee
- https://id.test.eesti.ee
defaultCentralConfigurationUpdateInterval_input:
description: Default Central Configuration Update Interval
type: number
default: 4
defaultCentralConfigurationTslUrl_input:
description: Default Central Configuration TSL URL
type: choice
default: http://10.1.24.31/tsl/trusted-test-mp.xml
options:
- http://10.1.24.31/tsl/trusted-test-mp.xml
- https://ec.europa.eu/tools/lotl/eu-lotl.xml
- https://open-eid.github.io/test-TL/tl-mp-test-EE.xml
memberTsl_input:
description: TSL member lists
type: string
default: "EE;EE_T"
enableTests_input:
description: Run tests?
type: boolean
default: false
scripts:
- name: Parameters
script: |
echo Default Central Configuration URL: ${{ inputs.defaultCentralConfigurationUrl_input }}
echo Default Central Configuration Update Interval: ${{ inputs.defaultCentralConfigurationUpdateInterval_input }}
echo Default Central Configuration TSL URL: ${{ inputs.defaultCentralConfigurationTslUrl_input }}
echo "TSL member lists: ${{ inputs.memberTsl_input }}"
echo Run tests?: ${{ inputs.enableTests_input }}
- *set_android_sdk_location
- *get_app_version
- *get_google_services_json
- name: "Setup debug keystore"
script: |
DEBUG_KEYSTORE_PATH="app/src/main/assets/keystore/debug.keystore"
mkdir -p "$(dirname "$DEBUG_KEYSTORE_PATH")"
cp $CM_KEYSTORE_PATH $DEBUG_KEYSTORE_PATH &>/dev/null
echo "Debug keystore setup at $DEBUG_KEYSTORE_PATH"
- name: "Setup config and TSL files"
script: |
CONFIG_DIR=config-lib/src/main/assets/config
TSL_FILES_DIR=config-lib/src/main/assets/tslFiles
# Create central configuration and TSL folders
mkdir -p $CONFIG_DIR
mkdir -p $TSL_FILES_DIR
# Remove current eu-lotl.xml if it exists
rm -f $TSL_FILES_DIR/eu-lotl.xml
# Download latest 'eu-lotl' file
echo "Downloading latest 'eu-lotl.xml' file"
wget "https://ec.europa.eu/tools/lotl/eu-lotl.xml" -P $TSL_FILES_DIR
# Get repo.ria values from environmental variables, as CodeMagic doesn't have access to repo.ria domain
if [[ "${{ inputs.defaultCentralConfigurationTslUrl_input }}" == *"10.1.24.31"* ]]; then
echo "Using repo.ria configuration"
echo $REPO_RIA_DEFAULT_PROPERTIES | base64 --decode > $CONFIG_DIR/configuration.properties
echo $REPO_RIA_CONFIG | base64 --decode > $CONFIG_DIR/default-config.json
echo $REPO_RIA_PUB_KEY | base64 --decode > $CONFIG_DIR/default-config.pub
echo $REPO_RIA_RSA | base64 --decode > $CONFIG_DIR/default-config.rsa
echo $REPO_RIA_TRUSTED_TEST_MP | base64 --decode > $TSL_FILES_DIR/trusted-test-mp.xml
echo $REPO_RIA_TL_MP_TEST_EE | base64 --decode > $TSL_FILES_DIR/tl-mp-test-EE.xml
# EE_T.xml is too large to use in environmental variable. Using compressed variant
echo $REPO_RIA_EE_TSL | base64 --decode | gunzip > $TSL_FILES_DIR/EE_T.xml
else
echo "Not using repo.ria configuration"
fi
if [ -f "$TSL_FILES_DIR/eu-lotl.xml" ]; then
echo "Getting TSL (local LOTL)"
# Repo.ria TSL files already in assets folder, doesn't need to download separately anymore
if [[ "${{ inputs.defaultCentralConfigurationTslUrl_input }}" == *"10.1.24.31"* ]]; then
python3 scripts/TSLXMLDownloader.py --tslFile="$TSL_FILES_DIR/eu-lotl.xml" --countries="${{ inputs.memberTsl_input }}" --isDevBuild="True"
else
python3 scripts/TSLXMLDownloader.py --tslFile="$TSL_FILES_DIR/eu-lotl.xml" --tslTestFile="$TSL_FILES_DIR/$(basename ${{ inputs.defaultCentralConfigurationTslUrl_input }})" --countries="${{ inputs.memberTsl_input }}" --isDevBuild="True"
fi
echo "Finished downloading TSL"
else
echo "Getting TSL (remote LOTL)"
python3 scripts/TSLXMLDownloader.py --tslTestFile="$TSL_FILES_DIR/$(basename 'https://ec.europa.eu/tools/lotl/eu-lotl.xml')" --countries="${{ inputs.memberTsl_input }}" --isDevBuild="True"
echo "Finished downloading TSL"
fi
echo "Moving TSLs to app's assets"
mv -v scripts/TSL/* $TSL_FILES_DIR/
echo "Done moving TSLs"
- name: Fetch default configuration
script: |
# Not running 'fetchAndPackageDefaultConfiguration' for repo.ria as necessary files are already setup
if [[ ! "${{ inputs.defaultCentralConfigurationTslUrl_input }}" == *"10.1.24.31"* ]]; then
./gradlew clean --no-daemon fetchAndPackageDefaultConfiguration --args="${{ inputs.defaultCentralConfigurationUrl_input }} ${{ inputs.defaultCentralConfigurationUpdateInterval_input }}" -Dorg.gradle.jvmargs="-Xmx4g"
else
echo "Skipping default configuration fetching for repo.ria"
fi
- name: Run tests
script: |
./gradlew test
when:
condition: ${{ inputs.enableTests_input }}
- name: Launch emulator for instrumented tests
script: |
cd $ANDROID_HOME/tools
emulator -avd emulator-35 -memory 4096 &
adb wait-for-device
when:
condition: ${{ inputs.enableTests_input }}
- name: Run instrumented tests
script: |
set -e
cd $CM_BUILD_DIR
./gradlew connectedDebugAndroidTest -Dorg.gradle.jvmargs="-Xmx4g"
adb logcat -d > emulator.log
when:
condition: ${{ inputs.enableTests_input }}
- name: Build RIA DigiDoc
script: |
# Make latest build number be available in all build steps
APP_VERSION="$APP_VERSION_NAME.$BUILD_NUMBER"
echo "APP_VERSION=$APP_VERSION" >> $CM_ENV
echo "Using app version: $APP_VERSION"
echo "Updating version to $BUILD_NUMBER"
sed -i "s/versionCode = \".*\"/versionCode = \"$BUILD_NUMBER\"/" gradle/libs.versions.toml
# Build app
./gradlew clean --no-daemon assembleDebug --info --quiet
- name: Rename and move APK
script: |
DEBUG_OUTPUT_DIR="app/build/outputs/apk/debug"
SIGNED_DEBUG_DIR="$DEBUG_OUTPUT_DIR/signed-debug"
mkdir -p "$SIGNED_DEBUG_DIR"
mv "$DEBUG_OUTPUT_DIR/app-debug.apk" "$SIGNED_DEBUG_DIR/RIA_DigiDoc_dev_$APP_VERSION.apk"
artifacts:
- app/build/outputs/apk/debug/signed-debug/*.apk
publishing:
email:
recipients:
- marten.rebane@nortal.com
notify:
success: true
failure: true
live:
name: RIA DigiDoc Android - Live configuration
max_build_duration: 120
instance_type: linux_x2
environment:
ubuntu: 24.04
java: 17
groups:
- "google_services"
- "debug"
vars:
PACKAGE_NAME: "ee.ria.DigiDoc"
android_signing:
- RIA DigiDoc (MOPP)
scripts:
- *set_android_sdk_location
- *get_app_version
- *get_google_services_json
- name: "Setup debug keystore for tests"
script: |
DEBUG_KEYSTORE_PATH="app/src/main/assets/keystore/debug.keystore"
mkdir -p "$(dirname "$DEBUG_KEYSTORE_PATH")"
# Generate debug keystore
keytool -genkeypair -v -keystore "$DEBUG_KEYSTORE_PATH" -storepass $DEBUG_KEYSTORE_PASS -keypass $DEBUG_KEYSTORE_PASS \
-alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000 \
-dname "CN=Debug,O=Debug,C=EE"
echo "Debug keystore created at $DEBUG_KEYSTORE_PATH"
- name: Fetch default configuration and setup TSLs
script: |
./gradlew clean --no-daemon fetchAndPackageDefaultConfiguration -Dorg.gradle.jvmargs="-Xmx4g"
TSL_FILES_DIR=config-lib/src/main/assets/tslFiles
# Create TSLs folder
mkdir -p $TSL_FILES_DIR
# Remove current eu-lotl.xml if it exists
rm -f $TSL_FILES_DIR/eu-lotl.xml
# Download latest 'eu-lotl' file
echo "Downloading latest 'eu-lotl.xml' file"
wget "https://ec.europa.eu/tools/lotl/eu-lotl.xml" -P $TSL_FILES_DIR
echo "Getting TSL (remote LOTL)"
python3 scripts/TSLXMLDownloader.py --tslFile="$TSL_FILES_DIR/$(basename 'https://ec.europa.eu/tools/lotl/eu-lotl.xml')" --tslTestFile="$TSL_FILES_DIR/$(basename 'https://ec.europa.eu/tools/lotl/eu-lotl.xml')" --countries="EE" --isDevBuild="False"
echo "Finished downloading TSL"
echo "Moving TSLs to app's assets"
mv -v scripts/TSL/* $TSL_FILES_DIR/
echo "Done moving TSLs"
- name: Run tests
script: |
./gradlew test
- name: Launch emulator for instrumented tests
script: |
cd $ANDROID_HOME/tools
emulator -avd emulator-35 -memory 4096 &
adb wait-for-device
- name: Run instrumented tests
script: |
set -e
cd $CM_BUILD_DIR
./gradlew clean connectedDebugAndroidTest -Dorg.gradle.jvmargs="-Xmx4g"
adb logcat -d > emulator.log
- name: Build RIA DigiDoc
script: |
# Get latest build numbers from "internal" and "production" tracks
LATEST_GOOGLE_PLAY_INTERNAL_BUILD_NUMBER=$(google-play get-latest-build-number --package-name "$PACKAGE_NAME" --tracks internal)
LATEST_GOOGLE_PLAY_PRODUCTION_BUILD_NUMBER=$(google-play get-latest-build-number --package-name "$PACKAGE_NAME" --tracks production)
# Check that both tracks have valid build numbers (over 0) and select the highest.
# Add +1 to the highest build number to submit to Google Play
# If any are 0, use build number
if [ "$LATEST_GOOGLE_PLAY_INTERNAL_BUILD_NUMBER" -gt 0 ] && [ "$LATEST_GOOGLE_PLAY_PRODUCTION_BUILD_NUMBER" -gt 0 ]; then
if [ "$LATEST_GOOGLE_PLAY_INTERNAL_BUILD_NUMBER" -gt "$LATEST_GOOGLE_PLAY_PRODUCTION_BUILD_NUMBER" ]; then
LATEST_BUILD_NUMBER=$(($LATEST_GOOGLE_PLAY_INTERNAL_BUILD_NUMBER + 1))
echo "New build number for this build: $LATEST_BUILD_NUMBER"
echo LATEST_BUILD_NUMBER=$LATEST_BUILD_NUMBER >> $CM_ENV
else
LATEST_BUILD_NUMBER=$(($LATEST_GOOGLE_PLAY_PRODUCTION_BUILD_NUMBER + 1))
echo "New build number for this build: $LATEST_BUILD_NUMBER"
echo LATEST_BUILD_NUMBER=$LATEST_BUILD_NUMBER >> $CM_ENV
fi
else
# Display error and exit
echo "One or both build numbers are 0" >&2
exit 1
fi
# Make latest build number be available in all build steps
APP_VERSION="$APP_VERSION_NAME.$LATEST_BUILD_NUMBER"
echo "APP_VERSION=$APP_VERSION" >> $CM_ENV
echo "Using app version: $APP_VERSION"
echo "Updating version to $LATEST_BUILD_NUMBER"
sed -i "s/versionCode = \".*\"/versionCode = \"$LATEST_BUILD_NUMBER\"/" gradle/libs.versions.toml
# Build app
./gradlew clean --no-daemon assembleRelease --quiet
- name: Align APK
script: |
OUTPUT_DIR="app/build/outputs/apk/release"
zipalign -v -p 4 $OUTPUT_DIR/app-release-unsigned.apk $OUTPUT_DIR/app-release-unsigned-aligned.apk
- name: Sign APK
script: |
OUTPUT_DIR="app/build/outputs/apk/release"
apksigner sign --ks $CM_KEYSTORE_PATH --ks-pass pass:$CM_KEYSTORE_PASSWORD --out $OUTPUT_DIR/app-release_$APP_VERSION.apk $OUTPUT_DIR/app-release-unsigned-aligned.apk
- name: Rename and move APK
script: |
OUTPUT_DIR="app/build/outputs/apk/release"
SIGNED_DIR="$OUTPUT_DIR/signed"
mkdir -p "$SIGNED_DIR"
mv "$OUTPUT_DIR/app-release_$APP_VERSION.apk" "$SIGNED_DIR/RIA_DigiDoc_$APP_VERSION.apk"
artifacts:
- app/build/outputs/apk/release/signed/*.apk
publishing:
email:
recipients:
- marten.rebane@nortal.com
notify:
success: true
failure: true
google_play:
credentials: $GOOGLE_PLAY_SERVICE_ACCOUNT_CREDENTIALS
track: internal