Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows unpackaged DeviceTests in CI #17001

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 72 additions & 27 deletions eng/devices/windows.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const string dotnetVersion = "net7.0";

// required
FilePath PROJECT = Argument("project", EnvironmentVariable("WINDOWS_TEST_PROJECT") ?? DEFAULT_PROJECT);
// Not used for Windows. TODO Use this for packaged vs unpackaged?
// Used for Windows to differentiate between packaged and unpackaged
string TEST_DEVICE = Argument("device", EnvironmentVariable("WINDOWS_TEST_DEVICE") ?? $"");
// Package ID of the WinUI Application
var PACKAGEID = Argument("packageid", EnvironmentVariable("WINDOWS_TEST_PACKAGE_ID") ?? $"");
Expand All @@ -34,6 +34,7 @@ string PLATFORM = "windows";
string DOTNET_PLATFORM = $"win10-x64";
bool DEVICE_CLEANUP = Argument("cleanup", true);
string certificateThumbprint = "";
bool isPackagedTestRun = TEST_DEVICE.ToLower().Equals("packaged");

// Certificate Common Name to use/generate (eg: CN=DotNetMauiTests)
var certCN = Argument("commonname", "DotNetMAUITests");
Expand Down Expand Up @@ -74,6 +75,7 @@ void Cleanup()
Task("Cleanup");

