From 02145c5d7790ad9c570e260ab4d21cd2caa8a966 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 17 Aug 2023 17:03:55 +0200 Subject: [PATCH] Add an argument for device OS version (#2558) --- .config/dotnet-tools.json | 2 +- build.cake | 68 ++++++++++++++---------- scripts/azure-pipelines-variables.yml | 2 + scripts/azure-templates-bootstrapper.yml | 5 ++ scripts/azure-templates-stages.yml | 16 +++--- scripts/cake/xharness-android.cake | 8 ++- scripts/cake/xharness-apple.cake | 4 ++ 7 files changed, 68 insertions(+), 37 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index c83423345a..3e72d39c0f 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -21,7 +21,7 @@ ] }, "microsoft.dotnet.xharness.cli": { - "version": "8.0.0-prerelease.23307.1", + "version": "8.0.0-prerelease.23407.2", "commands": [ "xharness" ] diff --git a/build.cake b/build.cake index 6541a9b476..2812886d6d 100644 --- a/build.cake +++ b/build.cake @@ -203,11 +203,14 @@ Task ("tests-netfx") if (SUPPORT_VULKAN) testAssemblies.Add ("SkiaSharp.Vulkan.Tests.Console"); foreach (var testAssembly in testAssemblies) { - // build var csproj = $"./tests/{testAssembly}/{testAssembly}.csproj"; - RunDotNetBuild (csproj, platform: arch, properties: new Dictionary { - { "TargetFramework", tfm } - }); + + // build + if (!SKIP_BUILD) { + RunDotNetBuild (csproj, platform: arch, properties: new Dictionary { + { "TargetFramework", tfm } + }); + } // test DirectoryPath results = $"./output/logs/testlogs/{testAssembly}/{DATE_TIME_STR}/{tfm}-{arch}"; @@ -251,11 +254,14 @@ Task ("tests-netcore") if (SUPPORT_VULKAN) testAssemblies.Add ("SkiaSharp.Vulkan.Tests.Console"); foreach (var testAssembly in testAssemblies) { - // build var csproj = $"./tests/{testAssembly}/{testAssembly}.csproj"; - RunDotNetBuild (csproj, properties: new Dictionary { - { "TargetFramework", tfm } - }); + + // build + if (!SKIP_BUILD) { + RunDotNetBuild (csproj, properties: new Dictionary { + { "TargetFramework", tfm } + }); + } // test var results = $"./output/logs/testlogs/{testAssembly}/{DATE_TIME_STR}/{tfm}"; @@ -294,12 +300,14 @@ Task ("tests-android") FilePath app = $"./tests/SkiaSharp.Tests.Devices/bin/{configuration}/{tfm}/{rid}/com.companyname.SkiaSharpTests-Signed.apk"; // build the app - RunDotNetBuild (csproj, - configuration: configuration, - properties: new Dictionary { - { "TargetFramework", tfm }, - { "RuntimeIdentifier", rid }, - }); + if (!SKIP_BUILD) { + RunDotNetBuild (csproj, + configuration: configuration, + properties: new Dictionary { + { "TargetFramework", tfm }, + { "RuntimeIdentifier", rid }, + }); + } // run the tests DirectoryPath results = $"./output/logs/testlogs/SkiaSharp.Tests.Devices.Android/{DATE_TIME_STR}"; @@ -324,12 +332,14 @@ Task ("tests-ios") FilePath app = $"./tests/SkiaSharp.Tests.Devices/bin/{configuration}/{tfm}/{rid}/SkiaSharp.Tests.Devices.app"; // package the app - RunDotNetBuild (csproj, - configuration: configuration, - properties: new Dictionary { - { "TargetFramework", tfm }, - { "RuntimeIdentifier", rid }, - }); + if (!SKIP_BUILD) { + RunDotNetBuild (csproj, + configuration: configuration, + properties: new Dictionary { + { "TargetFramework", tfm }, + { "RuntimeIdentifier", rid }, + }); + } // run the tests DirectoryPath results = $"./output/logs/testlogs/SkiaSharp.Tests.Devices.iOS/{DATE_TIME_STR}"; @@ -354,12 +364,14 @@ Task ("tests-maccatalyst") FilePath app = $"./tests/SkiaSharp.Tests.Devices/bin/{configuration}/{tfm}/{rid}/SkiaSharp.Tests.Devices.app"; // package the app - RunDotNetBuild (csproj, - configuration: configuration, - properties: new Dictionary { - { "TargetFramework", tfm }, - { "RuntimeIdentifier", rid }, - }); + if (!SKIP_BUILD) { + RunDotNetBuild (csproj, + configuration: configuration, + properties: new Dictionary { + { "TargetFramework", tfm }, + { "RuntimeIdentifier", rid }, + }); + } // run the tests DirectoryPath results = $"./output/logs/testlogs/SkiaSharp.Tests.Devices.MacCatalyst/{DATE_TIME_STR}"; @@ -375,7 +387,9 @@ Task ("tests-wasm") .IsDependentOn ("externals-wasm") .Does (() => { - RunDotNetBuild ("./tests/SkiaSharp.Tests.Wasm.sln"); + if (!SKIP_BUILD) { + RunDotNetBuild ("./tests/SkiaSharp.Tests.Wasm.sln"); + } IProcess serverProc = null; try { diff --git a/scripts/azure-pipelines-variables.yml b/scripts/azure-pipelines-variables.yml index b33a019dcf..b3fa7fcac2 100644 --- a/scripts/azure-pipelines-variables.yml +++ b/scripts/azure-pipelines-variables.yml @@ -23,3 +23,5 @@ variables: ENABLE_CODE_COVERAGE: true EMSCRIPTEN_VERSION: 3.1.12 Codeql.Enabled: true + IOS_TEST_DEVICE_VERSION: 16.4 + ANDROID_TEST_DEVICE_VERSION: 34 diff --git a/scripts/azure-templates-bootstrapper.yml b/scripts/azure-templates-bootstrapper.yml index bb2120b071..9cea226332 100644 --- a/scripts/azure-templates-bootstrapper.yml +++ b/scripts/azure-templates-bootstrapper.yml @@ -275,9 +275,11 @@ jobs: - ${{ if eq(parameters.docker, '') }}: - ${{ if endsWith(parameters.name, '_windows') }}: - pwsh: | + Get-Content $PSCommandPath dotnet tool restore ${{ parameters.initScript }} dotnet cake --target=${{ parameters.target }} --verbosity=${{ parameters.verbosity }} --configuration=${{ coalesce(parameters.configuration, 'Release') }} ${{ parameters.additionalArgs }} + env: JavaSdkDirectory: $(JAVA_HOME) LLVM_HOME: $(LLVM_HOME) @@ -288,9 +290,11 @@ jobs: condition: and(succeeded(), eq(variables['DOWNLOAD_EXTERNALS'], '')) - ${{ if not(endsWith(parameters.name, '_windows')) }}: - bash: | + cat ${BASH_SOURCE[0]} dotnet tool restore ${{ parameters.initScript }} dotnet cake --target=${{ parameters.target }} --verbosity=${{ parameters.verbosity }} --configuration=${{ coalesce(parameters.configuration, 'Release') }} ${{ parameters.additionalArgs }} + env: JavaSdkDirectory: $(JAVA_HOME) displayName: Run the bootstrapper for ${{ parameters.target }} @@ -309,6 +313,7 @@ jobs: echo dotnet tool restore > cmd.sh echo dotnet cake --target=${{ parameters.target }} --verbosity=${{ parameters.verbosity }} --configuration=${{ coalesce(parameters.configuration, 'Release') }} ${{ parameters.additionalArgs }} >> cmd.sh sed -i 's/--gnArgs=\" \"//' cmd.sh + cat cmd.sh displayName: Generate the script for the Docker image condition: and(succeeded(), eq(variables['DOWNLOAD_EXTERNALS'], '')) - bash: | diff --git a/scripts/azure-templates-stages.yml b/scripts/azure-templates-stages.yml index 4e87587d83..b8681a4986 100644 --- a/scripts/azure-templates-stages.yml +++ b/scripts/azure-templates-stages.yml @@ -613,7 +613,7 @@ stages: buildPipelineType: ${{ parameters.buildPipelineType }} vmImage: ${{ parameters.VM_IMAGE_MAC }} target: tests-android - additionalArgs: --device=android-emulator-64_34 --skipExternals="all" --coverage=$(ENABLE_CODE_COVERAGE) + additionalArgs: --device=android-emulator-64 --deviceVersion=$(ANDROID_TEST_DEVICE_VERSION) --skipExternals="all" --coverage=$(ENABLE_CODE_COVERAGE) shouldPublish: false requiredArtifacts: - name: native_android_x86_macos @@ -623,8 +623,8 @@ stages: preBuildSteps: - pwsh: .\scripts\install-android-package.ps1 -Package "emulator" displayName: Install the Android emulator - - pwsh: .\scripts\install-android-package.ps1 -Package "system-images;android-34;google_apis;x86_64" - displayName: Install the Android API 34 emulator image + - pwsh: .\scripts\install-android-package.ps1 -Package "system-images;android-$(ANDROID_TEST_DEVICE_VERSION);google_apis;x86_64" + displayName: Install the Android API $(ANDROID_TEST_DEVICE_VERSION) emulator image postBuildSteps: - task: PublishTestResults@2 displayName: Publish the Android test results @@ -632,12 +632,12 @@ stages: inputs: testResultsFormat: xUnit testResultsFiles: 'output/logs/testlogs/**/TestResults.xml' - testRunTitle: 'Android Tests' + testRunTitle: 'Android Tests (API $(ANDROID_TEST_DEVICE_VERSION))' - task: PublishBuildArtifacts@1 displayName: Publish the test logs condition: always() inputs: - artifactName: testlogs_android + artifactName: testlogs_android_$(ANDROID_TEST_DEVICE_VERSION) pathToPublish: 'output/logs/testlogs' - template: azure-templates-bootstrapper.yml # Tests|ios (macOS) parameters: @@ -646,7 +646,7 @@ stages: buildPipelineType: ${{ parameters.buildPipelineType }} vmImage: ${{ parameters.VM_IMAGE_MAC }} target: tests-ios - additionalArgs: --device=ios-simulator-64 --skipExternals="all" --coverage=$(ENABLE_CODE_COVERAGE) + additionalArgs: --device=ios-simulator-64 --deviceVersion=$(IOS_TEST_DEVICE_VERSION) --skipExternals="all" --coverage=$(ENABLE_CODE_COVERAGE) shouldPublish: false requiredArtifacts: - name: native_ios_macos @@ -659,12 +659,12 @@ stages: inputs: testResultsFormat: xUnit testResultsFiles: 'output/logs/testlogs/**/TestResults.xml' - testRunTitle: 'iOS Tests' + testRunTitle: 'iOS Tests (v$(IOS_TEST_DEVICE_VERSION))' - task: PublishBuildArtifacts@1 displayName: Publish the test logs condition: always() inputs: - artifactName: testlogs_ios + artifactName: testlogs_ios_$(IOS_TEST_DEVICE_VERSION) pathToPublish: 'output/logs/testlogs' - template: azure-templates-bootstrapper.yml # Tests|maccatalyst (macOS) parameters: diff --git a/scripts/cake/xharness-android.cake b/scripts/cake/xharness-android.cake index fa81a8c13f..23b04376e2 100644 --- a/scripts/cake/xharness-android.cake +++ b/scripts/cake/xharness-android.cake @@ -7,7 +7,8 @@ DirectoryPath ROOT_PATH = MakeAbsolute(Directory("../..")); var TEST_APP = Argument("app", EnvironmentVariable("ANDROID_TEST_APP") ?? ""); var TEST_RESULTS = Argument("results", EnvironmentVariable("ANDROID_TEST_RESULTS") ?? ""); -var TEST_DEVICE = Argument("device", EnvironmentVariable("ANDROID_TEST_DEVICE") ?? "android-emulator-64_34"); +var TEST_DEVICE = Argument("device", EnvironmentVariable("ANDROID_TEST_DEVICE") ?? "android-emulator-64"); +var TEST_VERSION = Argument("deviceVersion", EnvironmentVariable("ANDROID_TEST_DEVICE_VERSION") ?? "34"); var TEST_APP_PACKAGE_NAME = Argument("package", EnvironmentVariable("ANDROID_TEST_APP_PACKAGE_NAME") ?? ""); var TEST_APP_INSTRUMENTATION = Argument("instrumentation", EnvironmentVariable("ANDROID_TEST_APP_INSTRUMENTATION") ?? "devicerunners.xharness.maui.XHarnessInstrumentation"); @@ -52,7 +53,12 @@ AndroidEmulatorProcess emulatorProcess = null; Setup(context => { + if (!string.IsNullOrEmpty(TEST_VERSION) && TEST_VERSION != "latest") + TEST_DEVICE = $"{TEST_DEVICE}_{TEST_VERSION}"; + + Information("Test App: {0}", TEST_APP); Information("Test Device: {0}", TEST_DEVICE); + Information("Test Results Directory: {0}", TEST_RESULTS); // determine the device characteristics { diff --git a/scripts/cake/xharness-apple.cake b/scripts/cake/xharness-apple.cake index 20d2eb1417..8e54faaf93 100644 --- a/scripts/cake/xharness-apple.cake +++ b/scripts/cake/xharness-apple.cake @@ -5,6 +5,7 @@ DirectoryPath ROOT_PATH = MakeAbsolute(Directory("../..")); var TEST_APP = Argument("app", EnvironmentVariable("IOS_TEST_APP")); var TEST_RESULTS = Argument("results", EnvironmentVariable("IOS_TEST_RESULTS") ?? ""); var TEST_DEVICE = Argument("device", EnvironmentVariable("IOS_TEST_DEVICE") ?? "ios-simulator-64"); +var TEST_VERSION = Argument("deviceVersion", EnvironmentVariable("IOS_TEST_DEVICE_VERSION") ?? "latest"); Task("Default") .Does(() => @@ -16,6 +17,9 @@ Task("Default") TEST_RESULTS = TEST_APP + "-results"; } + if (!string.IsNullOrEmpty(TEST_VERSION) && TEST_VERSION.ToLower() != "latest") + TEST_DEVICE = $"{TEST_DEVICE}_{TEST_VERSION}"; + Information("Test App: {0}", TEST_APP); Information("Test Device: {0}", TEST_DEVICE); Information("Test Results Directory: {0}", TEST_RESULTS);