Skip to content

Commit

Permalink
fix broken output case, refactor actions, add case for wrong activity
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman authored Nov 21, 2024
1 parent 6df3fb7 commit 104ecd9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 45 deletions.
49 changes: 44 additions & 5 deletions .github/workflows/android-smoke-test-wrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,66 @@ 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:
unity-version: ${{ inputs.unity-version }}
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
73 changes: 36 additions & 37 deletions .github/workflows/android-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,21 +31,21 @@ 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: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
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
Expand All @@ -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 # [email protected]
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
Expand All @@ -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 # [email protected]
id: smoke-test
Expand Down
18 changes: 15 additions & 3 deletions scripts/smoke-test-android.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 104ecd9

Please sign in to comment.