From 9fda1d0e4fa898b4260944053ff100b0fb061d2d Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 26 Nov 2018 10:44:42 -0800 Subject: [PATCH] Publish test package to AppVeyor daily build (#8273) --- build.psm1 | 28 +++++++++++++++++++++++++++- tools/appveyor.psm1 | 6 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index b8b6eb4dc5..94f46c1289 100644 --- a/build.psm1 +++ b/build.psm1 @@ -2975,6 +2975,31 @@ $script:RESX_TEMPLATE = @' '@ +function Get-UniquePackageFolderName { + param( + [Parameter(Mandatory)] $Root + ) + + $packagePath = Join-Path $Root 'TestPackage' + + $triesLeft = 10 + + while(Test-Path $packagePath) { + $suffix = Get-Random + + # Not using Guid to avoid maxpath problems as in example below. + # Example: 'TestPackage-ba0ae1db-8512-46c5-8b6c-1862d33a2d63\test\powershell\Modules\Microsoft.PowerShell.Security\TestData\CatalogTestData\UserConfigProv\DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.schema.mof' + $packagePath = Join-Path $Root "TestPackage_$suffix" + $triesLeft-- + + if ($triesLeft -le 0) { + throw "Could find unique folder name for package path" + } + } + + $packagePath +} + function New-TestPackage { [CmdletBinding()] @@ -2995,13 +3020,14 @@ function New-TestPackage $rootFolder = $env:TEMP + # In some build agents, typically macOS on AzDevOps, $env:TEMP might not be set. if (-not $rootFolder -and $env:TF_BUILD) { $rootFolder = $env:AGENT_WORKFOLDER } Write-Verbose -Verbose "RootFolder: $rootFolder" + $packageRoot = Get-UniquePackageFolderName -Root $rootFolder - $packageRoot = Join-Path $rootFolder ('TestPackage-' + (new-guid)) $null = New-Item -ItemType Directory -Path $packageRoot -Force $packagePath = Join-Path $Destination "TestPackage.zip" Write-Verbose -Verbose "PackagePath: $packagePath" diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index 270e21d73f..9f16dc0c76 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -502,6 +502,12 @@ function Invoke-AppVeyorAfterTest $codeCoverageArtifacts | ForEach-Object { Push-Artifact -Path $_ } + + New-TestPackage -Destination (Get-Location).Path + $testPackageFullName = Join-Path $pwd 'TestPackage.zip' + Write-Verbose "Created TestPackage.zip" -Verbose + Write-Host -ForegroundColor Green 'Upload test package' + Push-Artifact $testPackageFullName } }