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

Script to create local test binaries from Azure Pipelines build #914

Merged
merged 4 commits into from Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
194 changes: 194 additions & 0 deletions CreateTestBinariesDirFromBuild.ps1
@@ -0,0 +1,194 @@
[CmdletBinding()]
param(
[String]$Flavor = "Debug",
[String]$Platform = "x86",
[switch]$NoBuild,
[switch]$NugetPkgTests,
[switch]$FrameworkPkgTests,
[String]$BuildId
)

if($NugetPkgTests -and $FrameworkPkgTests)
{
Write-Error "-NugetPkgTests and -FrameworkPkgTests are mutually exclusive"
kmahone marked this conversation as resolved.
Show resolved Hide resolved
exit 1
}
if(!$BuildId -and $FrameworkPkgTests)
{
Write-Error "-FrameworkPkgTests is only valid when using a -BuildId. Use -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($NugetPkgTests)
{
$artifactName = "NugetPkgTestsDrop"
}
elseif($FrameworkPkgTests)
{
$artifactName = "FrameworkPkgTestsDrop"
}

$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(!$NugetPkgTests)
{
$shouldBuild = $shouldBuild -Or (DoesTaefAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "MUXControlsTestApp" -Platform $Platform -Flavor $Flavor)
$shouldBuild = $shouldBuild -Or (DoesTaefAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "IXMPTestApp" -Platform $Platform -Flavor $Flavor)
$shouldBuild = $shouldBuild -Or (DoesAppXNeedBuild -MuxDllFile $muxDllFile -ProjectName "MUXControlsTestAppWPFPackage" -Platform $Platform -Flavor $Flavor -AppXPath "MUXControlsTestAppWPFPackage\AppPackages\MUXControlsTestAppWPFPackage_Test\MUXControlsTestAppWPFPackage.appx" -ExePath "MUXControlsTestAppWPF\MUXControlsTestAppWPF.exe" -ProjectPath "MUXControlsTestAppWPFPackage\MUXControlsTestAppWPFPackage.wapproj")
if($shouldBuild)
{
$buildCmd = "$PSScriptRoot\build.cmd $($Platform.ToLower()) $($Flavor.ToLower()) /target test\MUXControlsTestApp\MUXControlsTestApp_TAEF:Publish /target test\IXMPTestApp\IXMPTestApp_TAEF:Publish /target test\MUXControlsTestAppWPF\MUXControlsTestAppWPFPackage: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")
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"
}
120 changes: 0 additions & 120 deletions CreateTestBinariesDirFromLocalBuild.ps1

This file was deleted.

3 changes: 2 additions & 1 deletion RunTestsOnTShellConnectedDevice.ps1
Expand Up @@ -45,7 +45,8 @@ $ignoredOutput = cmdd if not exist $deviceDir mkdir $deviceDir

if(!$NoDeploy)
{
& .\CreateTestBinariesDirFromLocalBuild.ps1 -NoBuild:$NoBuild -Release:$Release -Flavor:$Flavor -Platform:$Platform

& .\CreateTestBinariesDirFromBuild.ps1 -NoBuild:$NoBuild -NugetPkgTests:$Release -Flavor:$Flavor -Platform:$Platform
}


Expand Down
4 changes: 2 additions & 2 deletions build/Helix/PrepareHelixPayload.ps1
Expand Up @@ -21,8 +21,6 @@ New-Item -ItemType Directory -Force -Path $payloadDir
Copy-Item "$nugetPackagesDir\microsoft.windows.apps.test.1.0.181203002\lib\netcoreapp2.1\*.dll" $payloadDir
Copy-Item "$nugetPackagesDir\taef.redist.wlk.10.31.180822002\build\Binaries\$Platform\*" $payloadDir
Copy-Item "$nugetPackagesDir\taef.redist.wlk.10.31.180822002\build\Binaries\$Platform\CoreClr\*" $payloadDir
Copy-Item "$nugetPackagesDir\runtime.win-$Platform.microsoft.netcore.app.2.1.0\runtimes\win-$Platform\lib\netcoreapp2.1\*" $payloadDir
Copy-Item "$nugetPackagesDir\runtime.win-$Platform.microsoft.netcore.app.2.1.0\runtimes\win-$Platform\native\*" $payloadDir
New-Item -ItemType Directory -Force -Path "$payloadDir\.NETCoreApp2.1\"
Copy-Item "$nugetPackagesDir\runtime.win-$Platform.microsoft.netcore.app.2.1.0\runtimes\win-$Platform\lib\netcoreapp2.1\*" "$payloadDir\.NETCoreApp2.1\"
Copy-Item "$nugetPackagesDir\runtime.win-$Platform.microsoft.netcore.app.2.1.0\runtimes\win-$Platform\native\*" "$payloadDir\.NETCoreApp2.1\"
Expand All @@ -49,12 +47,14 @@ Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\MUXControlsTestApp_Test\Dependencies\$Platform\*" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\IXMPTestApp_Test\*" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\IXMPTestApp_Test\Dependencies\$Platform\*" $payloadDir

# NuGet test artifacts
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\Test\MUXControls.ReleaseTest.dll" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\NugetPackageTestApp_Test\*" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\NugetPackageTestApp_Test\Dependencies\$Platform\*" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\NugetPackageTestAppCX_Test\*" $payloadDir
Copy-If-Exists "$repoDirectory\Artifacts\$ArtifactName\$Configuration\$Platform\AppxPackages\NugetPackageTestAppCX_Test\Dependencies\$Platform\*" $payloadDir

# Copy files from the repo
New-Item -ItemType Directory -Force -Path "$payloadDir\scripts"
Copy-Item "build\helix\ConvertWttLogToXUnit.ps1" "$payloadDir\scripts"
Expand Down
2 changes: 1 addition & 1 deletion build/ShouldSkipPRBuild.ps1
Expand Up @@ -11,7 +11,7 @@ function AllChangedFilesAreSkippable
foreach($file in $files)
{
Write-Host "Checking '$file'"
$ext = (Get-Item $file).Extension
$ext = [System.IO.Path]::GetExtension($file)
$fileIsSkippable = $ext -in $skipExts
Write-Host "File '$file' is skippable: '$fileIsSkippable'"

Expand Down