From 50870def0339433bde02cbdc27f6d86ba052e717 Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Thu, 1 Sep 2022 18:03:39 +0200 Subject: [PATCH] Maui Windows on CI --- .github/templates/main.yml | 4 +- .github/templates/pr.yml | 2 +- .github/templates/test-net-core.yml | 2 +- .github/templates/test-uwp-managed.yml | 27 ---- .github/templates/test-windows.yml | 58 ++++++++ .github/templates/test.lib.yml | 9 +- .github/workflows/main.yml | 6 +- .github/workflows/pr.yml | 8 +- .github/workflows/test-net-core.yml | 2 +- .github/workflows/test-unity.yml | 1 + .github/workflows/test-uwp-managed.yml | 77 ---------- .github/workflows/test-windows.yml | 136 ++++++++++++++++++ Tests/Tests.Maui/MainPage.xaml.cs | 54 ++++--- Tests/Tests.Maui/MauiProgram.cs | 6 + .../Tests.Maui/Platforms/Windows/App.xaml.cs | 5 +- .../Platforms/Windows/Package.appxmanifest | 18 ++- Tests/Tests.Maui/Tests.Maui.csproj | 12 +- 17 files changed, 275 insertions(+), 152 deletions(-) delete mode 100644 .github/templates/test-uwp-managed.yml create mode 100644 .github/templates/test-windows.yml delete mode 100755 .github/workflows/test-uwp-managed.yml create mode 100755 .github/workflows/test-windows.yml diff --git a/.github/templates/main.yml b/.github/templates/main.yml index de0654273c..5fd79db54f 100644 --- a/.github/templates/main.yml +++ b/.github/templates/main.yml @@ -53,7 +53,7 @@ jobs: - #@ template.replace(uploadPackagesToSleet("needs.build-packages.outputs.package_version", True)) _: #@ template.replace(buildUnity()) _: #@ template.replace(runTests(".NET Framework")) - _: #@ template.replace(runTests("UWP Managed", additionalSecrets = ["Pfx_Password", "Base64_Encoded_Pfx"])) + _: #@ template.replace(runTests("Windows", additionalSecrets = ["Pfx_Password", "Base64_Encoded_Pfx"])) _: #@ template.replace(runNetCoreTests("[\"netcoreapp3.1\", \"net6.0\"]")) _: #@ template.replace(runTests("macOS")) _: #@ template.replace(runTests("iOS")) @@ -87,7 +87,7 @@ jobs: - #@ template.replace(checkoutCode()) - #@ template.replace(fetchPackageArtifacts()) - #@ setupDotnet() - - #@ template.replace(dotnetBuildTests("Tests/Benchmarks/PerformanceTests", "net6.0", "linux-x64", "needs.build-packages.outputs.package_version")) + - #@ template.replace(dotnetBuildTests("Tests/Benchmarks/PerformanceTests", "net6.0", "linux-x64", "needs.build-packages.outputs.package_version", RealmTestsStandaloneExe="true")) - name: Run the tests run: #@ "${{ steps.dotnet-publish.outputs.executable-path }}/PerformanceTests -f \"*\" --join" - name: Find Results file diff --git a/.github/templates/pr.yml b/.github/templates/pr.yml index 59875f90f7..ea1137e3c9 100644 --- a/.github/templates/pr.yml +++ b/.github/templates/pr.yml @@ -35,7 +35,7 @@ jobs: _: #@ template.replace(buildUnity()) _: #@ template.replace(testUnity('["Mono-Net4"]', '[{ "os": "windows", "testPlatform": "Windows64" }, { "os": "linux", "testPlatform": "Linux64" }]')) _: #@ template.replace(runTests(".NET Framework", runSyncTests = False)) - _: #@ template.replace(runTests("UWP Managed", runSyncTests = False, additionalSecrets = ["Pfx_Password", "Base64_Encoded_Pfx"])) + _: #@ template.replace(runTests("Windows", runSyncTests = False)) _: #@ template.replace(runNetCoreTests('["net6.0"]')) _: #@ template.replace(runTests("macOS", runSyncTests = False)) _: #@ template.replace(runTests("iOS", runSyncTests = False)) diff --git a/.github/templates/test-net-core.yml b/.github/templates/test-net-core.yml index 6743ddba4d..bfb3ef915e 100644 --- a/.github/templates/test-net-core.yml +++ b/.github/templates/test-net-core.yml @@ -34,7 +34,7 @@ jobs: run: git clean -fdx - #@ setupDotnet(ifCondition = "matrix.framework == 'net6.0' && matrix.os.runner != 'macos-arm'") - #@ template.replace(fetchPackageArtifacts()) - - #@ template.replace(dotnetBuildTests("Tests/Realm.Tests", "${{ matrix.framework }}", "${{ matrix.os.runtime }}")) + - #@ template.replace(dotnetBuildTests("Tests/Realm.Tests", "${{ matrix.framework }}", "${{ matrix.os.runtime }}", RealmTestsStandaloneExe="true")) - name: Run the tests run: #@ "${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests --result=TestResults.xml --labels=After" + baasTestArgs("net-core-${{ matrix.runner }}-${{ matrix.runtime }}") - #@ publishTestsResults("TestResults.xml", ".NET (${{ matrix.os.runner }}, ${{ matrix.framework }})") diff --git a/.github/templates/test-uwp-managed.yml b/.github/templates/test-uwp-managed.yml deleted file mode 100644 index b8a6c7bbf1..0000000000 --- a/.github/templates/test-uwp-managed.yml +++ /dev/null @@ -1,27 +0,0 @@ -#@ load("@ytt:template", "template") -#@ load("common.lib.yml", "checkoutCode") -#@ load("test.lib.yml", "fetchPackageArtifacts", "baasTestArgs", "publishTestsResults", "testDefinition", "buildTests") - ---- -name: test-uwp-managed -_: #@ template.replace(testDefinition(["Base64_Encoded_Pfx", "Pfx_Password"])) -jobs: - run-tests: - runs-on: windows-2019 - name: UWP - timeout-minutes: 45 - steps: - - #@ template.replace(checkoutCode()) - - #@ template.replace(fetchPackageArtifacts()) - - name: Import test certificate - run: | - $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}") - $currentDirectory = Get-Location - [IO.File]::WriteAllBytes("${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx", $pfx_cert_byte) - certutil -f -p "${{ secrets.Pfx_Password }}" -importpfx my ${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx - shell: powershell - - #@ template.replace(buildTests("Tests/Tests.UWP", AppxBundle="Always", PackageCertificateKeyFile="${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx", PackageCertificatePassword='"${{ secrets.Pfx_Password }}"', UseDotNetNativeToolchain="false", AppxBundlePlatforms="x64")) - - name: Run the tests - run: #@ "./Tests/Tests.UWP/RunTests.ps1 -ExtraAppArgs '" + baasTestArgs("uwp-managed") + "'" - shell: powershell - - #@ publishTestsResults("${{ env.TEST_RESULTS }}", "UWP Managed") diff --git a/.github/templates/test-windows.yml b/.github/templates/test-windows.yml new file mode 100644 index 0000000000..6122fa86c2 --- /dev/null +++ b/.github/templates/test-windows.yml @@ -0,0 +1,58 @@ +#@ load("@ytt:template", "template") +#@ load("common.lib.yml", "checkoutCode", "setupDotnet") +#@ load("test.lib.yml", "fetchPackageArtifacts", "baasTestArgs", "publishTestsResults", "testDefinition", "buildTests", "dotnetBuildTests") + +#@ def importPfx(id): +name: Import test certificate +id: #@ id +#@yaml/text-templated-strings +run: | + $cert = New-SelfSignedCertificate -Type Custom -Subject "CN=RealmTests" -KeyUsage DigitalSignature -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") + echo "::set-output name=thumbprint::$($cert.Thumbprint)" +shell: powershell +#@ end + +--- +name: test-windows +_: #@ template.replace(testDefinition()) +jobs: + test-uwp: + runs-on: windows-2019 + name: UWP + timeout-minutes: 45 + steps: + - #@ template.replace(checkoutCode()) + - #@ template.replace(fetchPackageArtifacts()) + - #@ importPfx("import-pfx") + - #@ template.replace(buildTests("Tests/Tests.UWP", AppxBundle="Always", PackageCertificateThumbprint="${{ steps.import-pfx.outputs.thumbprint }}", UseDotNetNativeToolchain="false", AppxBundlePlatforms="x64")) + - name: Run the tests + run: #@ "./Tests/Tests.UWP/RunTests.ps1 -ExtraAppArgs '" + baasTestArgs("uwp-managed") + "'" + shell: powershell + - #@ publishTestsResults("${{ env.TEST_RESULTS }}", "UWP Managed") + test-maui: + runs-on: windows-2019 + name: Maui.Windows + timeout-minutes: 45 + steps: + - #@ template.replace(checkoutCode()) + - #@ template.replace(fetchPackageArtifacts()) + - #@ setupDotnet() + - run: dotnet workload install maui + - #@ importPfx("import-pfx") + - #@ template.replace(dotnetBuildTests("Tests/Tests.Maui", "net6.0-windows10.0.19041", "win10-x64", GenerateAppxPackageOnBuild="true", PackageCertificateThumbprint="${{ steps.import-pfx.outputs.thumbprint }}", AppxPackageTestDir="Output/")) + - name: Run the tests + #@yaml/text-templated-strings + run: | + .\Tests\Tests.Maui\Output\Install.ps1 -Force + # Tests.Maui --headless --labels=After --result=TestResults.Windows.xml (@= baasTestArgs('Maui.Windows') @) + + $package = Get-AppxPackage -Name realm.maui.tests + Start-Process "shell:AppsFolder\$($package.PackageFamilyName)!App" -ArgumentList "--headless --labels=After --result=$(pwd)\TestResults.Windows.xml --output=$(pwd)\test.log (@= baasTestArgs('Maui.Windows') @)" + Start-Sleep 5 + echo "Waiting for tests to finish" + $(Get-Process Tests.Maui).WaitForExit(90000) + Get-Content args.txt + Get-Content test.log + shell: powershell + - #@ publishTestsResults("TestResults.Windows.xml", "Maui.Windows") + diff --git a/.github/templates/test.lib.yml b/.github/templates/test.lib.yml index 32e977a606..dc9540b38a 100644 --- a/.github/templates/test.lib.yml +++ b/.github/templates/test.lib.yml @@ -67,11 +67,10 @@ env: #@ return msbuild(projectPath, RestoreConfigFile="Tests/Test.NuGet.Config", UseRealmNupkgsWithVersion="${{ inputs.version }}", **properties) #@ end -#@ def dotnetBuildTests(projectPath, framework, runtime, version = "inputs.version"): -#@ properties = { +#@ def dotnetBuildTests(projectPath, framework, runtime, version = "inputs.version", **properties): +#@ properties.update({ #@ "RestoreConfigFile": "Tests/Test.NuGet.Config", -#@ "UseRealmNupkgsWithVersion": "${{ " + version + " }}", -#@ "RealmTestsStandaloneExe": "true" -#@ } +#@ "UseRealmNupkgsWithVersion": "${{ " + version + " }}" +#@ }) #@ return dotnetPublish(projectPath, framework, runtime, properties) #@ end \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8343822e8b..91833603e5 100755 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -96,8 +96,8 @@ jobs: BaseUrl: ${{ secrets.REALM_QA_BASE_URL }} AtlasPublicKey: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }} AtlasPrivateKey: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }} - test-uwp-managed: - uses: ./.github/workflows/test-uwp-managed.yml + test-windows: + uses: ./.github/workflows/test-windows.yml name: Test if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') needs: @@ -260,7 +260,7 @@ jobs: with: dotnet-version: 6.0.x - name: Publish Tests/Benchmarks/PerformanceTests - run: dotnet publish Tests/Benchmarks/PerformanceTests -c Release -f net6.0 -r linux-x64 -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} -p:RealmTestsStandaloneExe=true --no-self-contained + run: dotnet publish Tests/Benchmarks/PerformanceTests -c Release -f net6.0 -r linux-x64 -p:RealmTestsStandaloneExe=true -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} --no-self-contained - name: Output executable path id: dotnet-publish run: echo '::set-output name=executable-path::./Tests/Benchmarks/PerformanceTests/bin/Release/net6.0/linux-x64' diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 52b5753819..99101ad966 100755 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -67,8 +67,8 @@ jobs: version: ${{ needs.build-packages.outputs.package_version }} clusterName: ${{ needs.deploy-cluster.outputs.clusterName }} secrets: {} - test-uwp-managed: - uses: ./.github/workflows/test-uwp-managed.yml + test-windows: + uses: ./.github/workflows/test-windows.yml name: Test if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') needs: @@ -76,9 +76,7 @@ jobs: with: version: ${{ needs.build-packages.outputs.package_version }} clusterName: ${{ needs.deploy-cluster.outputs.clusterName }} - secrets: - Pfx_Password: ${{ secrets.Pfx_Password }} - Base64_Encoded_Pfx: ${{ secrets.Base64_Encoded_Pfx }} + secrets: {} test-net-core: if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') name: Test diff --git a/.github/workflows/test-net-core.yml b/.github/workflows/test-net-core.yml index f99514bc02..0cfec2826d 100755 --- a/.github/workflows/test-net-core.yml +++ b/.github/workflows/test-net-core.yml @@ -74,7 +74,7 @@ jobs: name: Realm.Fody.${{ inputs.version }} path: ${{ github.workspace }}/Realm/packages/ - name: Publish Tests/Realm.Tests - run: dotnet publish Tests/Realm.Tests -c Release -f ${{ matrix.framework }} -r ${{ matrix.os.runtime }} -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:RealmTestsStandaloneExe=true --no-self-contained + run: dotnet publish Tests/Realm.Tests -c Release -f ${{ matrix.framework }} -r ${{ matrix.os.runtime }} -p:RealmTestsStandaloneExe=true -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} --no-self-contained - name: Output executable path id: dotnet-publish run: echo '::set-output name=executable-path::./Tests/Realm.Tests/bin/Release/${{ matrix.framework }}/${{ matrix.os.runtime }}' diff --git a/.github/workflows/test-unity.yml b/.github/workflows/test-unity.yml index f2ca7899de..d3c06f5793 100755 --- a/.github/workflows/test-unity.yml +++ b/.github/workflows/test-unity.yml @@ -57,6 +57,7 @@ jobs: name: UnityTestsRunner.${{ matrix.platform.os }} path: ${{ github.workspace }}/Tests/Tests.Unity/Player_Standalone${{ matrix.platform.testPlatform }}_${{ matrix.settings }}/ retention-days: ${{ github.event_name != 'pull_request' && 30 || 1 }} + if-no-files-found: error run-tests-linux: runs-on: ubuntu-latest name: Unity Linux diff --git a/.github/workflows/test-uwp-managed.yml b/.github/workflows/test-uwp-managed.yml deleted file mode 100755 index 64c56c3488..0000000000 --- a/.github/workflows/test-uwp-managed.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: test-uwp-managed -"on": - workflow_call: - inputs: - version: - required: true - type: string - clusterName: - required: false - type: string - secrets: - AtlasProjectId: - required: false - BaseUrl: - required: false - AtlasPublicKey: - required: false - AtlasPrivateKey: - required: false - Base64_Encoded_Pfx: - required: true - Pfx_Password: - required: true -env: - REALM_DISABLE_ANALYTICS: true - DOTNET_NOLOGO: true -jobs: - run-tests: - runs-on: windows-2019 - name: UWP - timeout-minutes: 45 - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - submodules: false - ref: ${{ github.event.pull_request.head.sha }} - - name: Register csc problem matcher - run: echo "::add-matcher::.github/problem-matchers/csc.json" - - name: Register msvc problem matcher - run: echo "::add-matcher::.github/problem-matchers/msvc.json" - - name: Fetch Realm - uses: actions/download-artifact@v2 - with: - name: Realm.${{ inputs.version }} - path: ${{ github.workspace }}/Realm/packages/ - - name: Fetch Realm.Fody - uses: actions/download-artifact@v2 - with: - name: Realm.Fody.${{ inputs.version }} - path: ${{ github.workspace }}/Realm/packages/ - - name: Import test certificate - run: | - $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}") - $currentDirectory = Get-Location - [IO.File]::WriteAllBytes("${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx", $pfx_cert_byte) - certutil -f -p "${{ secrets.Pfx_Password }}" -importpfx my ${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx - shell: powershell - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.2 - if: ${{ runner.os == 'Windows' }} - - name: Build Tests/Tests.UWP - run: msbuild Tests/Tests.UWP -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:AppxBundle=Always -p:PackageCertificateKeyFile=${{ github.workspace }}\Tests\Tests.UWP\Tests.UWP_TemporaryKey.pfx -p:PackageCertificatePassword="${{ secrets.Pfx_Password }}" -p:UseDotNetNativeToolchain=false -p:AppxBundlePlatforms=x64 - - name: Run the tests - run: ./Tests/Tests.UWP/RunTests.ps1 -ExtraAppArgs ' --baasurl=${{ secrets.BaseUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=uwp-managed' - shell: powershell - - name: Publish Unit Test Results - uses: LaPeste/test-reporter@b8a650f4490e7472b930f56bbb92c7b42dc5db15 - if: always() - with: - name: Results UWP Managed - path: ${{ env.TEST_RESULTS }} - reporter: java-junit - list-suites: failed - list-tests: failed - path-replace-backslashes: true - fail-on-error: false diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml new file mode 100755 index 0000000000..1c76ce00f8 --- /dev/null +++ b/.github/workflows/test-windows.yml @@ -0,0 +1,136 @@ +name: test-windows +"on": + workflow_call: + inputs: + version: + required: true + type: string + clusterName: + required: false + type: string + secrets: + AtlasProjectId: + required: false + BaseUrl: + required: false + AtlasPublicKey: + required: false + AtlasPrivateKey: + required: false +env: + REALM_DISABLE_ANALYTICS: true + DOTNET_NOLOGO: true +jobs: + test-uwp: + runs-on: windows-2019 + name: UWP + timeout-minutes: 45 + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: false + ref: ${{ github.event.pull_request.head.sha }} + - name: Register csc problem matcher + run: echo "::add-matcher::.github/problem-matchers/csc.json" + - name: Register msvc problem matcher + run: echo "::add-matcher::.github/problem-matchers/msvc.json" + - name: Fetch Realm + uses: actions/download-artifact@v2 + with: + name: Realm.${{ inputs.version }} + path: ${{ github.workspace }}/Realm/packages/ + - name: Fetch Realm.Fody + uses: actions/download-artifact@v2 + with: + name: Realm.Fody.${{ inputs.version }} + path: ${{ github.workspace }}/Realm/packages/ + - name: Import test certificate + id: import-pfx + run: | + $cert = New-SelfSignedCertificate -Type Custom -Subject "CN=RealmTests" -KeyUsage DigitalSignature -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") + echo "::set-output name=thumbprint::$($cert.Thumbprint)" + shell: powershell + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + if: ${{ runner.os == 'Windows' }} + - name: Build Tests/Tests.UWP + run: msbuild Tests/Tests.UWP -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:AppxBundle=Always -p:PackageCertificateThumbprint=${{ steps.import-pfx.outputs.thumbprint }} -p:UseDotNetNativeToolchain=false -p:AppxBundlePlatforms=x64 + - name: Run the tests + run: ./Tests/Tests.UWP/RunTests.ps1 -ExtraAppArgs ' --baasurl=${{ secrets.BaseUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=uwp-managed' + shell: powershell + - name: Publish Unit Test Results + uses: LaPeste/test-reporter@b8a650f4490e7472b930f56bbb92c7b42dc5db15 + if: always() + with: + name: Results UWP Managed + path: ${{ env.TEST_RESULTS }} + reporter: java-junit + list-suites: failed + list-tests: failed + path-replace-backslashes: true + fail-on-error: false + test-maui: + runs-on: windows-2019 + name: Maui.Windows + timeout-minutes: 45 + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: false + ref: ${{ github.event.pull_request.head.sha }} + - name: Register csc problem matcher + run: echo "::add-matcher::.github/problem-matchers/csc.json" + - name: Register msvc problem matcher + run: echo "::add-matcher::.github/problem-matchers/msvc.json" + - name: Fetch Realm + uses: actions/download-artifact@v2 + with: + name: Realm.${{ inputs.version }} + path: ${{ github.workspace }}/Realm/packages/ + - name: Fetch Realm.Fody + uses: actions/download-artifact@v2 + with: + name: Realm.Fody.${{ inputs.version }} + path: ${{ github.workspace }}/Realm/packages/ + - name: Configure .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + - run: dotnet workload install maui + - name: Import test certificate + id: import-pfx + run: | + $cert = New-SelfSignedCertificate -Type Custom -Subject "CN=RealmTests" -KeyUsage DigitalSignature -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") + echo "::set-output name=thumbprint::$($cert.Thumbprint)" + shell: powershell + - name: Publish Tests/Tests.Maui + run: dotnet publish Tests/Tests.Maui -c Release -f net6.0-windows10.0.19041 -r win10-x64 -p:GenerateAppxPackageOnBuild=true -p:PackageCertificateThumbprint=${{ steps.import-pfx.outputs.thumbprint }} -p:AppxPackageTestDir=Output/ -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} --no-self-contained + - name: Output executable path + id: dotnet-publish + run: echo '::set-output name=executable-path::./Tests/Tests.Maui/bin/Release/net6.0-windows10.0.19041/win10-x64' + - name: Run the tests + run: | + .\Tests\Tests.Maui\Output\Install.ps1 -Force + # Tests.Maui --headless --labels=After --result=TestResults.Windows.xml --baasurl=${{ secrets.BaseUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=Maui.Windows + + $package = Get-AppxPackage -Name realm.maui.tests + Start-Process "shell:AppsFolder\$($package.PackageFamilyName)!App" -ArgumentList "--headless --labels=After --result=$(pwd)\TestResults.Windows.xml --output=$(pwd)\test.log --baasurl=${{ secrets.BaseUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=Maui.Windows" + Start-Sleep 5 + echo "Waiting for tests to finish" + $(Get-Process Tests.Maui).WaitForExit(90000) + Get-Content args.txt + Get-Content test.log + shell: powershell + - name: Publish Unit Test Results + uses: LaPeste/test-reporter@b8a650f4490e7472b930f56bbb92c7b42dc5db15 + if: always() + with: + name: Results Maui.Windows + path: TestResults.Windows.xml + reporter: java-junit + list-suites: failed + list-tests: failed + path-replace-backslashes: true + fail-on-error: false diff --git a/Tests/Tests.Maui/MainPage.xaml.cs b/Tests/Tests.Maui/MainPage.xaml.cs index 5776457dd2..b09162eb2e 100644 --- a/Tests/Tests.Maui/MainPage.xaml.cs +++ b/Tests/Tests.Maui/MainPage.xaml.cs @@ -69,31 +69,43 @@ private async Task RunTests() var autorun = new AutoRun(typeof(TestHelpers).Assembly); var arguments = Realms.Tests.Sync.SyncTestHelpers.ExtractBaasSettings(MauiProgram.Args); - using var reader = new StringReader(string.Empty); - using var writer = new DebugWriter((msg, style, newLine) => + int failed = default; + + var nunitArgs = arguments.Except(new[] { "--headless" }).ToArray(); +#if !__IOS__ && !__ANDROID__ + if (nunitArgs.Length != arguments.Length) // arguments contained --headless + { + failed = autorun.Execute(nunitArgs); + } + else +#endif { - Dispatcher.Dispatch(() => + using var reader = new StringReader(string.Empty); + using var writer = new DebugWriter((msg, style, newLine) => { - var span = GetSpan(msg, style); - var label = LogsStack.Children.LastOrDefault() as Label; - if (label == null) + Dispatcher.Dispatch(() => { - label = new Label { FormattedText = new FormattedString() }; - LogsStack.Children.Add(label); - } - label.FormattedText.Spans.Add(span); - if (newLine) - { - LogsStack.Children.Add(new Label { FormattedText = new FormattedString() }); - } - - if (ScrollLogsToggle.IsToggled) - { - _ = LogsScrollView.ScrollToAsync(0, 999999, false); - } + var span = GetSpan(msg, style); + var label = LogsStack.Children.LastOrDefault() as Label; + if (label == null) + { + label = new Label { FormattedText = new FormattedString() }; + LogsStack.Children.Add(label); + } + label.FormattedText.Spans.Add(span); + if (newLine) + { + LogsStack.Children.Add(new Label { FormattedText = new FormattedString() }); + } + + if (ScrollLogsToggle.IsToggled) + { + _ = LogsScrollView.ScrollToAsync(0, 999999, false); + } + }); }); - }); - var failed = autorun.Execute(arguments.Where(a => a != "--headless").ToArray(), writer, reader); + failed = autorun.Execute(nunitArgs, writer, reader); + } var resultPath = TestHelpers.GetResultsPath(MauiProgram.Args); if (!string.IsNullOrEmpty(resultPath)) diff --git a/Tests/Tests.Maui/MauiProgram.cs b/Tests/Tests.Maui/MauiProgram.cs index 2e0d4da4e0..e461cc0e04 100644 --- a/Tests/Tests.Maui/MauiProgram.cs +++ b/Tests/Tests.Maui/MauiProgram.cs @@ -31,6 +31,12 @@ public static MauiApp CreateMauiApp(params string[] args) Args = args; + var workspace = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"); + if (!string.IsNullOrEmpty(workspace)) + { + File.AppendAllText(Path.Combine(workspace, "args.txt"), string.Join(Environment.NewLine, args)); + } + var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() diff --git a/Tests/Tests.Maui/Platforms/Windows/App.xaml.cs b/Tests/Tests.Maui/Platforms/Windows/App.xaml.cs index 35679364bd..de7e333ef4 100644 --- a/Tests/Tests.Maui/Platforms/Windows/App.xaml.cs +++ b/Tests/Tests.Maui/Platforms/Windows/App.xaml.cs @@ -30,11 +30,14 @@ public App() protected override void OnLaunched(LaunchActivatedEventArgs args) { base.OnLaunched(args); + + // Try to attach to a parent process's console, for logging + PInvoke.Kernel32.AttachConsole(-1); } protected override MauiApp CreateMauiApp() { - var args = Environment.GetCommandLineArgs(); + var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); return MauiProgram.CreateMauiApp(args); } diff --git a/Tests/Tests.Maui/Platforms/Windows/Package.appxmanifest b/Tests/Tests.Maui/Platforms/Windows/Package.appxmanifest index 0cb469c4dc..9cf6121503 100644 --- a/Tests/Tests.Maui/Platforms/Windows/Package.appxmanifest +++ b/Tests/Tests.Maui/Platforms/Windows/Package.appxmanifest @@ -2,13 +2,19 @@ - + - User Name + Tests.Maui + Realm @@ -23,6 +29,14 @@ + + + + + + + diff --git a/Tests/Tests.Maui/Tests.Maui.csproj b/Tests/Tests.Maui/Tests.Maui.csproj index 31824b4aca..661685070e 100644 --- a/Tests/Tests.Maui/Tests.Maui.csproj +++ b/Tests/Tests.Maui/Tests.Maui.csproj @@ -2,7 +2,7 @@ net6.0-android;net6.0-ios;net6.0-maccatalyst - $(TargetFrameworks);net6.0-windows10.0.19041 + $(TargetFrameworks);net6.0-windows10.0.19041 Exe Tests.Maui true @@ -31,8 +31,13 @@ 10.0.17763.0 + + True + + + @@ -100,9 +105,4 @@ - - WinExe - win10-x64 - -