Skip to content

Add compose test step to CI #10

Add compose test step to CI

Add compose test step to CI #10

Workflow file for this run

name: UI Tests
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
ui-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
- name: Cache gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Decode google-services.json
run: echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > app/google-services.json
env:
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
- name: Make gradlew executable
run: chmod +x gradlew
- name: Build for debug with gradle
run: ./gradlew assembleDebug assembleAndroidTest
- name: Check Docker version
run: |
docker --version
docker ps
- name: Start Docker Android Container
run: |
# Pull the Android emulator image
docker pull budtmo/docker-android:emulator_13.0_v2.16.2-p0
# Run the container
docker run -d --name android-container \
-p 4723:4723 -p 6080:6080 -p 5554:5554 -p 5555:5555 \
--privileged \
budtmo/docker-android:emulator_13.0_v2.16.2-p0
# Wait for container to fully initialize
echo "Waiting for Android container to initialize..."
sleep 90
# Check container status
docker ps
docker logs android-container --tail 50
- name: Install Android tools
run: |
sudo apt-get update
sudo apt-get install -y android-tools-adb
adb version
- name: Set up ADB and connect to device
run: |
adb start-server
# Get container IP
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' android-container)
echo "Container IP: $CONTAINER_IP"
# Connect to the emulator
adb connect $CONTAINER_IP:5555
# Wait for device to be fully booted
echo "Waiting for device to fully boot..."
sleep 30
# Check connected devices
adb devices -l
# Disable animations
adb shell settings put global window_animation_scale 0.0 || echo "Could not disable window animations"
adb shell settings put global transition_animation_scale 0.0 || echo "Could not disable transition animations"
adb shell settings put global animator_duration_scale 0.0 || echo "Could not disable animator duration"
- name: Run UI Tests
run: |
# Check if device is connected
DEVICE_COUNT=$(adb devices | grep -c device)
if [ $DEVICE_COUNT -le 1 ]; then
echo "No devices connected. Trying to reconnect..."
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' android-container)
adb connect $CONTAINER_IP:5555
sleep 10
adb devices -l
fi
# Install app
./gradlew installDebug
# Run tests
./gradlew connectedDebugAndroidTest
- name: Cleanup Docker Container
if: always()
run: |
adb kill-server
docker stop android-container
docker rm android-container
- name: Upload UI test report
if: always()
uses: actions/upload-artifact@v4
with:
name: compose_test_report
path: |
app/build/reports/androidTests/connected/
app/build/outputs/androidTest-results/connected/