Skip to content
Closed
49 changes: 41 additions & 8 deletions .github/workflows/android-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,31 @@ jobs:
max-parallel: 2
matrix:
include:
- backend: "tflite"
device: "Samsung Galaxy M32-11.0"
- backend: "pixel"
device: "Google Pixel 9 Pro-15.0"
- backend: "qti"
device: "Samsung Galaxy S25 Ultra-15.0"
- backend: "samsung"
device: "Samsung Galaxy S24-14.0"
- device: "Samsung Galaxy S25 Ultra-15.0"
- device: "Samsung Galaxy S25-15.0"
- device: "Samsung Galaxy Tab S10 Plus-15.0"
- device: "Samsung Galaxy S24 Ultra-14.0"
- device: "Samsung Galaxy S24-14.0"
- device: "Samsung Galaxy Tab A9 Plus-14.0"
- device: "Samsung Galaxy S23 Ultra-13.0"
- device: "Samsung Galaxy S23-13.0"
- device: "Samsung Galaxy Tab S9-13.0"
- device: "Samsung Galaxy S22 Ultra-12.0"
- device: "Samsung Galaxy S22 Plus-12.0"
- device: "Samsung Galaxy S22-12.0"
- device: "Samsung Galaxy S21-12.0"
- device: "Samsung Galaxy Tab S8-12.0"
- device: "Samsung Galaxy S21 Ultra-11.0"
- device: "Samsung Galaxy S21-11.0"
- device: "Samsung Galaxy S21 Plus-11.0"
- device: "Samsung Galaxy M52-11.0"
- device: "Samsung Galaxy M32-11.0"
- device: "Samsung Galaxy A52-11.0"
- device: "Samsung Galaxy Tab S7-11.0"
env:
MAIN_APK_NAME: test-main-unified-${{ github.run_number }}.apk
HELPER_APK_NAME: test-helper-unified-${{ github.run_number }}.apk
BROWSERSTACK_LOGS_DIR: /tmp/browserstack-device-logs
steps:
- uses: actions/checkout@v4
- name: Set up authentication for Google Cloud SDK
Expand Down Expand Up @@ -310,6 +324,7 @@ jobs:
BROWSERSTACK_APP: ${{ env.MAIN_APK_NAME }}
BROWSERSTACK_TEST_SUITE: ${{ env.HELPER_APK_NAME }}
BROWSERSTACK_BUILD_TAG: ${{ github.run_number }}
BROWSERSTACK_LOGS_DIR: ${{ env.BROWSERSTACK_LOGS_DIR }}
BROWSERSTACK_DEVICES: >-
["${{ matrix.device }}"]
with:
Expand All @@ -319,6 +334,14 @@ jobs:
retry_on_exit_code: 9
command: |
bash .github/workflows/scripts/browserstack-app-automate.sh
- name: Upload BrowserStack logs
uses: actions/upload-artifact@v4
if: always()
with:
name: logs-${{ matrix.backend }}-${{ matrix.device }}-${{ github.run_number }}
path: ${{ env.BROWSERSTACK_LOGS_DIR }}
retention-days: 28
if-no-files-found: error

