Skip to content

Commit f275eb3

Browse files
committed
deduplicate device-tests
1 parent 5c549d1 commit f275eb3

File tree

5 files changed

+92
-96
lines changed

5 files changed

+92
-96
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 & 24 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
@@ -70,28 +67,12 @@ jobs:
7067

7168
- name: Run Tests
7269
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"
70+
continue-on-error: true
71+
run: pwsh scripts/device-test.ps1 android -Run
8172

8273
- 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
74+
if: steps.first-run.outcome == 'failure'
75+
run: pwsh scripts/device-test.ps1 android -Run
9576

9677
- name: Upload results
9778
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+
if (!(Get-Command xharness -ErrorAction SilentlyContinue))
25+
{
26+
Push-Location $env:TMPDIR
27+
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" `
28+
--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
29+
Pop-Location
30+
}
31+
32+
$tfm = 'net7.0-'
33+
$arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64'
34+
if ($Platform -eq 'android')
35+
{
36+
$tfm += 'android'
37+
$group = 'android'
38+
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/android-$arch"
39+
$arguments = @(
40+
'--app', "$buildDir/io.sentry.dotnet.maui.device.testapp-Signed.apk",
41+
'--package-name', 'io.sentry.dotnet.maui.device.testapp'
42+
)
43+
}
44+
elseif ($Platform -eq 'ios')
45+
{
46+
$tfm += 'ios'
47+
$group = 'apple'
48+
$buildDir = $CI ? 'bin' : "test/Sentry.Maui.Device.TestApp/bin/Release/$tfm/iossimulator-$arch"
49+
$arguments = @(
50+
'--app', "$buildDir/Sentry.Maui.Device.TestApp.app",
51+
'--target', 'ios-simulator-64',
52+
'--launch-timeout', '00:10:00'
53+
)
54+
}
55+
56+
if ($Build)
57+
{
58+
dotnet build -f $tfm -c Release test/Sentry.Maui.Device.TestApp
59+
if ($LASTEXITCODE -ne 0)
60+
{
61+
throw "Failed to build Sentry.Maui.Device.TestApp"
62+
}
63+
}
64+
65+
if ($Run)
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)