diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 93cb0984..d0982805 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -8,17 +8,17 @@ } } - 'powershell-yaml' = '0.4.2' - InvokeBuild = '5.9.10' - PSScriptAnalyzer = '1.20.0' + 'powershell-yaml' = '0.4.3' + InvokeBuild = '5.9.12' + PSScriptAnalyzer = '1.21.0' Pester = '5.3.3' Plaster = '1.1.3' ModuleBuilder = '2.0.0' ChangelogManagement = '2.1.4' - Sampler = '0.115.0-preview0005' - 'Sampler.GitHubTasks' = '0.3.5-preview0001' - PowerShellForGitHub = '0.16.0' - 'Sampler.DscPipeline' = '0.2.0-preview0002' + Sampler = '0.115.0' + 'Sampler.GitHubTasks' = '0.3.5-preview0002' + PowerShellForGitHub = '0.16.1' + 'Sampler.DscPipeline' = '0.2.0-preview0003' MarkdownLinkCheck = '0.2.0' 'DscResource.AnalyzerRules' = '0.2.0' DscBuildHelpers = '0.2.1' @@ -26,12 +26,12 @@ ProtectedData = '4.1.3' 'Datum.ProtectedData' = '0.0.1' 'Datum.InvokeCommand' = '0.3.0-preview0006' - ReverseDSC = '2.0.0.11' - Configuration = '1.5.0' - Metadata = '1.5.3' - xDscResourceDesigner = '1.9.0.0' + ReverseDSC = '2.0.0.13' + Configuration = '1.5.1' + Metadata = '1.5.7' + xDscResourceDesigner = '1.13.0.0' 'DscResource.Test' = '0.16.1' - 'DscResource.DocGenerator' = '0.11.0' + 'DscResource.DocGenerator' = '0.11.1' # Composites 'DscConfig.Demo' = '0.8.1-preview0002' @@ -39,9 +39,9 @@ #DSC Resources xPSDesiredStateConfiguration = '9.1.0' ComputerManagementDsc = '8.5.0' - NetworkingDsc = '8.2.0' + NetworkingDsc = '9.0.0' JeaDsc = '0.7.2' - xWebAdministration = '3.2.0' + xWebAdministration = '3.3.0' FileSystemDsc = '1.1.1' SecurityPolicyDsc = '2.10.0.0' xDscDiagnostics = '2.8.0' diff --git a/Resolve-Dependency.ps1 b/Resolve-Dependency.ps1 index a8c6b4d1..3848462c 100644 --- a/Resolve-Dependency.ps1 +++ b/Resolve-Dependency.ps1 @@ -9,7 +9,7 @@ .PARAMETER PSDependTarget Path for PSDepend to be bootstrapped and save other dependencies. Can also be CurrentUser or AllUsers if you wish to install the modules in - such scope. The default value is './output/RequiredModules' relative to + such scope. The default value is 'output/RequiredModules' relative to this script's path. .PARAMETER Proxy @@ -59,7 +59,7 @@ param [Parameter()] [System.String] - $PSDependTarget = (Join-Path -Path $PSScriptRoot -ChildPath './output/RequiredModules'), + $PSDependTarget = (Join-Path -Path $PSScriptRoot -ChildPath 'output/RequiredModules'), [Parameter()] [System.Uri] @@ -96,7 +96,11 @@ param [Parameter()] [System.Management.Automation.SwitchParameter] - $WithYAML + $WithYAML, + + [Parameter()] + [System.Collections.Hashtable] + $RegisterGallery ) try @@ -138,7 +142,7 @@ try { if (-not $PSBoundParameters.Keys.Contains($parameterName) -and $resolveDependencyDefaults.ContainsKey($parameterName)) { - Write-Verbose -Message "Setting $parameterName with $($resolveDependencyDefaults[$parameterName])." + Write-Verbose -Message "Setting parameter '$parameterName' to value '$($resolveDependencyDefaults[$parameterName])'." try { @@ -207,6 +211,7 @@ if (-not $powerShellGetModule -and -not $nuGetProvider) Write-Information -MessageData 'Bootstrap: Installing NuGet Package Provider from the web (Make sure Microsoft addresses/ranges are allowed).' + # TODO: This does not handle a private Gallery yet. $null = Install-PackageProvider @providerBootstrapParams $nuGetProvider = Get-PackageProvider -Name 'NuGet' -ListAvailable | Select-Object -First 1 @@ -218,12 +223,50 @@ if (-not $powerShellGetModule -and -not $nuGetProvider) $Null = Import-PackageProvider -Name 'NuGet' -RequiredVersion $nuGetProviderVersion -Force } +if ($RegisterGallery) +{ + if ($RegisterGallery.ContainsKey('Name') -and -not [System.String]::IsNullOrEmpty($RegisterGallery.Name)) + { + $Gallery = $RegisterGallery.Name + } + else + { + $RegisterGallery.Name = $Gallery + } + + Write-Progress -Activity 'Bootstrap:' -PercentComplete 7 -CurrentOperation "Verifying private package repository '$Gallery'" -Completed + + $previousRegisteredRepository = Get-PSRepository -Name $Gallery -ErrorAction 'SilentlyContinue' + + if ($previousRegisteredRepository.SourceLocation -ne $RegisterGallery.SourceLocation) + { + if ($previousRegisteredRepository) + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 9 -CurrentOperation "Re-registrering private package repository '$Gallery'" -Completed + + Unregister-PSRepository -Name $Gallery + + $unregisteredPreviousRepository = $true + } + else + { + Write-Progress -Activity 'Bootstrap:' -PercentComplete 9 -CurrentOperation "Registering private package repository '$Gallery'" -Completed + } + + Register-PSRepository @RegisterGallery + } +} + Write-Progress -Activity 'Bootstrap:' -PercentComplete 10 -CurrentOperation "Ensuring Gallery $Gallery is trusted" # Fail if the given PSGallery is not registered. $previousGalleryInstallationPolicy = (Get-PSRepository -Name $Gallery -ErrorAction 'Stop').InstallationPolicy -Set-PSRepository -Name $Gallery -InstallationPolicy 'Trusted' -ErrorAction 'Ignore' +if ($previousGalleryInstallationPolicy -ne 'Trusted') +{ + # Only change policy if the repository is not trusted + Set-PSRepository -Name $Gallery -InstallationPolicy 'Trusted' -ErrorAction 'Ignore' +} try { @@ -305,7 +348,7 @@ try # PSDepend module not found, installing or saving it. if ($PSDependTarget -in 'CurrentUser', 'AllUsers') { - Write-Debug -Message "PSDepend module not found. Attempting to install from Gallery $Gallery." + Write-Debug -Message "PSDepend module not found. Attempting to install from Gallery '$Gallery'." Write-Warning -Message "Installing PSDepend in $PSDependTarget Scope." @@ -373,7 +416,7 @@ try { Write-Progress -Activity 'Bootstrap:' -PercentComplete 85 -CurrentOperation 'Installing PowerShell module PowerShell-Yaml' - Write-Verbose -Message "PowerShell-Yaml module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + Write-Verbose -Message "PowerShell-Yaml module not found. Attempting to Save from Gallery '$Gallery' to '$PSDependTarget'." $SaveModuleParam = @{ Name = 'PowerShell-Yaml' @@ -388,10 +431,6 @@ try { Write-Verbose "PowerShell-Yaml is already available" } - - Write-Progress -Activity 'Bootstrap:' -PercentComplete 88 -CurrentOperation 'Importing PowerShell module PowerShell-Yaml' - - Import-Module -Name 'PowerShell-Yaml' -ErrorAction 'Stop' } Write-Progress -Activity 'Bootstrap:' -PercentComplete 90 -CurrentOperation 'Invoke PSDepend' @@ -415,7 +454,53 @@ try } finally { - # Reverting the Installation Policy for the given gallery - Set-PSRepository -Name $Gallery -InstallationPolicy $previousGalleryInstallationPolicy + if ($RegisterGallery) + { + Write-Verbose -Message "Removing private package repository '$Gallery'." + Unregister-PSRepository -Name $Gallery + } + + if ($unregisteredPreviousRepository) + { + Write-Verbose -Message "Reverting private package repository '$Gallery' to previous location URI:s." + + $registerPSRepositoryParameters = @{ + Name = $previousRegisteredRepository.Name + InstallationPolicy = $previousRegisteredRepository.InstallationPolicy + } + + if ($previousRegisteredRepository.SourceLocation) + { + $registerPSRepositoryParameters.SourceLocation = $previousRegisteredRepository.SourceLocation + } + + if ($previousRegisteredRepository.PublishLocation) + { + $registerPSRepositoryParameters.PublishLocation = $previousRegisteredRepository.PublishLocation + } + + if ($previousRegisteredRepository.ScriptSourceLocation) + { + $registerPSRepositoryParameters.ScriptSourceLocation = $previousRegisteredRepository.ScriptSourceLocation + } + + if ($previousRegisteredRepository.ScriptPublishLocation) + { + $registerPSRepositoryParameters.ScriptPublishLocation = $previousRegisteredRepository.ScriptPublishLocation + } + + Register-PSRepository @registerPSRepositoryParameters + } + + # Only try to revert installation policy if the repository exist + if ((Get-PSRepository -Name $Gallery -ErrorAction 'SilentlyContinue')) + { + if ($previousGalleryInstallationPolicy -and $previousGalleryInstallationPolicy -ne 'Trusted') + { + # Reverting the Installation Policy for the given gallery if it was not already trusted + Set-PSRepository -Name $Gallery -InstallationPolicy $previousGalleryInstallationPolicy + } + } + Write-Verbose -Message "Project Bootstrapped, returning to Invoke-Build" } diff --git a/Resolve-Dependency.psd1 b/Resolve-Dependency.psd1 index f61799ff..7db04d81 100644 --- a/Resolve-Dependency.psd1 +++ b/Resolve-Dependency.psd1 @@ -1,5 +1,30 @@ @{ + #PSDependTarget = './output/modules' + #Proxy = '' + #ProxyCredential = '$MyCredentialVariable' #TODO: find a way to support credentials in build (resolve variable) + Gallery = 'PSGallery' + + # To use a private nuget repository change the following to your own feed. The locations must be a Nuget v2 feed due + # to limitation in PowerShellGet v2.x. Example below is for a Azure DevOps Server project-scoped feed. While resolving + # dependencies it will be registered as a trusted repository with the name specified in the property 'Gallery' above, + # unless property 'Name' is provided in the hashtable below, if so it will override the property 'Gallery' above. The + # registered repository will be removed when dependencies has been resolved, unless it was already registered to begin + # with. If repository is registered already but with different URL:s the repository will be re-registered and reverted + # after dependencies has been resolved. Currently only Windows integrated security works with private Nuget v2 feeds + # (or if it is a public feed with no security), it is not possible yet to securely provide other credentials for the feed. + #RegisterGallery = @{ + # #Name = 'MyPrivateFeedName' + # GallerySourceLocation = 'https://azdoserver.company.local///_packaging//nuget/v2' + # GalleryPublishLocation = 'https://azdoserver.company.local///_packaging//nuget/v2' + # GalleryScriptSourceLocation = 'https://azdoserver.company.local///_packaging//nuget/v2' + # GalleryScriptPublishLocation = 'https://azdoserver.company.local///_packaging//nuget/v2' + # #InstallationPolicy = 'Trusted' + #} + + #AllowOldPowerShellGetModule = $true + #MinimumPSDependVersion = '0.3.0' AllowPrerelease = $false - WithYAML = $false # Will also bootstrap PowerShell-Yaml to read other config files + WithYAML = $true # Will also bootstrap PowerShell-Yaml to read other config files } + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cef80ad3..4c304675 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,6 +24,10 @@ stages: pool: vmImage: 'windows-2019' steps: + + - pwsh: | + dir -Path env: | Out-String | Write-Host + displayName: 'Display Environment Variables' - pwsh: | dotnet tool install --global GitVersion.Tool diff --git a/build.ps1 b/build.ps1 index 83a05350..f1dd091e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -470,7 +470,7 @@ Begin # The parameter has been explicitly used for calling the .build.ps1 if ($MyInvocation.BoundParameters.ContainsKey($cmdParameter)) { - $paramValue = $MyInvocation.BoundParameters.ContainsKey($cmdParameter) + $paramValue = $MyInvocation.BoundParameters.Item($cmdParameter) Write-Debug " adding $cmdParameter :: $paramValue [from user-provided parameters to Build.ps1]"