Skip to content

Commit

Permalink
deduplicate device-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Nov 18, 2023
1 parent 5c549d1 commit f275eb3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 96 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/device-tests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ jobs:
- name: Build Native Dependencies
uses: ./.github/actions/buildnative

- name: Restore .NET Dependencies
run: dotnet restore test/Sentry.Maui.Device.TestApp --nologo

- name: Build Android Test App
run: dotnet build test/Sentry.Maui.Device.TestApp -c Release -f net7.0-android --no-restore --nologo
run: pwsh ./scripts/device-test.ps1 android -Build

- name: Upload Android Test App
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -80,10 +77,6 @@ jobs:
name: device-test-android
path: bin

- name: Install XHarness
run: dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
working-directory: ${{ runner.temp }} # Run outside of the project dir so global.json doesn't have an effect.

- name: Setup Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # pin@v2

Expand Down Expand Up @@ -127,12 +120,7 @@ jobs:
disk-size: 4096M
emulator-options: -no-snapshot-save -no-window -accel on -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: xharness android test --output-directory=./test_output --app=bin/io.sentry.dotnet.maui.device.testapp-Signed.apk --package-name=io.sentry.dotnet.maui.device.testapp

- name: Create Test Report
if: success() || failure()
run: scripts/parse-xunit2-xml.ps1 ./test_output/TestResults.xml | Out-File $env:GITHUB_STEP_SUMMARY
shell: pwsh
script: pwsh scripts/device-test.ps1 android -Run

- name: Upload results
if: success() || failure()
Expand Down
29 changes: 5 additions & 24 deletions .github/workflows/device-tests-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/environment

- name: Restore .NET Dependencies
run: dotnet restore test/Sentry.Maui.Device.TestApp --nologo

- name: Build iOS Test App
run: dotnet build test/Sentry.Maui.Device.TestApp -c Release -f net7.0-ios --no-restore --nologo
run: pwsh ./scripts/device-test.ps1 ios -Build

- name: Upload iOS Test App
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -70,28 +67,12 @@ jobs:

- name: Run Tests
id: first-run
shell: bash +e {0}
run: >
xharness apple test \
--app=bin/Sentry.Maui.Device.TestApp.app \
--target=ios-simulator-64 \
--launch-timeout=00:10:00 \
--output-directory=./test_output \
; export exitcode=$? ; echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
continue-on-error: true
run: pwsh scripts/device-test.ps1 android -Run

- name: Retry Tests (if previous failed to run)
if: steps.first-run.outputs.exitcode > 1
run: >
xharness apple test \
--app=bin/Sentry.Maui.Device.TestApp.app \
--target=ios-simulator-64 \
--launch-timeout=00:10:00 \
--output-directory=./test_output
- name: Create Test Report
if: success() || failure()
run: scripts/parse-xunit2-xml.ps1 @(gci ./test_output/*.xml)[0].FullName | Out-File $env:GITHUB_STEP_SUMMARY
shell: pwsh
if: steps.first-run.outcome == 'failure'
run: pwsh scripts/device-test.ps1 android -Run

- name: Upload results
if: success() || failure()
Expand Down
85 changes: 85 additions & 0 deletions scripts/device-test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
param(
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateSet('android', 'ios')] # TODO , 'maccatalyst'
[String] $Platform,

[Switch] $Build,
[Switch] $Run
)

Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"

if (!$Build -and !$Run)
{
$Build = $true
$Run = $true
}
$CI = Test-Path env:CI

Push-Location $PSScriptRoot/..
try
{
if (!(Get-Command xharness -ErrorAction SilentlyContinue))
{
Push-Location $env:TMPDIR
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" `
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
Pop-Location
}

$tfm = 'net7.0-'
$arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64'
if ($Platform -eq 'android')
{
$tfm += 'android'
$group = 'android'
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/android-$arch"
$arguments = @(
'--app', "$buildDir/io.sentry.dotnet.maui.device.testapp-Signed.apk",
'--package-name', 'io.sentry.dotnet.maui.device.testapp'
)
}
elseif ($Platform -eq 'ios')
{
$tfm += 'ios'
$group = 'apple'
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/iossimulator-$arch"
$arguments = @(
'--app', "$buildDir/Sentry.Maui.Device.TestApp.app",
'--target', 'ios-simulator-64',
'--launch-timeout', '00:10:00'
)
}

if ($Build)
{
dotnet build -f $tfm -c Release test/Sentry.Maui.Device.TestApp
if ($LASTEXITCODE -ne 0)
{
throw "Failed to build Sentry.Maui.Device.TestApp"
}
}

if ($Run)
{
Remove-Item -Recurse -Force test_output -ErrorAction SilentlyContinue
try
{
xharness $group test $arguments --output-directory=test_output
if ($LASTEXITCODE -ne 0)
{
throw "xharness run failed with non-zero exit code"
}
}
finally
{
scripts/parse-xunit2-xml.ps1 ./test_output/TestResults.xml | Out-File $env:GITHUB_STEP_SUMMARY
}
}
}
finally
{
Pop-Location
}
29 changes: 0 additions & 29 deletions scripts/run-android-tests.ps1

This file was deleted.

29 changes: 0 additions & 29 deletions scripts/run-ios-tests.ps1

This file was deleted.

0 comments on commit f275eb3

Please sign in to comment.