Skip to content

Commit 5bcab0e

Browse files
committed
Refactored CI scripts for improved robustness and emulator handling
- Updated shebangs to `#!/usr/bin/env bash` and added `set -euo pipefail` for better error handling. - Improved emulator setup in `ci-setup-and-run-emulator.sh` by ensuring a fresh AVD state and configuring hardware parameters like RAM and GPU. - Optimized `ci-wait-for-emulator.sh` with more reliable boot completion checks and a retry loop for internet connectivity. - Added existence checks for directories and files in artifact and test result publishing scripts to prevent errors when files are missing. - Cleaned up redundant script headers and refactored argument handling in instrumentation test scripts.
1 parent bae1500 commit 5bcab0e

11 files changed

Lines changed: 173 additions & 77 deletions

script/ci-after-success-actions-for-instrumentation-tests.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
#
4+
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
5+
# Contributors: denbond7
6+
#
7+
8+
set -euo pipefail
29

310
if [[ "$SEMAPHORE_JOB_NAME" =~ ^Instrumentation.* ]]; then
411
# print debug info about connected device
512
echo "Print connected devices"
613
adb devices
714

8-
# store logcat log
15+
if [[ -f "$HOME/logcat_log.txt" ]]; then
916
echo "Store logcat log"
10-
artifact push job ~/logcat_log.txt
17+
artifact push job "$HOME/logcat_log.txt"
18+
else
19+
echo "No logcat_log.txt found, skipping"
20+
fi
1121

12-
# store screenshots
13-
echo "Store screenshots"
14-
adb pull "/sdcard/Pictures"
15-
adb shell ls /sdcard/Pictures
22+
echo "Store screenshots"
23+
if adb shell test -d /sdcard/Pictures; then
24+
rm -rf Pictures
25+
adb pull "/sdcard/Pictures" Pictures
1626
artifact push job Pictures
27+
else
28+
echo "No /sdcard/Pictures directory found, skipping"
29+
fi
1730
fi
18-

script/ci-get-and-publish-debug-info-as-artifact.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
#
4+
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
5+
# Contributors: denbond7
6+
#
7+
8+
set -euo pipefail
29

310
if [[ "$SEMAPHORE_JOB_NAME" =~ ^Lint.* ]]; then
4-
# don't do any things for 'Lint(structural quality)' job
5-
exit 0
11+
# Do nothing for 'Lint(structural quality)' job.
12+
exit 0
613
fi
714

8-
echo "Store tests results for $SEMAPHORE_JOB_NAME"
9-
artifact push job FlowCrypt/build/reports/
15+
reports_dir="FlowCrypt/build/reports/"
16+
if [[ -d "$reports_dir" ]]; then
17+
echo "Store test reports for $SEMAPHORE_JOB_NAME"
18+
artifact push job "$reports_dir"
19+
else
20+
echo "Reports directory does not exist: $reports_dir"
21+
fi
1022

1123
if [[ "$SEMAPHORE_JOB_NAME" =~ ^Instrumentation.* ]]; then
12-
# store full logcat log
13-
echo "Collect logcat logs as logcat.txt.gz for $SEMAPHORE_JOB_NAME"
14-
adb logcat -d | gzip > ~/logcat.txt.gz
15-
artifact push job ~/logcat.txt.gz
24+
# store full logcat log
25+
echo "Collect logcat logs as logcat.txt.gz for $SEMAPHORE_JOB_NAME"
26+
adb logcat -d | gzip > "$HOME/logcat.txt.gz"
27+
artifact push job "$HOME/logcat.txt.gz"
1628

