Skip to content

Commit 1179610

Browse files
authored
Chore: deduplicate device tests (#2858)
1 parent 30c8eba commit 1179610

File tree

5 files changed

+92
-100
lines changed

5 files changed

+92
-100
lines changed

.github/workflows/device-tests-android.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ jobs:
3535
- name: Build Native Dependencies
3636
uses: ./.github/actions/buildnative
3737

38-
- name: Restore .NET Dependencies
39-
run: dotnet restore test/Sentry.Maui.Device.TestApp --nologo
40-
4138
- name: Build Android Test App
42-
run: dotnet build test/Sentry.Maui.Device.TestApp -c Release -f net7.0-android --no-restore --nologo
39+
run: pwsh ./scripts/device-test.ps1 android -Build
4340

4441
- name: Upload Android Test App
4542
uses: actions/upload-artifact@v3
@@ -80,10 +77,6 @@ jobs:
8077
name: device-test-android
8178
path: bin
8279

83-
- name: Install XHarness
84-
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
85-
working-directory: ${{ runner.temp }} # Run outside of the project dir so global.json doesn't have an effect.
86-
8780
- name: Setup Gradle
8881
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # pin@v2
8982

@@ -127,12 +120,7 @@ jobs:
127120
disk-size: 4096M
128121
emulator-options: -no-snapshot-save -no-window -accel on -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
129122
disable-animations: false
130-
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
131-
132-
- name: Create Test Report
133-
if: success() || failure()
134-
run: scripts/parse-xunit2-xml.ps1 ./test_output/TestResults.xml | Out-File $env:GITHUB_STEP_SUMMARY
135-
shell: pwsh
123+
script: pwsh scripts/device-test.ps1 android -Run
136124

137125
- name: Upload results
138126
if: success() || failure()

.github/workflows/device-tests-ios.yml

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ jobs:
3232
- name: Setup Environment
3333
uses: ./.github/actions/environment
3434

35-
- name: Restore .NET Dependencies
36-
run: dotnet restore test/Sentry.Maui.Device.TestApp --nologo
37-
3835
- name: Build iOS Test App
39-
run: dotnet build test/Sentry.Maui.Device.TestApp -c Release -f net7.0-ios --no-restore --nologo
36+
run: pwsh ./scripts/device-test.ps1 ios -Build
4037

4138
- name: Upload iOS Test App
4239
uses: actions/upload-artifact@v3
@@ -64,34 +61,14 @@ jobs:
6461
name: device-test-ios
6562
path: bin/Sentry.Maui.Device.TestApp.app
6663

67-
- name: Install XHarness
68-
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
69-
working-directory: ${{ runner.temp }} # Run outside of the project dir so global.json doesn't have an effect.
70-
7164
- name: Run Tests
7265
id: first-run
73-
shell: bash +e {0}
74-
run: >
75-
xharness apple test \
76-
--app=bin/Sentry.Maui.Device.TestApp.app \
77-
--target=ios-simulator-64 \
78-
--launch-timeout=00:10:00 \
79-
--output-directory=./test_output \
80-
; export exitcode=$? ; echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
66+
continue-on-error: true
67+
run: pwsh scripts/device-test.ps1 ios -Run
8168

8269
- name: Retry Tests (if previous failed to run)
83-
if: steps.first-run.outputs.exitcode > 1
84-
run: >
85-
xharness apple test \
86-
--app=bin/Sentry.Maui.Device.TestApp.app \
87-
--target=ios-simulator-64 \
88-
--launch-timeout=00:10:00 \
89-
--output-directory=./test_output
90-
91-
- name: Create Test Report
92-
if: success() || failure()
93-
run: scripts/parse-xunit2-xml.ps1 @(gci ./test_output/*.xml)[0].FullName | Out-File $env:GITHUB_STEP_SUMMARY
94-
shell: pwsh
70+
if: steps.first-run.outcome == 'failure'
71+
run: pwsh scripts/device-test.ps1 ios -Run
9572

9673
- name: Upload results
9774
if: success() || failure()

scripts/device-test.ps1

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
param(
2+
[Parameter(Position = 0, Mandatory = $true)]
3+
[ValidateNotNullOrEmpty()]
4+
[ValidateSet('android', 'ios')] # TODO , 'maccatalyst'
5+
[String] $Platform,
6+
7+
[Switch] $Build,
8+
[Switch] $Run
9+
)
10+
11+
Set-StrictMode -Version latest
12+
$ErrorActionPreference = "Stop"
13+
14+
if (!$Build -and !$Run)
15+
{
16+
$Build = $true
17+
$Run = $true
18+
}
19+
$CI = Test-Path env:CI
20+
21+
Push-Location $PSScriptRoot/..
22+
try
23+
{
24+
$tfm = 'net7.0-'
25+
$arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64'
26+
if ($Platform -eq 'android')
27+
{
28+
$tfm += 'android'
29+
$group = 'android'
30+
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/android-$arch"
31+
$arguments = @(
32+
'--app', "$buildDir/io.sentry.dotnet.maui.device.testapp-Signed.apk",
33+
'--package-name', 'io.sentry.dotnet.maui.device.testapp'
34+
)
35+
}
36+
elseif ($Platform -eq 'ios')
37+
{
38+
$tfm += 'ios'
39+
$group = 'apple'
40+
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/iossimulator-$arch"
41+
$arguments = @(
42+
'--app', "$buildDir/Sentry.Maui.Device.TestApp.app",
43+
'--target', 'ios-simulator-64',
44+
'--launch-timeout', '00:10:00'
45+
)
46+
}
47+
48+
if ($Build)
49+
{
50+
dotnet build -f $tfm -c Release test/Sentry.Maui.Device.TestApp
51+
if ($LASTEXITCODE -ne 0)
52+
{
53+
throw "Failed to build Sentry.Maui.Device.TestApp"
54+
}
55+
}
56+
57+
if ($Run)
58+
{
59+
if (!(Get-Command xharness -ErrorAction SilentlyContinue))
60+
{
61+
Push-Location ($CI ? $env:RUNNER_TEMP : $IsWindows ? $env:TMP : $IsMacos ? $env:TMPDIR : '/temp')
62+
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" `
63+
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
64+
Pop-Location
65+
}
66+
67+
Remove-Item -Recurse -Force test_output -ErrorAction SilentlyContinue
68+
try
69+
{
70+
xharness $group test $arguments --output-directory=test_output
71+
if ($LASTEXITCODE -ne 0)
72+
{
73+
throw "xharness run failed with non-zero exit code"
74+
}
75+
}
76+
finally
77+
{
78+
scripts/parse-xunit2-xml.ps1 ./test_output/TestResults.xml | Out-File $env:GITHUB_STEP_SUMMARY
79+
}
80+
}
81+
}
82+
finally
83+
{
84+
Pop-Location
85+
}

scripts/run-android-tests.ps1

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/run-ios-tests.ps1

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)