forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateTestBinariesDirFromBuild.ps1
201 lines (168 loc) · 7.47 KB
/
CreateTestBinariesDirFromBuild.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
[CmdletBinding()]
param(
[ValidateSet("Debug", "Release")]
[String]$Flavor = "Debug",
[ValidateSet("x86", "x64")]
[String]$Platform = "x86",
[switch]$NoBuild,
[String]$BuildId,
[ValidateSet("DevTest", "NugetPkgTests", "FrameworkPkgTests")]
[string]$TestSuite = "DevTest"
)
if(!$BuildId -and $TestSuite -eq "FrameworkPkgTests")
{
Write-Error "-TestSuite='FrameworkPkgTests' is only valid when using a -BuildId. Use -TestSuite='NugetPkgTests' for testing locally."
exit 1
}
function DoesTaefAppXNeedBuild
{
param(
[System.IO.FileSystemInfo]$MuxDllFile,
[string]$ProjectName,
[string]$Platform,
[string]$Flavor
)
$projectFileName = "$($ProjectName).TAEF"
return DoesAppXNeedBuild -MuxDllFile $MuxDllFile -ProjectName $ProjectName -Platform $Platform -Flavor $Flavor -AppXPath "$projectFileName\AppPackages\$($ProjectName)_Test\$ProjectName.appx" -ExePath "$projectFileName\$ProjectName.exe"
}
function DoesAppXNeedBuild
{
param(
[System.IO.FileSystemInfo]$MuxDllFile,
[string]$AppXPath,
[string]$ExePath,
[string]$ProjectName,
[string]$BuildTarget,
[string]$Platform,
[string]$Flavor
)
$appxFullPath = "$PSScriptRoot\BuildOutput\$Flavor\$Platform\$AppXPath"
$testAppxFile = Get-Item $appxFullPath -ErrorAction Ignore
$testExeFile = Get-Item "$PSScriptRoot\BuildOutput\$Flavor\$Platform\$ExePath" -ErrorAction Ignore
if((!$testAppxFile) -or (!$testExeFile) -or ($testExeFile.LastWriteTime -gt $testAppxFile.LastWriteTime) -or ($muxDllFile.LastWriteTime -gt $testAppxFile.LastWriteTime))
{
if ($testAppxFile)
{
Write-Host "$testAppxFile LastWriteTime = $($testAppxFile.LastWriteTime)"
}
else
{
Write-Host "No appx at $appxFullPath"
}
if ($testExeFile)
{
Write-Host "$testExeFile LastWriteTime = $($testExeFile.LastWriteTime)"
}
Write-Host "$muxDllFile LastWriteTime = $($muxDllFile.LastWriteTime)"
return $true
}
else
{
return $false
}
}
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
$name = [System.IO.Path]::GetRandomFileName()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}
# Clean up artifacts and HelixPayload directories:
$artifactsDir = "$PSScriptRoot\Artifacts"
$artifactsDropDir = "$PSScriptRoot\Artifacts\drop"
$helixpayloadDir = "$PSScriptRoot\HelixPayload\$Flavor\$Platform"
if(Test-Path $artifactsDropDir)
{
Remove-Item $artifactsDropDir -Force -Recurse
}
if(Test-Path $helixpayloadDir)
{
Remove-Item $helixpayloadDir -Force -Recurse
}
if($BuildId)
{
$artifactName = "drop"
if($TestSuite -eq "NugetPkgTests")
{
$artifactName = "NugetPkgTestsDrop"
}
elseif($TestSuite -eq "FrameworkPkgTests")
{
$artifactName = "FrameworkPkgTestsDrop"
}
$artifactTargetDir = "$artifactsDir\$artifactName"
if(Test-Path $artifactTargetDir)
{
Remove-Item $artifactTargetDir -Force -Recurse
}
$tempDir = New-TemporaryDirectory
$tempDirPath = $tempDir.FullName
$downloadFileName = $artifactName + ".zip"
$downloadFilePath = Join-Path $tempDirPath $downloadFileName
$dropData = Invoke-RestMethod -Uri "https://dev.azure.com/ms/microsoft-ui-xaml/_apis/build/builds/$buildId/artifacts?artifactName=$artifactName&api-version=4.1" -Method Get
# Invoke-WebRequest is orders of magnitude slower when the progress indicator is being displayed. So temporarily disable it.
$ProgressPreferenceOld = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
try
{
Write-Host "Downloading '$downloadFileName'. Please wait, this will take a few moments..."
Invoke-WebRequest -Uri $dropData.resource.downloadUrl -OutFile $downloadFilePath
}
finally
{
$ProgressPreference = $ProgressPreferenceOld
}
Write-Host "Done!"
Write-Host "Downloaded file to $downloadFilePath"
Write-Host "Extracting files to $artifactsDir"
Expand-Archive -Path $downloadFilePath -DestinationPath $artifactsDir
& .\Tools\NugetWrapper.cmd restore build\Helix\packages.config -PackagesDirectory build\Helix\packages
& .\build\Helix\PrepareHelixPayload.ps1 -Platform $Platform -Configuration $Flavor -ArtifactName $artifactName
Write-Verbose "Removing temp dir '$tempDirPath'"
Remove-Item -Force -Recurse $tempDirPath
Write-Host ""
Write-Host "Test binaries dir created in $helixpayloadDir"
}
else
{
Write-Host "Creating test binaries dir from local build."
# Determine if we need to build the test binaries:
$muxDllFile = Get-Item "$PSScriptRoot\BuildOutput\$Flavor\$Platform\Microsoft.UI.Xaml\Microsoft.UI.Xaml.dll"
$shouldBuild = $false;
$buildCmd = "";
if($TestSuite -eq "DevTest")
{
$shouldBuild = $shouldBuild -Or (DoesTaefAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "MUXControlsTestApp" -Platform $Platform -Flavor $Flavor)
$shouldBuild = $shouldBuild -Or (DoesTaefAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "IXMPTestApp" -Platform $Platform -Flavor $Flavor)
if($shouldBuild)
{
$buildCmd = "$PSScriptRoot\build.cmd $($Platform.ToLower()) $($Flavor.ToLower()) /target test\MUXControlsTestApp\MUXControlsTestApp_TAEF:Publish /target test\IXMPTestApp\IXMPTestApp_TAEF:Publish"
}
}
else
{
$shouldBuild = $shouldBuild -Or (DoesAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "NugetPackageTestApp" -Platform $Platform -Flavor $Flavor -AppXPath "NugetPackageTestApp\AppPackages\NugetPackageTestApp_Test\NugetPackageTestApp.appx" -ExePath "NugetPackageTestApp\NugetPackageTestApp.exe" -ProjectPath "MUXControlsReleaseTest\NugetPackageTestApp\NugetPackageTestApp.csproj")
$shouldBuild = $shouldBuild -Or (DoesAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "NugetPackageTestAppCX" -Platform $Platform -Flavor $Flavor -AppXPath "NugetPackageTestAppCX\AppPackages\NugetPackageTestAppCX_Test\NugetPackageTestAppCX.appx" -ExePath "NugetPackageTestAppCX\NugetPackageTestAppCX.exe" -ProjectPath "MUXControlsReleaseTest\NugetPackageTestAppCX\NugetPackageTestAppCX.csproj")
$shouldBuild = $shouldBuild -Or (DoesAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "WpfApp" -Platform $Platform -Flavor $Flavor -AppXPath "WpfApp.Package\AppPackages\WpfApp_Test\WpfApp.msix" -ExePath "WpfApp\WpfApp.exe" -ProjectPath "MUXControlsReleaseTest\XamlIslandsTestApp\WpfApp\WpfApp.Package.wapproj")
if($shouldBuild)
{
$buildCmd = "$PSScriptRoot\build.cmd $($Platform.ToLower()) $($Flavor.ToLower()) /project D:\microsoft-ui-xaml\test\MUXControlsReleaseTest\MUXControlsReleaseTest.sln"
}
}
if($shouldBuild)
{
if(!$NoBuild)
{
Write-Host $buildCmd
Invoke-Expression $buildCmd
}
else
{
Write-Warning "Test binaries are out of date, but -NoBuild flag was specified so skipping build"
}
}
& .\build\CopyFilesToStagingDir.ps1 -BuildOutputDir "$PSScriptRoot\BuildOutput\" -PublishDir $artifactsDropDir -Platform $Platform -Configuration $Flavor -PublishAppxFiles
& .\Tools\NugetWrapper.cmd restore build\Helix\packages.config -PackagesDirectory build\Helix\packages
& .\build\Helix\PrepareHelixPayload.ps1 -Platform $Platform -Configuration $Flavor
Write-Host ""
Write-Host "Test binaries dir created in $helixpayloadDir"
}