17-
# store the device's screenshot. it may help to debug a failure
18-
echo "Store the device's screenshot for $SEMAPHORE_JOB_NAME"
19-
adb shell screencap -p /sdcard/screencap.png
20-
adb pull "/sdcard/screencap.png"
21-
artifact push job screencap.png
29+
echo "Store the device's screenshot for $SEMAPHORE_JOB_NAME"
30+
if adb shell screencap -p /sdcard/screencap.png; then
31+
if adb pull "/sdcard/screencap.png"; then
32+
artifact push job screencap.png
33+
else
34+
echo "Could not pull screencap.png"
35+
fi
36+
else
37+
echo "Could not create screencap.png"
38+
fi
2239
fi
23-
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8-
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 --no-daemon --build-cache --max-workers=2 :FlowCrypt:connectedEnterpriseUiTestsAndroidTest \
8+
set -euo pipefail
9+
10+
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:connectedEnterpriseUiTestsAndroidTest \
911
-Pandroid.testInstrumentationRunnerArguments.filter=com.flowcrypt.email.junit.filters.EnterpriseTestsFilter
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8+
set -euo pipefail
9+
810
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:connectedEnterpriseUiTestsAndroidTest \
911
-Pandroid.testInstrumentationRunnerArguments.filter=com.flowcrypt.email.junit.filters.ReadyForCIAndFlakyFilter

script/ci-instrumentation-tests-with-mailserver.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8+
set -euo pipefail
9+
810
#print test names
911
#adb shell am instrument -r -w \
1012
# -e filter com.flowcrypt.email.junit.filters.DependsOnMailServerFilter \
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8-
if [[ -z "$1" ]];
9-
then
8+
set -euo pipefail
9+
10+
if [[ -z "${1:-}" ]]; then
1011
echo "numShards is unset or set to the empty string"
1112
exit 1
12-
else
13-
varNumShards=$1
1413
fi
1514

16-
if [[ -z "$2" ]];
17-
then
15+
if [[ -z "${2:-}" ]]; then
1816
echo "shardIndex is unset or set to the empty string"
1917
exit 1
20-
else
21-
varShardIndex=$2
2218
fi
2319

24-
if [[ ${varShardIndex} -ge ${varNumShards} ]]
25-
then
20+
numShards="$1"
21+
shardIndex="$2"
22+
23+
if (( shardIndex >= numShards )); then
2624
echo "shardIndex should be lower than numShards"
27-
else
28-
#print test names
29-
#adb shell am instrument -w \
30-
# -e filter com.flowcrypt.email.junit.filters.DoesNotNeedMailServerFilter \
31-
# -e numShards 3 \
32-
# -e shardIndex 1 \
33-
# -e log true \
34-
# com.flowcrypt.email.debug.test/androidx.test.runner.AndroidJUnitRunner
35-
36-
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:connectedConsumerUiTestsAndroidTest \
37-
-Pandroid.testInstrumentationRunnerArguments.filter=com.flowcrypt.email.junit.filters.DoesNotNeedMailServerFilter \
38-
-Pandroid.testInstrumentationRunnerArguments.numShards="${varNumShards}" \
39-
-Pandroid.testInstrumentationRunnerArguments.shardIndex="${varShardIndex}"
25+
exit 1
4026
fi
27+
28+
#print test names
29+
#adb shell am instrument -w \
30+
# -e filter com.flowcrypt.email.junit.filters.DoesNotNeedMailServerFilter \
31+
# -e numShards 3 \
32+
# -e shardIndex 1 \
33+
# -e log true \
34+
# com.flowcrypt.email.debug.test/androidx.test.runner.AndroidJUnitRunner
35+
36+
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:connectedConsumerUiTestsAndroidTest \
37+
-Pandroid.testInstrumentationRunnerArguments.filter=com.flowcrypt.email.junit.filters.DoesNotNeedMailServerFilter \
38+
-Pandroid.testInstrumentationRunnerArguments.numShards="${numShards}" \
39+
-Pandroid.testInstrumentationRunnerArguments.shardIndex="${shardIndex}"

script/ci-junit-tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8+
set -euo pipefail
9+
810
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:testConsumerUiTestsUnitTest

script/ci-lint-checks.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8+
set -euo pipefail
9+
810
./gradlew --console=plain --no-daemon --build-cache --max-workers=2 :FlowCrypt:lintConsumerUiTests

