From 20b949654b297f84b702d47500ef286764d368ae Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 29 Nov 2018 16:39:03 -0800 Subject: [PATCH] Created a csproj to pin test modules and updated build.psm1 accordingly --- build.psm1 | 27 ++++++++++--------- .../tools/Modules/PSGalleryTestModules.csproj | 9 +++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 test/tools/Modules/PSGalleryTestModules.csproj diff --git a/build.psm1 b/build.psm1 index 866cc51de4a..6786d00bb61 100644 --- a/build.psm1 +++ b/build.psm1 @@ -5,10 +5,6 @@ # On Windows paths is separated by semicolon $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator -# Path to a directory to store modules we temporarily need to test PowerShell -$script:TestModuleDirPath = Join-Path ([System.IO.Path]::GetTempPath()) 'PwshTestModules' -$null = New-Item -Force -ItemType Directory -Path $script:TestModuleDirPath - $dotnetCLIChannel = "release" $dotnetCLIRequiredVersion = $(Get-Content $PSScriptRoot/global.json | ConvertFrom-Json).Sdk.Version @@ -556,7 +552,7 @@ function Restore-PSModuleToBuild Write-Log "Restore PowerShell modules to $publishPath" $modulesDir = Join-Path -Path $publishPath -ChildPath "Modules" - Copy-PSGalleryModules -Destination $modulesDir + Copy-PSGalleryModules -Destination $modulesDir -CsProjPath "$PSScriptRoot\src\Modules\PSGalleryModules.csproj" } function Restore-PSPester @@ -848,8 +844,8 @@ function Publish-PSTestTools { } } - # Get the SelfSignedCertificate module so the web listener can use it - Save-Module -Name SelfSignedCertificate -Path $script:TestModuleDirPath -Repository "PSGallery" -MinimumVersion '0.0.2' -Force -Confirm:$false + # `dotnet restore` on test project is not called if product projects have been restored unless -Force is specified. + Copy-PSGalleryModules -Destination "${PSScriptRoot}/test/tools/Modules" -CsProjPath "$PSScriptRoot/test/tools/Modules/PSGalleryTestModules.csproj" -Force } function Get-ExperimentalFeatureTests { @@ -893,7 +889,7 @@ function Start-PSPester { if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge "4.2" } )) { - Restore-PSPester + Restore-PSPester } if ($IncludeFailingTest.IsPresent) @@ -954,7 +950,7 @@ function Start-PSPester { } # Autoload (in subprocess) temporary modules used in our tests - $newPathFragment = $TestModulePath + $TestModulePathSeparator + $script:TestModuleDirPath + $TestModulePathSeparator + $newPathFragment = $TestModulePath + $TestModulePathSeparator $command += '$env:PSModulePath = '+"'$newPathFragment'" + '+$env:PSModulePath;' # Windows needs the execution policy adjusted @@ -2271,7 +2267,13 @@ function Copy-PSGalleryModules [CmdletBinding()] param( [Parameter(Mandatory=$true)] - [string]$Destination + [string]$CsProjPath, + + [Parameter(Mandatory=$true)] + [string]$Destination, + + [Parameter()] + [switch]$Force ) if (!$Destination.EndsWith("Modules")) { @@ -2279,7 +2281,8 @@ function Copy-PSGalleryModules } Find-DotNet - Restore-PSPackage + + Restore-PSPackage -ProjectDirs (Split-Path $CsProjPath) -Force:$Force.IsPresent $cache = dotnet nuget locals global-packages -l if ($cache -match "info : global-packages: (.*)") { @@ -2289,7 +2292,7 @@ function Copy-PSGalleryModules throw "Can't find nuget global cache" } - $psGalleryProj = [xml](Get-Content -Raw $PSScriptRoot\src\Modules\PSGalleryModules.csproj) + $psGalleryProj = [xml](Get-Content -Raw $CsProjPath) foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) { $name = $m.Include diff --git a/test/tools/Modules/PSGalleryTestModules.csproj b/test/tools/Modules/PSGalleryTestModules.csproj new file mode 100644 index 00000000000..8484d7adaa1 --- /dev/null +++ b/test/tools/Modules/PSGalleryTestModules.csproj @@ -0,0 +1,9 @@ + + + + + + + + +