From f275eb35d72168e5493336dfbfa485f4ad8759db Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Sat, 18 Nov 2023 13:53:24 +0100 Subject: [PATCH] deduplicate device-tests --- .github/workflows/device-tests-android.yml | 16 +--- .github/workflows/device-tests-ios.yml | 29 ++------ scripts/device-test.ps1 | 85 ++++++++++++++++++++++ scripts/run-android-tests.ps1 | 29 -------- scripts/run-ios-tests.ps1 | 29 -------- 5 files changed, 92 insertions(+), 96 deletions(-) create mode 100644 scripts/device-test.ps1 delete mode 100644 scripts/run-android-tests.ps1 delete mode 100644 scripts/run-ios-tests.ps1 diff --git a/.github/workflows/device-tests-android.yml b/.github/workflows/device-tests-android.yml index 9afdf246e8..a1f2392897 100644 --- a/.github/workflows/device-tests-android.yml +++ b/.github/workflows/device-tests-android.yml @@ -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 @@ -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 @@ -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() diff --git a/.github/workflows/device-tests-ios.yml b/.github/workflows/device-tests-ios.yml index ce5faa5649..c1fa30521e 100644 --- a/.github/workflows/device-tests-ios.yml +++ b/.github/workflows/device-tests-ios.yml @@ -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 @@ -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() diff --git a/scripts/device-test.ps1 b/scripts/device-test.ps1 new file mode 100644 index 0000000000..a885028988 --- /dev/null +++ b/scripts/device-test.ps1 @@ -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 +} diff --git a/scripts/run-android-tests.ps1 b/scripts/run-android-tests.ps1 deleted file mode 100644 index c23b878efd..0000000000 --- a/scripts/run-android-tests.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -Push-Location $PSScriptRoot/.. -try -{ - if (!(Get-Command xharness -ErrorAction SilentlyContinue)) - { - dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" - } - - $tfm = 'net7.0-android' - dotnet build -f $tfm test/Sentry.Maui.Device.TestApp - if ($LASTEXITCODE -ne 0) - { - throw "Failed to build Sentry.Maui.Device.TestApp" - } - - $arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64' - Remove-Item -Recurse -Force test_output -ErrorAction SilentlyContinue - xharness android test ` - --app=test/Sentry.Maui.Device.TestApp/bin/Debug/$tfm/android-$arch/io.sentry.dotnet.maui.device.testapp-Signed.apk ` - --package-name=io.sentry.dotnet.maui.device.testapp ` - --output-directory=test_output -} -finally -{ - Pop-Location -} diff --git a/scripts/run-ios-tests.ps1 b/scripts/run-ios-tests.ps1 deleted file mode 100644 index 7c447ab944..0000000000 --- a/scripts/run-ios-tests.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = "Stop" - -Push-Location $PSScriptRoot/.. -try -{ - if (!(Get-Command xharness -ErrorAction SilentlyContinue)) - { - dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*" - } - - $tfm = 'net7.0-ios' - dotnet build -f $tfm test/Sentry.Maui.Device.TestApp - if ($LASTEXITCODE -ne 0) - { - throw "Failed to build Sentry.Maui.Device.TestApp" - } - - $arch = $(uname -m) -eq 'arm64' ? 'arm64' : 'x64' - Remove-Item -Recurse -Force test_output -ErrorAction SilentlyContinue - xharness apple test ` - --app=test/Sentry.Maui.Device.TestApp/bin/Debug/$tfm/iossimulator-$arch/Sentry.Maui.Device.TestApp.app ` - --target=ios-simulator-64 ` - --output-directory=test_output -} -finally -{ - Pop-Location -}