test-android-apk-unified-mtk:
needs: build-android-apk
Expand Down Expand Up @@ -368,6 +391,7 @@ jobs:
env:
MAIN_APK_NAME: test-main-${{ matrix.backend }}-${{ github.run_number }}.apk
HELPER_APK_NAME: test-helper-${{ matrix.backend }}-${{ github.run_number }}.apk
BROWSERSTACK_LOGS_DIR: /tmp/browserstack-device-logs
steps:
- uses: actions/checkout@v4
- name: Set up authentication for Google Cloud SDK
Expand Down Expand Up @@ -402,6 +426,7 @@ jobs:
BROWSERSTACK_APP: ${{ env.MAIN_APK_NAME }}
BROWSERSTACK_TEST_SUITE: ${{ env.HELPER_APK_NAME }}
BROWSERSTACK_BUILD_TAG: ${{ github.run_number }}
BROWSERSTACK_LOGS_DIR: ${{ env.BROWSERSTACK_LOGS_DIR }}
BROWSERSTACK_DEVICES: >-
["${{ matrix.device }}"]
with:
Expand All @@ -411,6 +436,14 @@ jobs:
retry_on_exit_code: 9
command: |
bash .github/workflows/scripts/browserstack-app-automate.sh
- name: Upload BrowserStack logs
uses: actions/upload-artifact@v4
if: always()
with:
name: logs-${{ matrix.backend }}-${{ matrix.device }}-${{ github.run_number }}
path: ${{ env.BROWSERSTACK_LOGS_DIR }}
retention-days: 28
if-no-files-found: error

deploy-playstore:
needs:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/scripts/browserstack-app-automate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RETRY_INTERVAL=10
TRIGGER_URL="https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/build"
STATUS_URL="https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/builds"
DEVICES_URL="https://api-cloud.browserstack.com/app-automate/devices"
BUILDS_URL="https://api.browserstack.com/app-automate/flutter-integration-tests/builds"

# Retrieve vars from environment variables
CREDENTIALS="${BROWSERSTACK_CREDENTIALS:-}"
Expand All @@ -18,6 +19,7 @@ APP="${BROWSERSTACK_APP:-}"
TEST_SUITE="${BROWSERSTACK_TEST_SUITE:-}"
BUILD_TAG="${BROWSERSTACK_BUILD_TAG:-}"
DEVICES="${BROWSERSTACK_DEVICES:-}"
LOGS_DIR="${BROWSERSTACK_LOGS_DIR:-}"

# Validate required environment variables
if [[ -z "$CREDENTIALS" ]]; then
Expand Down Expand Up @@ -69,6 +71,42 @@ trigger_build() {
fi
}

# Function to download device logs
download_device_logs() {
local build_id=$1
local session_id=$2

echo "Downloading device logs for build $build_id, session $session_id"

# Create logs directory if it doesn't exist
mkdir -p "$LOGS_DIR"

# Get the status of the session
local response=$(curl -s -u "$CREDENTIALS" -X GET "$STATUS_URL/$build_id/sessions/$session_id")

echo "Extracting last test case information from session response..."

# Use jq to extract the last test case with its ID and device log URL
local last_testcase=$(echo "$response" | jq -c '.testcases.data[].testcases | .[-1]')
local test_id=$(echo "$last_testcase" | jq -r '.id')
local device_log_url=$(echo "$last_testcase" | jq -r '.device_log')

if [[ -n "$test_id" && "$test_id" != "null" && -n "$device_log_url" && "$device_log_url" != "null" ]]; then
echo "Found last test case $test_id with device log URL"

# Download device logs using the extracted URL
local log_file="$LOGS_DIR/${test_id}.log"
echo "Downloading device log to $log_file"
curl -s -u "$CREDENTIALS" -X GET "$device_log_url" -o "$log_file"

if [ -f "$log_file" ]; then
echo "Device logs downloaded successfully to $log_file"
else
echo "Failed to download device logs for test case $test_id"
fi
fi
}

# Function to check build status
check_build_status() {
local build_id=$1
Expand All @@ -90,6 +128,18 @@ check_build_status() {
'
fi

# Download device logs for all sessions if build is not running
if [[ "$status" != "running" ]]; then
sleep 5
echo "Downloading device logs for all sessions..."
# Extract session IDs and download logs for each session
echo "$response" | jq -r '.devices[] | .sessions[] | .id' | while read -r session_id; do
if [[ -n "$session_id" ]]; then
download_device_logs "$build_id" "$session_id"
fi
done
fi

# Display build status
if [[ "$status" == "passed" ]]; then
echo "Build completed successfully!"
Expand Down
Loading