Task("GenerateMsixCert")
.WithCriteria(isPackagedTestRun)
.Does(() =>
{
// We need the key to be in LocalMachine -> TrustedPeople to install the msix signed with the key
Expand Down Expand Up @@ -155,9 +157,38 @@ Task("Build")
s.Framework = TARGET_FRAMEWORK;
s.MSBuildSettings = new DotNetMSBuildSettings();
s.MSBuildSettings.Properties.Add("RuntimeIdentifierOverride", new List<string> { "win10-x64" });
s.MSBuildSettings.Properties.Add("PackageCertificateThumbprint", new List<string> { certificateThumbprint });
s.MSBuildSettings.Properties.Add("AppxPackageSigningEnabled", new List<string> { "True" });
s.MSBuildSettings.Properties.Add("SelfContained", new List<string> { "True" });

var launchSettingsNeedle = "Project";
var launchSettingsReplacement = "MsixPackage";

if (!isPackagedTestRun)
{
launchSettingsNeedle = "MsixPackage";
launchSettingsReplacement = "Project";
}

if (isPackagedTestRun)
{
// Apply correct build properties for packaged builds
s.MSBuildSettings.Properties.Add("PackageCertificateThumbprint", new List<string> { certificateThumbprint });
s.MSBuildSettings.Properties.Add("AppxPackageSigningEnabled", new List<string> { "True" });
s.MSBuildSettings.Properties.Add("SelfContained", new List<string> { "True" });
}
else
{
// Apply correct build properties for unpackaged builds
s.MSBuildSettings.Properties.Add("WindowsPackageType", new List<string> { "None" });
}

// Set correct launchSettings.json setting for packaged/unpackaged
// Get launchSettings.json Path
var launchSettingsPath = PROJECT.GetDirectory();
launchSettingsPath = launchSettingsPath.Combine("Properties").Combine("launchSettings.json");

// Replace value in launchSettings.json
var launchSettingsContents = System.IO.File.ReadAllText(launchSettingsPath.FullPath);
launchSettingsContents = launchSettingsContents.Replace($"\"commandName\": \"{launchSettingsNeedle}\",", $"\"commandName\": \"{launchSettingsReplacement}\",");
System.IO.File.WriteAllText(launchSettingsPath.FullPath, launchSettingsContents);

DotNetPublish(PROJECT.FullPath, s);
});
Expand All @@ -167,52 +198,66 @@ Task("Test")
.IsDependentOn("SetupTestPaths")
.Does(() =>
{
var waitForResultTimeoutInSeconds = 120;

CleanDirectories(TEST_RESULTS);

Information("Cleaned directories");

// Try to uninstall the app if it exists from before
uninstallPS();

Information("Uninstalled previously deployed app");
var projectDir = PROJECT.GetDirectory();
var cerPath = GetFiles(projectDir.FullPath + "/**/AppPackages/*/*.cer").First();
var msixPath = GetFiles(projectDir.FullPath + "/**/AppPackages/*/*.msix").First();

var testResultsFile = MakeAbsolute((DirectoryPath)TEST_RESULTS).FullPath.Replace("/", "\\") + $"\\TestResults-{PACKAGEID.Replace(".", "_")}.xml";

Information($"Found MSIX, installing: {msixPath}");
Information($"Test Results File: {testResultsFile}");

if (FileExists(testResultsFile))
{
DeleteFile(testResultsFile);
}

// Install dependencies
var dependencies = GetFiles(projectDir.FullPath + "/**/AppPackages/**/Dependencies/x64/*.msix");
foreach (var dep in dependencies) {
Information("Installing Dependency MSIX: {0}", dep);
StartProcess("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(dep).FullPath + "\"");
}
if (isPackagedTestRun)
{
// Try to uninstall the app if it exists from before
uninstallPS();

Information("Uninstalled previously deployed app");

var projectDir = PROJECT.GetDirectory();
var cerPath = GetFiles(projectDir.FullPath + "/**/AppPackages/*/*.cer").First();
var msixPath = GetFiles(projectDir.FullPath + "/**/AppPackages/*/*.msix").First();

Information($"Found MSIX, installing: {msixPath}");

// Install the DeviceTests app
StartProcess("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(msixPath).FullPath + "\"");
// Install dependencies
var dependencies = GetFiles(projectDir.FullPath + "/**/AppPackages/**/Dependencies/x64/*.msix");
foreach (var dep in dependencies) {
Information("Installing Dependency MSIX: {0}", dep);
StartProcess("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(dep).FullPath + "\"");
}

// Install the DeviceTests app
StartProcess("powershell", "Add-AppxPackage -Path \"" + MakeAbsolute(msixPath).FullPath + "\"");

var startArgs = "Start-Process shell:AppsFolder\\$((Get-AppxPackage -Name \"" + PACKAGEID + "\").PackageFamilyName)!App -Args \"" + testResultsFile + "\"";

var startArgs = "Start-Process shell:AppsFolder\\$((Get-AppxPackage -Name \"" + PACKAGEID + "\").PackageFamilyName)!App -Args \"" + testResultsFile + "\"";
Information(startArgs);

Information(startArgs);
// Start the DeviceTests app for packaged
StartProcess("powershell", startArgs);
}
else
{
// Unpackaged process blocks the thread, so we can wait shorter for the results
waitForResultTimeoutInSeconds = 30;

// Start the DeviceTests app
StartProcess("powershell", startArgs);
// Start the DeviceTests app for unpackaged
StartProcess(TEST_APP, testResultsFile);
}

var waited = 0;
while (!FileExists(testResultsFile)) {
System.Threading.Thread.Sleep(1000);
waited++;

Information($"Waiting {waited} second(s) for tests to finish...");
if (waited >= 120)
if (waited >= waitForResultTimeoutInSeconds)
break;
}

Expand Down
10 changes: 6 additions & 4 deletions eng/pipelines/common/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,18 @@ stages:
# create all the variables used for the matrix
${{ each project in parameters.projects }}:
${{ if ne(project.windows, '') }}:
${{ replace(coalesce(project.desc, project.name), ' ', '_') }}:
PROJECT_PATH: ${{ project.windows }}
PACKAGE_ID: ${{ project.windowsPackageId }}
${{ each version in parameters.windowsVersions }}:
${{ replace(coalesce(project.desc, project.name), ' ', '_') }}_${{ version }}:
PROJECT_PATH: ${{ project.windows }}
PACKAGE_ID: ${{ project.windowsPackageId }}
DEVICE: ${{ version }}
steps:
- template: device-tests-steps.yml
parameters:
platform: windows
path: $(PROJECT_PATH)
windowsPackageId: $(PACKAGE_ID)
device: windows
device: $(DEVICE) # For Windows this switches between packaged and unpackaged
provisionatorChannel: ${{ parameters.provisionatorChannel }}
agentPoolAccessToken: ${{ parameters.agentPoolAccessToken }}
artifactName: ${{ parameters.artifactName }}
Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/device-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ stages:
# androidApiLevels: [ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21 ] # fix the issue of getting the test results off
iosVersions: [ '16.4', '15.5', '14.5', '13.7']
catalystVersions: [ 'latest' ]
windowsVersions: ['packaged', 'unpackaged']
provisionatorChannel: ${{ parameters.provisionatorChannel }}
${{ if not(or(parameters.BuildEverything, and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'devdiv')))) }}:
androidApiLevels: [ 30, 23 ]
# androidApiLevels: [ 30, 21 ] # fix the issue of getting the test results off
iosVersions: [ '16.4' ]
catalystVersions: [ 'latest' ]
windowsVersions: ['packaged', 'unpackaged']
provisionatorChannel: ${{ parameters.provisionatorChannel }}
projects:
- name: essentials
Expand Down