diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index b1c40ecc3..46bed95e5 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -7,71 +7,24 @@ on:
paths-ignore:
- '**.md'
jobs:
- Build:
- runs-on: ubuntu-latest
+ Test:
+ runs-on: self-hosted
steps:
- name: Check out source code
uses: actions/checkout@v1
- - name: Install Java Development Kit 11
- uses: actions/setup-java@v1
- with:
- java-version: 11
-
- - name: Build Project
+ - name: Build project
run: ./build.sh build
- - name: Upload Build Artifacts
- uses: actions/upload-artifact@v2
- with:
- name: uhabits-android
- path: uhabits-android/build/outputs/
-
- AndroidTest:
- needs: Build
- runs-on: macOS-10.15
- timeout-minutes: 60
- strategy:
- matrix:
- api: [
- 25,
- 27,
- 28,
- 30,
- 31,
- ]
+ - name: Run Android tests
+ run: ./build.sh android-tests-parallel 23 24 25 26 27 28 30 31
- steps:
- - name: Check out source code
- uses: actions/checkout@v1
-
- - name: Download Previously Built APK
- uses: actions/download-artifact@v2
- with:
- name: uhabits-android
- path: uhabits-android/build/outputs/
-
- - name: Install Linux utils
- run: |
- brew unlink parallel
- brew install util-linux moreutils coreutils
- echo "/usr/local/opt/util-linux/bin" >> $GITHUB_PATH
- echo "/usr/local/opt/moreutils/bin" >> $GITHUB_PATH
- echo "/usr/local/opt/coreutils/libexec/gnubin" >> $GITHUB_PATH
-
- - name: AVD cache
- uses: actions/cache@v3
- id: avd-cache
+ - name: Upload artifacts
+ if: always()
+ uses: actions/upload-artifact@v2
with:
+ name: build
path: |
- ~/.android/avd/*
- ~/.android/adb*
- key: avd-${{ matrix.api }}
-
- - name: Setup AVD
- if: steps.avd-cache.outputs.cache-hit != 'true'
- run: ./build.sh android-setup ${{ matrix.api }}
-
- - name: Run Android Tests
- run: ./build.sh android-tests ${{ matrix.api }}
+ build/*log
+ uhabits-android/build/outputs
diff --git a/build.sh b/build.sh
index 7fd30d33e..5c27503fa 100755
--- a/build.sh
+++ b/build.sh
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
-set -o xtrace
cd "$(dirname "$0")" || exit
ADB="${ANDROID_HOME}/platform-tools/adb"
@@ -99,11 +98,6 @@ android_setup() {
$EMULATOR \
-avd $AVDNAME \
-port 6${API}0 \
- -no-window \
- -gpu swiftshader_indirect \
- -noaudio \
- -no-boot-anim \
- -camera-back none \
1>/dev/null 2>&1 &
log_info "Waiting for emulator to boot..."
@@ -114,16 +108,6 @@ android_setup() {
return 1
fi
- log_info "Disabling animations..."
- $ADB root || return 1
- sleep 5
- $ADB shell settings put global window_animation_scale 0 || return 1
- $ADB shell settings put global transition_animation_scale 0 || return 1
- $ADB shell settings put global animator_duration_scale 0 || return 1
-
- log_info "Acquiring wake lock..."
- $ADB shell 'echo android-test > /sys/power/wake_lock' || return 1
-
log_info "Saving snapshot..."
$ADB emu avd snapshot save fresh-install
}
@@ -154,6 +138,17 @@ android_boot_attempt() {
log_error "Emulator failed to boot after $BOOT_TIMEOUT seconds."
return 1
fi
+
+ log_info "Disabling animations..."
+ $ADB root || return 1
+ sleep 5
+ $ADB shell settings put global window_animation_scale 0 || return 1
+ $ADB shell settings put global transition_animation_scale 0 || return 1
+ $ADB shell settings put global animator_duration_scale 0 || return 1
+
+ log_info "Acquiring wake lock..."
+ $ADB shell 'echo android-test > /sys/power/wake_lock' || return 1
+
}
android_boot() {
@@ -216,6 +211,8 @@ android_test() {
}
android_test_parallel() {
+ # Launch background processes
+ PIDS=""
for API in $*; do
(
LOG=build/android-test-$API.log
@@ -223,12 +220,27 @@ android_test_parallel() {
if android_test $API 1>$LOG 2>&1; then
log_info "API $API: Passed"
else
- log_error "API $API: Failed. See $LOG for more details."
+ log_error "API $API: Failed"
fi
pkill -9 -f ${AVD_PREFIX}${API}
)&
+ PIDS+=" $!"
done
- wait
+
+ # Check exit codes
+ RET_CODE=0
+ for pid in $PIDS; do
+ wait $pid || RET_CODE=1
+ done
+
+ # Print all logs
+ for API in $*; do
+ echo "::group::Android Tests (API $API)"
+ cat build/android-test-$API.log
+ echo "::endgroup::"
+ done
+
+ return $RET_CODE
}
android_build() {
@@ -300,12 +312,14 @@ CI/CD script for Loop Habit Tracker.
Usage:
build.sh build [options]
+ build.sh android-setup
build.sh android-tests [options]
build.sh android-tests-parallel ... [options]
build.sh android-accept-images [options]
Commands:
build Build the app and run small tests
+ android-setup Create Android virtual machine
android-tests Run medium and large Android tests on an emulator
android-tests-parallel Tests multiple API levels simultaneously
android-accept-images Copy fetched images to corresponding assets folder