script/ci-publish-test-results.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
#
4+
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
5+
# Contributors: denbond7
6+
#
7+
8+
set -euo pipefail
29

310
if [[ "$SEMAPHORE_JOB_NAME" =~ ^Instrumentation.* ]]; then
4-
# publish test results for Instrumentation tests
5-
test-results publish ~/git/flowcrypt-android/FlowCrypt/build/outputs/androidTest-results/connected/ --name "$SEMAPHORE_JOB_NAME"
11+
results_dir="$HOME/git/flowcrypt-android/FlowCrypt/build/outputs/androidTest-results/connected/"
12+
if [[ -d "$results_dir" ]]; then
13+
test-results publish "$results_dir" --name "$SEMAPHORE_JOB_NAME"
14+
else
15+
echo "Instrumentation test results directory does not exist: $results_dir"
16+
fi
617
fi
718

819
if [[ "$SEMAPHORE_JOB_NAME" =~ ^JUnit.* ]]; then
9-
# publish test results for JUnit tests
10-
test-results publish ~/git/flowcrypt-android/FlowCrypt/build/test-results/ --name "$SEMAPHORE_JOB_NAME"
20+
results_dir="$HOME/git/flowcrypt-android/FlowCrypt/build/test-results/"
21+
if [[ -d "$results_dir" ]]; then
22+
test-results publish "$results_dir" --name "$SEMAPHORE_JOB_NAME"
23+
else
24+
echo "JUnit test results directory does not exist: $results_dir"
25+
fi
1126
fi
12-
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
#
44
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
55
# Contributors: denbond7
66
#
77

8+
set -euo pipefail
9+
10+
AVD_NAME="ci-emulator"
11+
SYSTEM_IMAGE="system-images;android-36;google_apis;x86_64"
12+
DEVICE_NAME="pixel_9"
13+
ABI="google_apis/x86_64"
14+
815
"$ANDROID_HOME/emulator/emulator" -accel-check
16+
17+
# Keep the emulator fresh for every CI job. Do not reuse AVD state.
18+
rm -rf "$HOME/.android/avd/${AVD_NAME}.avd" "$HOME/.android/avd/${AVD_NAME}.ini"
19+
920
avdmanager list devices #debug
10-
echo -ne '\n' | avdmanager -v create avd --name ci-emulator --package "system-images;android-36;google_apis;x86_64" --device 'pixel_9' --abi 'google_apis/x86_64'
11-
cat ~/.android/avd/ci-emulator.avd/config.ini
12-
# echo "hw.ramSize=3064" >> ~/.android/avd/ci-emulator.avd/config.ini
13-
# cat ~/.android/avd/ci-emulator.avd/config.ini
21+
22+
echo -ne '\n' | avdmanager -v create avd \
23+
--name "$AVD_NAME" \
24+
--package "$SYSTEM_IMAGE" \
25+
--device "$DEVICE_NAME" \
26+
--abi "$ABI"
27+
28+
# Keep RAM modest for e2-standard-2. This file belongs to the fresh AVD created above.
29+
echo "hw.ramSize=2048" >> "$HOME/.android/avd/${AVD_NAME}.avd/config.ini"
30+
cat "$HOME/.android/avd/${AVD_NAME}.avd/config.ini"
31+
1432
"$ANDROID_HOME/emulator/emulator" -list-avds #debug
15-
"$ANDROID_HOME/emulator/emulator" -avd ci-emulator -no-snapshot -no-window -no-boot-anim -no-audio -gpu auto -read-only -no-metrics &
33+
34+
"$ANDROID_HOME/emulator/emulator" \
35+
-avd "$AVD_NAME" \
36+
-no-window \
37+
-no-boot-anim \
38+
-no-audio \
39+
-no-snapshot \
40+
-no-snapshot-load \
41+
-no-snapshot-save \
42+
-wipe-data \
43+
-gpu swiftshader_indirect \
44+
-read-only \
45+
-no-metrics &

0 commit comments

Comments
 (0)