From 104ecd9cf70164cd0e5bbf3555a23681a7f4b77a Mon Sep 17 00:00:00 2001 From: LucasZF Date: Thu, 21 Nov 2024 20:38:35 +0000 Subject: [PATCH] fix broken output case, refactor actions, add case for wrong activity --- .../workflows/android-smoke-test-wrapper.yml | 49 +++++++++++-- .github/workflows/android-smoke-test.yml | 73 +++++++++---------- scripts/smoke-test-android.ps1 | 18 ++++- 3 files changed, 95 insertions(+), 45 deletions(-) diff --git a/.github/workflows/android-smoke-test-wrapper.yml b/.github/workflows/android-smoke-test-wrapper.yml index 0ce48596c..b3d2a04bf 100644 --- a/.github/workflows/android-smoke-test-wrapper.yml +++ b/.github/workflows/android-smoke-test-wrapper.yml @@ -9,6 +9,8 @@ on: type: string jobs: + # needs.try-*.outputs.status == 'failed' => Smoke test failed, no need to retry. + # needs.try-*.result == 'failure' => CI Setup failed. try-1: uses: ./.github/workflows/android-smoke-test.yml with: @@ -16,20 +18,57 @@ jobs: api-level: ${{ inputs.api-level }} try: 1 - try-2: + try-1-check-failed: + runs-on: ubuntu-latest needs: [try-1] - if: ${{ needs.try-1.result == 'failure' }} + if: ${{ needs.try-1.outputs.status != 'success' }} + steps: + - name: Check failed + run: | + if [[ "${{ needs.try-1.outputs.status }}" == "failed" ]]; then + echo "Smoke test failed." + exit 1 + fi + + try-2: + needs: [try-1-check-failed] uses: ./.github/workflows/android-smoke-test.yml with: unity-version: ${{ inputs.unity-version }} api-level: ${{ inputs.api-level }} - try: 2 + try: 2 - try-3: + try-2-check-failed: + runs-on: ubuntu-latest needs: [try-2] - if: ${{ needs.try-2.result == 'failure' }} + if: ${{ needs.try-2.outputs.status != 'success' }} + steps: + - name: Check failed + run: | + if [[ "${{ needs.try-2.outputs.status }}" == "failed" ]]; then + echo "Smoke test failed." + exit 1 + fi + + try-3: + needs: [try-2-check-failed] uses: ./.github/workflows/android-smoke-test.yml with: unity-version: ${{ inputs.unity-version }} api-level: ${{ inputs.api-level }} try: 3 + + try-3-check-status: + runs-on: ubuntu-latest + needs: [try-3] + steps: + - name: Check final result + run: | + if [[ "${{ needs.try-3.outputs.status }}" == "flaky" || "${{ needs.try-3.outputs.status }}" == "crashed" ]]; then + echo "Job status is flaky or crashed. Exiting with code 78." + exit 78 + fi + if [[ "${{ needs.try-2.outputs.status }}" == "failed" ]]; then + echo "Smoke test failed." + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/android-smoke-test.yml b/.github/workflows/android-smoke-test.yml index b512cd41c..beafa9fcf 100644 --- a/.github/workflows/android-smoke-test.yml +++ b/.github/workflows/android-smoke-test.yml @@ -12,9 +12,9 @@ on: type: number # Map the workflow outputs to job outputs outputs: - outcome: - description: - value: ${{ jobs.run.outputs.outcome }} + status: + description: "The outcome status of the smoke test" + value: ${{ jobs.run.outputs.status }} jobs: run: @@ -31,14 +31,8 @@ jobs: outcome: ${{ steps.smoke-test.outcome }} steps: - name: Checkout - uses: actions/checkout@v3 - - - name: Download test app artifact - uses: actions/download-artifact@v4 - with: - name: testapp-Android-compiled-${{ inputs.unity-version }} - path: samples/IntegrationTest/Build - + uses: actions/checkout@v4 + # Not required for MacOS. - name: Enable KVM group perms run: | @@ -46,6 +40,12 @@ jobs: sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm + - name: Download test app artifact + uses: actions/download-artifact@v4 + with: + name: testapp-Android-compiled-${{ inputs.unity-version }} + path: samples/IntegrationTest/Build + # outputs variables: api-level, label, target - name: Configure Android Settings id: config @@ -72,34 +72,11 @@ jobs: "api-level=$apiLevel" >> $env:GITHUB_OUTPUT "label=$($label ?? $apiLevel)" >> $env:GITHUB_OUTPUT - - name: Set up JDK 17 - if: steps.avd-cache.outputs.cache-hit == '2' - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b - with: - java-version: 17 - distribution: 'adopt' - - - name: Setup Android SDK - uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 - - - name: Gradle cache - uses: gradle/actions/setup-gradle@d0a116fff52a680bc1541b7c4c87ca37d30abf00 - - - name: AVD cache - if: steps.avd-cache.outputs.cache-hit == '2' - uses: actions/cache@v4 - id: avd-cache - with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ steps.config.outputs.api-level }} - - - name: create Android Emulator Image - if: steps.avd-cache.outputs.cache-hit != 'true' + - name: create Android Emulator Image uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # pin@v233.0 with: api-level: ${{ steps.config.outputs.api-level }} + target: ${{ steps.config.outputs.target }} force-avd-creation: false emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: false @@ -108,9 +85,31 @@ jobs: adb wait-for-device adb shell input keyevent 82 adb devices -l - gradle connectedAndroidTest --continue echo "Generated AVD snapshot for caching." + + - name: Wait for Emulator to Close + env: + EMULATOR_NAME: emulator-5554 + run: | + Write-Output "Waiting for emulator $env:EMULATOR_NAME to close..." + $retries = 0 + $maxRetries = 60 # Adjust timeout (60 x 5 seconds = 5 minutes) + while ($true) { + $devices = adb devices | Select-String -Pattern $env:EMULATOR_NAME + if (-not $devices) { + Write-Output "Emulator $env:EMULATOR_NAME is offline." + break + } + if ($retries -ge $maxRetries) { + Write-Error "Timeout: Emulator $env:EMULATOR_NAME did not go offline after $(($maxRetries * 5)) seconds." + exit 1 + } + Write-Output "Emulator $env:EMULATOR_NAME is still running. Retrying in 5 seconds... ($retries/$maxRetries)" + Start-Sleep -Seconds 5 + $retries++ + } + - name: Android API ${{ steps.config.outputs.label }} Smoke test uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b # pin@v233.0 id: smoke-test diff --git a/scripts/smoke-test-android.ps1 b/scripts/smoke-test-android.ps1 index 5dccfd0f1..77fed5eb4 100644 --- a/scripts/smoke-test-android.ps1 +++ b/scripts/smoke-test-android.ps1 @@ -61,7 +61,7 @@ else $ApkFileName = "IL2CPP_Player.apk" $ProcessName = "io.sentry.samples.unityofbugs" } -$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerActivity" +$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerGameActivity" $_ArtifactsPath = ((Test-Path env:ARTIFACTS_PATH) ? $env:ARTIFACTS_PATH : "./$BuildDir/../test-artifacts/") ` + $(Get-Date -Format "HHmmss") @@ -77,7 +77,13 @@ function ArtifactsPath if (Test-Path env:CI) { # Take Screenshot of VM to verify emulator start - screencapture "$(ArtifactsPath)/host-screenshot.jpg" + if ($IsMacOS) + { + screencapture "$(ArtifactsPath)/host-screenshot.jpg" + } + else { + Write-Warning "Screenshot functionality is not implemented for this platform." + } } function TakeScreenshot([string] $deviceId) @@ -348,7 +354,13 @@ foreach ($device in $DeviceList) adb -s $device logcat -c } - adb -s $device shell am start -n $TestActivityName -e test $Name + Write-Host "Starting app $TestActivityName" + $output = & adb -s $device shell am start -n $TestActivityName -e test $Name 2>&1 + if ($output -match "Error type 3" -or $output -match "Activity class \{$TestActivityName\} does not exist.") { + ExitNow "failed" "Activity does not exist" + } else { + Write-Host "Activity started successfully." + } #despite calling start, the app might not be started yet. $timedOut = $true