From c38aa894acae0b64f4370b655f1905b8cb2ed3ae Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Thu, 23 Jul 2020 16:18:10 -0700 Subject: [PATCH 01/74] Remove aliases, update module name --- README.md | 22 +++---- SignConfig.xml | 6 +- Test/Proxy.Tests.ps1 | 2 +- ...etCompat.psd1 => CompatPowerShellGet.psd1} | 40 +++--------- ...etCompat.psm1 => CompatPowerShellGet.psm1} | 63 +++++++------------ 5 files changed, 45 insertions(+), 88 deletions(-) rename src/{PowerShellGetCompat.psd1 => CompatPowerShellGet.psd1} (56%) rename src/{PowerShellGetCompat.psm1 => CompatPowerShellGet.psm1} (98%) diff --git a/README.md b/README.md index ca36afb..1dbb56e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# PowerShellGetCompat +# CompatPowerShellGet -[![PowerShell Gallery - PowerShellGetCompat](https://img.shields.io/badge/PowerShell%20Gallery-PowerShellGet-blue.svg)](https://www.powershellgallery.com/packages/PowerShellGetCompat) -[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-3.0-blue.svg)](https://github.com/PowerShell/PowerShellGetCompat) +[![PowerShell Gallery - CompatPowerShellGet](https://img.shields.io/badge/PowerShell%20Gallery-PowerShellGet-blue.svg)](https://www.powershellgallery.com/packages/CompatPowerShellGet) +[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-3.0-blue.svg)](https://github.com/PowerShell/CompatPowerShellGet) Introduction ============ -PowerShellGetCompat is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' +CompatPowerShellGet is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) @@ -16,7 +16,7 @@ questions or comments. Documentation ============= -Documentation for PowerShellGetCompat has not yet been published, please +Documentation for CompatPowerShellGet has not yet been published, please [Click here](https://docs.microsoft.com/powershell/module/PowerShellGet/?view=powershell-7) to reference the documentation for previous versions of PowerShellGet. @@ -27,10 +27,10 @@ Requirements - PowerShell Core. -Get PowerShellGetCompat Module +Get CompatPowerShellGet Module ======================== -Please refer to our [documentation](https://www.powershellgallery.com/packages/PowerShellGetCompat/) for the up-to-date version on how to get the PowerShellGetCompat Module. +Please refer to our [documentation](https://www.powershellgallery.com/packages/CompatPowerShellGet/) for the up-to-date version on how to get the CompatPowerShellGet Module. Get PowerShellGet Source @@ -38,17 +38,17 @@ Get PowerShellGet Source #### Steps * Obtain the source - - Download the latest source code from the release page (https://github.com/PowerShell/PowerShellGetCompat/releases) OR + - Download the latest source code from the release page (https://github.com/PowerShell/CompatPowerShellGet/releases) OR - Clone the repository (needs git) ```powershell - git clone https://github.com/PowerShell/PowerShellGetCompat + git clone https://github.com/PowerShell/CompatPowerShellGet ``` * Navigate to the source directory ```powershell -cd path/to/PowerShellGetCompat +cd path/to/CompatPowerShellGet ``` * Import the module ```powershell -Import-Module src/PowerShellGetCompat +Import-Module src/CompatPowerShellGet ``` diff --git a/SignConfig.xml b/SignConfig.xml index fae5332..87b3d11 100644 --- a/SignConfig.xml +++ b/SignConfig.xml @@ -3,8 +3,8 @@ - - - + + + diff --git a/Test/Proxy.Tests.ps1 b/Test/Proxy.Tests.ps1 index 26c4737..df03140 100644 --- a/Test/Proxy.Tests.ps1 +++ b/Test/Proxy.Tests.ps1 @@ -13,7 +13,7 @@ Describe "Proxies exist" { $skipTest = $true } # be sure that this module is loaded - $proxyModuleName = "PowerShellGetCompat" + $proxyModuleName = "CompatPowerShellGet" $unloadModule = $false if ( ! (Get-Module $proxyModuleName) ) { $unloadModule = $true diff --git a/src/PowerShellGetCompat.psd1 b/src/CompatPowerShellGet.psd1 similarity index 56% rename from src/PowerShellGetCompat.psd1 rename to src/CompatPowerShellGet.psd1 index eca0d7c..b46918a 100644 --- a/src/PowerShellGetCompat.psd1 +++ b/src/CompatPowerShellGet.psd1 @@ -1,5 +1,5 @@ # -# Module manifest for module 'PowerShellGetCompat' +# Module manifest for module 'CompatPowerShellGet' # # Generated by: americks # @@ -7,40 +7,15 @@ # @{ - RootModule = 'PowerShellGetCompat.psm1' + RootModule = 'CompatPowerShellGet.psm1' ModuleVersion = '0.0.1' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' Copyright = '(c) Microsoft Corporation. All rights reserved.' - Description = 'PowerShellGetCompat is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' + Description = 'CompatPowerShellGet is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' PowerShellVersion = '3.0' FunctionsToExport = @( - "Find-CommandProxy", - "Find-DscResourceProxy", - "Find-ModuleProxy", - "Find-RoleCapabilityProxy", - "Find-ScriptProxy", - "Get-InstalledModuleProxy", - "Get-InstalledScriptProxy", - "Get-PSRepositoryProxy", - "Install-ModuleProxy", - "Install-ScriptProxy", - "Publish-ModuleProxy", - "Publish-ScriptProxy", - "Register-PSRepositoryProxy", - "Save-ModuleProxy", - "Save-ScriptProxy", - "Set-PSRepositoryProxy", - "Uninstall-ModuleProxy", - "Uninstall-ScriptProxy", - "Unregister-PSRepositoryProxy", - "Update-ModuleProxy", - "Update-ScriptProxy" - ) - CmdletsToExport = @() - VariablesToExport = '*' - AliasesToExport = @( "Find-Command", "Find-DscResource", "Find-Module", @@ -63,6 +38,9 @@ "Update-Module", "Update-Script" ) + CmdletsToExport = @() + VariablesToExport = '*' + AliasesToExport = @() PrivateData = @{ PSData = @{ @@ -73,14 +51,14 @@ 'Mac', 'Windows') - LicenseUri = 'https://github.com/PowerShell/PowerShellGetCompat/blob/master/LICENSE' - ProjectUri = 'https://github.com/PowerShell/PowerShellGetCompat' + LicenseUri = 'https://github.com/PowerShell/CompatPowerShellGet/blob/master/LICENSE' + ProjectUri = 'https://github.com/PowerShell/CompatPowerShellGet' ReleaseNotes = @' ### 0.0.1 * Initial release ## For full history of release notes see changelog: -https://github.com/PowerShell/PowerShellGetCompat/blob/master/CHANGELOG.md +https://github.com/PowerShell/CompatPowerShellGet/blob/master/CHANGELOG.md '@ } } diff --git a/src/PowerShellGetCompat.psm1 b/src/CompatPowerShellGet.psm1 similarity index 98% rename from src/PowerShellGetCompat.psm1 rename to src/CompatPowerShellGet.psm1 index cf6a699..dab1ec9 100644 --- a/src/PowerShellGetCompat.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -196,8 +196,7 @@ function Convert-ToUri ( [string]$location ) { # In some cases we have a completely new parameter which we need to set. #### #### -function Find-CommandProxy { -[Alias('Find-Command')] +function Find-Command { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=733636')] param( [Parameter(Position=0)] @@ -320,8 +319,7 @@ end } -function Find-DscResourceProxy { -[Alias('Find-DscResource')] +function Find-DscResource { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=517196')] param( [Parameter(Position=0)] @@ -441,8 +439,7 @@ end } -function Find-ModuleProxy { -[Alias('Find-Module')] +function Find-Module { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkID=398574')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -588,8 +585,7 @@ end } -function Find-RoleCapabilityProxy { -[Alias('Find-RoleCapability')] +function Find-RoleCapability { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=718029')] param( [Parameter(Position=0)] @@ -707,8 +703,7 @@ end } -function Find-ScriptProxy { -[Alias('Find-Script')] +function Find-Script { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=619785')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -846,8 +841,7 @@ end } -function Get-InstalledModuleProxy { -[Alias('Get-InstalledModule')] +function Get-InstalledModule { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=526863')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -931,8 +925,7 @@ end } -function Get-InstalledScriptProxy { -[Alias('Get-InstalledScript')] +function Get-InstalledScript { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=619790')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1014,8 +1007,7 @@ end } -function Get-PSRepositoryProxy { -[Alias('Get-PSRepository')] +function Get-PSRepository { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkID=517127')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1069,8 +1061,7 @@ end } -function Install-ModuleProxy { -[Alias('Install-Module')] +function Install-Module { [CmdletBinding(DefaultParameterSetName='NameParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkID=398573')] param( [Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1212,8 +1203,7 @@ end } -function Install-ScriptProxy { -[Alias('Install-Script')] +function Install-Script { [CmdletBinding(DefaultParameterSetName='NameParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=619784')] param( [Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1348,8 +1338,7 @@ end } -function Publish-ModuleProxy { -[Alias('Publish-Module')] +function Publish-Module { [CmdletBinding(DefaultParameterSetName='ModuleNameParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', PositionalBinding=$false, HelpUri='https://go.microsoft.com/fwlink/?LinkID=398575')] param( [Parameter(ParameterSetName='ModuleNameParameterSet', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] @@ -1477,8 +1466,7 @@ end } -function Publish-ScriptProxy { -[Alias('Publish-Script')] +function Publish-Script { [CmdletBinding(DefaultParameterSetName='PathParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', PositionalBinding=$false, HelpUri='https://go.microsoft.com/fwlink/?LinkId=619788')] param( [Parameter(ParameterSetName='PathParameterSet', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] @@ -1562,8 +1550,7 @@ end } -function Register-PSRepositoryProxy { -[Alias('Register-PSRepository')] +function Register-PSRepository { [CmdletBinding(DefaultParameterSetName='NameParameterSet', HelpUri='https://go.microsoft.com/fwlink/?LinkID=517129')] param( [Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0)] @@ -1685,8 +1672,7 @@ end } -function Save-ModuleProxy { -[Alias('Save-Module')] +function Save-Module { [CmdletBinding(DefaultParameterSetName='NameAndPathParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=531351')] param( [Parameter(ParameterSetName='NameAndLiteralPathParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1834,8 +1820,7 @@ end } -function Save-ScriptProxy { -[Alias('Save-Script')] +function Save-Script { [CmdletBinding(DefaultParameterSetName='NameAndPathParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=619786')] param( [Parameter(ParameterSetName='NameAndLiteralPathParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -1982,8 +1967,7 @@ end } -function Set-PSRepositoryProxy { -[Alias('Set-PSRepository')] +function Set-PSRepository { [CmdletBinding(PositionalBinding=$false, HelpUri='https://go.microsoft.com/fwlink/?LinkID=517128')] param( [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -2102,8 +2086,7 @@ end } -function Uninstall-ModuleProxy { -[Alias('Uninstall-Module')] +function Uninstall-Module { [CmdletBinding(DefaultParameterSetName='NameParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=526864')] param( [Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -2204,8 +2187,7 @@ end } -function Uninstall-ScriptProxy { -[Alias('Uninstall-Script')] +function Uninstall-Script { [CmdletBinding(DefaultParameterSetName='NameParameterSet', SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=619789')] param( [Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -2301,8 +2283,7 @@ end } -function Unregister-PSRepositoryProxy { -[Alias('Unregister-PSRepository')] +function Unregister-PSRepository { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkID=517130')] param( [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] @@ -2360,8 +2341,7 @@ end } -function Update-ModuleProxy { -[Alias('Update-Module')] +function Update-Module { [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkID=398576')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] @@ -2476,8 +2456,7 @@ end } -function Update-ScriptProxy { -[Alias('Update-Script')] +function Update-Script { [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium', HelpUri='https://go.microsoft.com/fwlink/?LinkId=619787')] param( [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] From ecb6f2d5a39065067d6808eed92a8637ef149b99 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 23 Jul 2020 16:59:54 -0700 Subject: [PATCH 02/74] Remove aliases to export --- src/CompatPowerShellGet.psm1 | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index dab1ec9..849bd3c 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -2567,30 +2567,6 @@ end } $functionsToExport = @( - "Find-CommandProxy", - "Find-DscResourceProxy", - "Find-ModuleProxy", - "Find-RoleCapabilityProxy", - "Find-ScriptProxy", - "Get-InstalledModuleProxy", - "Get-InstalledScriptProxy", - "Get-PSRepositoryProxy", - "Install-ModuleProxy", - "Install-ScriptProxy", - "Publish-ModuleProxy", - "Publish-ScriptProxy", - "Register-PSRepositoryProxy", - "Save-ModuleProxy", - "Save-ScriptProxy", - "Set-PSRepositoryProxy", - "Uninstall-ModuleProxy", - "Uninstall-ScriptProxy", - "Unregister-PSRepositoryProxy", - "Update-ModuleProxy", - "Update-ScriptProxy" -) - -$aliasesToExport = @( "Find-Command", "Find-DscResource", "Find-Module", @@ -2614,4 +2590,4 @@ $aliasesToExport = @( "Update-Script" ) -export-ModuleMember -Function $functionsToExport -Alias $aliasesToExport +export-ModuleMember -Function $functionsToExport From 4285945e533cb7790c2bb760107f38484f9c7dac Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Tue, 11 Aug 2020 20:42:53 -0700 Subject: [PATCH 03/74] Remove -Force parameter from PSBoundParameters --- CHANGELOG.md | 4 ++++ src/CompatPowerShellGet.psd1 | 6 +++++- src/CompatPowerShellGet.psm1 | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd89f7a..6b8e832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ # Changelog +### 0.0.2 +* Bug Fix +- Remove -Force parameter when calling into v3 cmdlets + ### 0.0.1 * Initial release diff --git a/src/CompatPowerShellGet.psd1 b/src/CompatPowerShellGet.psd1 index b46918a..3a9fa25 100644 --- a/src/CompatPowerShellGet.psd1 +++ b/src/CompatPowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'CompatPowerShellGet.psm1' - ModuleVersion = '0.0.1' + ModuleVersion = '0.0.2' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -54,6 +54,10 @@ LicenseUri = 'https://github.com/PowerShell/CompatPowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/CompatPowerShellGet' ReleaseNotes = @' +### 0.0.2 +* Bug Fix +- Remove -Force parameter when calling into v3 cmdlets + ### 0.0.1 * Initial release diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index 849bd3c..5a10172 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -1165,6 +1165,8 @@ begin if ( $PSBoundParameters['SkipPublisherCheck'] ) { $null = $PSBoundParameters.Remove('SkipPublisherCheck') } if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -1300,6 +1302,8 @@ begin if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -2149,6 +2153,7 @@ begin # Parameter Deletions (unsupported in v3) if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -2243,8 +2248,10 @@ begin $PSBoundParameters['Version'] = $ver } # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } + if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -2418,6 +2425,8 @@ begin if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -2525,9 +2534,11 @@ begin # Parameter translations if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) From ce2bc901d6202e22a26c56b3d46b4effb04d08d1 Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Tue, 26 Jan 2021 15:55:04 -0800 Subject: [PATCH 04/74] Add release build yaml --- .ci/releaseBuild.yml | 166 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 .ci/releaseBuild.yml diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml new file mode 100644 index 0000000..72f9c12 --- /dev/null +++ b/.ci/releaseBuild.yml @@ -0,0 +1,166 @@ +# The name of the build that will be seen in mscodehub +name: CompatPowerShellget-Release-$(Build.BuildId) +# how is the build triggered +# since this is a release build, no trigger as it's a manual release +trigger: none + +pr: + branches: + include: + - master + +# variables to set in the build environment +variables: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + POWERSHELL_TELEMETRY_OPTOUT: 1 + +# since this build relies on templates, we need access to those +# This needs a service connection in the build to work +# the *name* of the service connection must be the same as the endpoint +resources: + repositories: + - repository: ComplianceRepo + type: github + endpoint: ComplianceGHRepo + name: PowerShell/compliance + # this can be any branch of your choosing + ref: master + +# the stages in this build. There are 2 +# the assumption for script analyzer is that test is done as part of +# CI so we needn't do it here +stages: +- stage: Build + displayName: Build + pool: + name: Package ES CodeHub Lab E + jobs: + - job: Build_Job + displayName: Build Microsoft.PowerShell.CompatPowerShellGet + # note the variable reference to ESRP. + # this must be created in Project -> Pipelines -> Library -> VariableGroups + # where it describes the link to the SigningServer + variables: + - group: ESRP + steps: + - checkout: self + + # because CompatPowerShellGet is a script, we can skip the build step + + # these are setting vso variables which will be persisted between stages + - pwsh: | + $signSrcPath = "$(Build.SourcesDirectory)/src" + # Set signing src path variable + $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + + $signOutPath = "$(Build.SourcesDirectory)/CompatPowerShellGet/signed" + $null = New-Item -ItemType Directory -Path $signOutPath + # Set signing out path variable + $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + + # Set path variable for guardian codesign validation + $vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + + # Get version and create a variable + $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/CompatPowerShellGet/src/PSScriptAnalyzer.psd1" + $moduleVersion = $moduleData.ModuleVersion + $vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + + + displayName: Setup variables for signing + + # checkout the Compliance repository so it can be used to do the actual signing + - checkout: ComplianceRepo + + # this the MS authored step This cert covers MS autored items + # note that the buildOutputPath (where we get the files to sign) + # is the same as the signOutputPath in the previous step + # at the end of this step we will have all the files signed that should be + # signOutPath is the location which contains the files we will use to make the module + - template: EsrpSign.yml@ComplianceRepo + parameters: + # the folder which contains the binaries to sign + buildOutputPath: $(signSrcPath) + # the location to put the signed output + signOutputPath: $(signOutPath) + # the certificate ID to use + certificateId: "CP-230012" + # use minimatch because we need to exclude the NewtonSoft assembly + useMinimatch: true + # the file pattern to use - newtonSoft is excluded + pattern: | + **\*.psd1 + **\*.psm1 + + # now create the nupkg which we will use to publish the module + # to the powershell gallery (not part of this yaml) + #- pwsh: | + # Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA" + # ./build -BuildNupkg -signed + # displayName: Create nupkg for publishing + + # finally publish the parts of the build which will be used in the next stages + # if it's not published, the subsequent stages will not be able to access it. + # This is the build directory (it contains all of the dll/pdb files) + - publish: "$(Build.SourcesDirectory)/CompatPowerShellGet" + artifact: build + displayName: publish build directory + + # export the nupkg only which will be used in the release pipeline + - publish: "$(signOutPath)/CompatPowerShellGet.$(moduleVersion).nupkg" + artifact: nupkg + displayName: Publish module nupkg + +# Now on to the compliance stage +- stage: compliance + displayName: Compliance + dependsOn: Build + jobs: + - job: Compliance_Job + pool: + name: Package ES CodeHub Lab E + steps: + - checkout: self + - checkout: ComplianceRepo + - download: current + artifact: build + + # use the templates in the compliance repo + # no assemblies, you should use script-module-compliance template + - template: script-module-compliance.yml@ComplianceRepo + parameters: + # component-governance - the path to sources + sourceScanPath: '$(Build.SourcesDirectory)/CompatPowerShellGet' + # binskim - this isn't recursive, so you need the path to the assemblies + # analyzeTarget: '$(Pipeline.Workspace)\build\bin\PSV7Release\netcoreapp3.1\*.dll' + # credscan - scan the repo for credentials + # you can suppress some files with this. + # suppressionsFile: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/tools/ReleaseBuild/CredScan.Suppressions.json' + # TermCheck + optionsRulesDBPath: '' + optionsFTPath: '' + # tsa-upload + # the compliance scanning must be uploaded, which you need to request + codeBaseName: 'PSSA_202004' + # selections + APIScan: false # set to false when not using Windows APIs. + +#- template: template/publish.yml +# parameters: +# stageName: AzArtifactsFeed +# environmentName: +# feedCredential: + +#- template: template/publish.yml +# parameters: +# stageName: NuGet +# environmentName: PSMarkdownRenderNuGetApproval +# feedCredential: NugetOrgPush \ No newline at end of file From 5c0f10bb509f39aa2cb66c292cf854aaeb1b6deb Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Tue, 26 Jan 2021 17:59:56 -0800 Subject: [PATCH 05/74] Comment out publish nupkg task --- .ci/releaseBuild.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 72f9c12..f3e25f0 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -115,9 +115,9 @@ stages: displayName: publish build directory # export the nupkg only which will be used in the release pipeline - - publish: "$(signOutPath)/CompatPowerShellGet.$(moduleVersion).nupkg" - artifact: nupkg - displayName: Publish module nupkg + #- publish: "$(signOutPath)/CompatPowerShellGet.$(moduleVersion).nupkg" + # artifact: nupkg + # displayName: Publish module nupkg # Now on to the compliance stage - stage: compliance From 6208b68e514a1f92868eff094881a9c68a8f6d7c Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Mon, 1 Feb 2021 21:16:23 -0800 Subject: [PATCH 06/74] Add updates to release build yaml --- .ci/releaseBuild.yml | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index f3e25f0..42d6d37 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -46,16 +46,20 @@ stages: - checkout: self # because CompatPowerShellGet is a script, we can skip the build step + - pwsh: | + dir env: + displayName: Capture environment # these are setting vso variables which will be persisted between stages - pwsh: | - $signSrcPath = "$(Build.SourcesDirectory)/src" + $signSrcPath = "$(Build.SourcesDirectory)/CompatPowerShellGet/src" + dir # Set signing src path variable $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}" Write-Host "sending " + $vstsCommandString Write-Host "##$vstsCommandString" - $signOutPath = "$(Build.SourcesDirectory)/CompatPowerShellGet/signed" + $signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet/signed/CompatPowerShellGet" $null = New-Item -ItemType Directory -Path $signOutPath # Set signing out path variable $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}" @@ -68,13 +72,11 @@ stages: Write-Host "##$vstsCommandString" # Get version and create a variable - $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/CompatPowerShellGet/src/PSScriptAnalyzer.psd1" + $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/CompatPowerShellGet/src/CompatPowerShellGet.psd1" $moduleVersion = $moduleData.ModuleVersion $vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}" Write-Host "sending " + $vstsCommandString Write-Host "##$vstsCommandString" - - displayName: Setup variables for signing # checkout the Compliance repository so it can be used to do the actual signing @@ -100,13 +102,6 @@ stages: **\*.psd1 **\*.psm1 - # now create the nupkg which we will use to publish the module - # to the powershell gallery (not part of this yaml) - #- pwsh: | - # Set-Location "$(Build.SourcesDirectory)/OSS_Microsoft_PSSA" - # ./build -BuildNupkg -signed - # displayName: Create nupkg for publishing - # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. # This is the build directory (it contains all of the dll/pdb files) @@ -114,11 +109,6 @@ stages: artifact: build displayName: publish build directory - # export the nupkg only which will be used in the release pipeline - #- publish: "$(signOutPath)/CompatPowerShellGet.$(moduleVersion).nupkg" - # artifact: nupkg - # displayName: Publish module nupkg - # Now on to the compliance stage - stage: compliance displayName: Compliance @@ -149,18 +139,6 @@ stages: optionsFTPath: '' # tsa-upload # the compliance scanning must be uploaded, which you need to request - codeBaseName: 'PSSA_202004' + codeBaseName: 'CompatPowerShellGet_20200201' # selections APIScan: false # set to false when not using Windows APIs. - -#- template: template/publish.yml -# parameters: -# stageName: AzArtifactsFeed -# environmentName: -# feedCredential: - -#- template: template/publish.yml -# parameters: -# stageName: NuGet -# environmentName: PSMarkdownRenderNuGetApproval -# feedCredential: NugetOrgPush \ No newline at end of file From 60330750ae4a06bf417445aa41eb639fe677ddfd Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 1 Feb 2021 21:58:55 -0800 Subject: [PATCH 07/74] Update releaseBuild.yml for Azure Pipelines --- .ci/releaseBuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 42d6d37..1e12a2a 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -105,7 +105,7 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. # This is the build directory (it contains all of the dll/pdb files) - - publish: "$(Build.SourcesDirectory)/CompatPowerShellGet" + - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet" artifact: build displayName: publish build directory From 28e730a3a62814a3be594da968eddc2fec71ecc0 Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Thu, 4 Feb 2021 22:08:19 -0800 Subject: [PATCH 08/74] Remove debugging statements and unnecessary comments --- .ci/releaseBuild.yml | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 1e12a2a..2338f40 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -27,7 +27,7 @@ resources: ref: master # the stages in this build. There are 2 -# the assumption for script analyzer is that test is done as part of +# the assumption for is that test is done as part of # CI so we needn't do it here stages: - stage: Build @@ -45,11 +45,6 @@ stages: steps: - checkout: self - # because CompatPowerShellGet is a script, we can skip the build step - - pwsh: | - dir env: - displayName: Capture environment - # these are setting vso variables which will be persisted between stages - pwsh: | $signSrcPath = "$(Build.SourcesDirectory)/CompatPowerShellGet/src" @@ -82,7 +77,7 @@ stages: # checkout the Compliance repository so it can be used to do the actual signing - checkout: ComplianceRepo - # this the MS authored step This cert covers MS autored items + # this the MS authored step This cert covers MS authored items # note that the buildOutputPath (where we get the files to sign) # is the same as the signOutputPath in the previous step # at the end of this step we will have all the files signed that should be @@ -93,18 +88,14 @@ stages: buildOutputPath: $(signSrcPath) # the location to put the signed output signOutputPath: $(signOutPath) - # the certificate ID to use + # the certificate ID to use (Authenticode) certificateId: "CP-230012" - # use minimatch because we need to exclude the NewtonSoft assembly - useMinimatch: true - # the file pattern to use - newtonSoft is excluded pattern: | **\*.psd1 **\*.psm1 # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - # This is the build directory (it contains all of the dll/pdb files) - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet" artifact: build displayName: publish build directory @@ -129,11 +120,6 @@ stages: parameters: # component-governance - the path to sources sourceScanPath: '$(Build.SourcesDirectory)/CompatPowerShellGet' - # binskim - this isn't recursive, so you need the path to the assemblies - # analyzeTarget: '$(Pipeline.Workspace)\build\bin\PSV7Release\netcoreapp3.1\*.dll' - # credscan - scan the repo for credentials - # you can suppress some files with this. - # suppressionsFile: '$(Build.SourcesDirectory)/OSS_Microsoft_PSSA/tools/ReleaseBuild/CredScan.Suppressions.json' # TermCheck optionsRulesDBPath: '' optionsFTPath: '' From d254b166a243b9287a00a564514f6aad3a20720c Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Tue, 24 May 2022 12:12:27 -0700 Subject: [PATCH 09/74] Change 'Url' params to 'Uri ' --- src/CompatPowerShellGet.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index 5a10172..83efa5e 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -1628,7 +1628,7 @@ begin $PSBoundParameters['Trusted'] = $true } } - if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Url'] = Convert-ToUri -location $SourceLocation } + if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = Convert-ToUri -location $SourceLocation } if ( $PSBoundParameters['Default'] ) { $null = $PSBoundParameters.Remove('Default'); $PSBoundParameters['PSGallery'] = $Default } # Parameter Deletions (unsupported in v3) @@ -2041,7 +2041,7 @@ begin $PSBoundParameters['Trusted'] = $false } } - if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Url'] = Convert-ToUri -location $SourceLocation } + if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = Convert-ToUri -location $SourceLocation } if ( $PSBoundParameters['Default'] ) { $null = $PSBoundParameters.Remove('Default'); $PSBoundParameters['PSGallery'] = $Default } # Parameter Deletions (unsupported in v3) From 18d9ca0feccdba65daaccb6067b3cc1aa679e5ca Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Wed, 25 May 2022 12:31:04 -0700 Subject: [PATCH 10/74] Update changelog/release notes, and up version --- CHANGELOG.md | 4 ++++ src/CompatPowerShellGet.psd1 | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8e832..0e5c859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +### 0.0.3 +* Changes +- Updated reference to PowerShellGet 'Url' parameter to 'Uri' to reflect changes made in PowerShellGet + ### 0.0.2 * Bug Fix - Remove -Force parameter when calling into v3 cmdlets diff --git a/src/CompatPowerShellGet.psd1 b/src/CompatPowerShellGet.psd1 index 3a9fa25..30474ba 100644 --- a/src/CompatPowerShellGet.psd1 +++ b/src/CompatPowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'CompatPowerShellGet.psm1' - ModuleVersion = '0.0.2' + ModuleVersion = '0.0.3' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -54,6 +54,10 @@ LicenseUri = 'https://github.com/PowerShell/CompatPowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/CompatPowerShellGet' ReleaseNotes = @' +### 0.0.3 +* Changes +- Updated reference to PowerShellGet 'Url' parameter to 'Uri' to reflect changes made in PowerShellGet + ### 0.0.2 * Bug Fix - Remove -Force parameter when calling into v3 cmdlets From 2c98ec54f6b0bd2c66ece8bfac3e595651cda1d9 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 3 May 2023 15:12:44 -0700 Subject: [PATCH 11/74] update compat module --- src/CompatPowerShellGet.psm1 | 2580 ++++++++++++++++++---------------- 1 file changed, 1347 insertions(+), 1233 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index 83efa5e..bb2ac74 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -108,81 +108,41 @@ function Compare-Version return 0 } - -# Convert-VersionsToNugetVersion -RequiredVersion $RequiredVersion -MinimumVersion $MinimumVersion -MaximumVersion $MaximumVersion +# Convert-VersionParamaters -RequiredVersion $RequiredVersion -MinimumVersion $MinimumVersion -MaximumVersion $MaximumVersion # this tries to figure out whether we have an improper use of version parameters # such as RequiredVersion with MinimumVersion or MaximumVersion -function Convert-VersionsToNugetVersion +function Convert-VersionParamaters { param ( $RequiredVersion, $MinimumVersion, $MaximumVersion ) + # validate that required is not used with minimum or maximum version if ( $RequiredVersion -and ($MinimumVersion -or $MaximumVersion) ) { throw "RequiredVersion may not be used with MinimumVersion or MaximumVersion" } - elseif ( ! $RequiredVersion -and ! $MinimuVersion -and ! $MaximumVersion ) { + elseif ( ! $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { return $null } - if ( $RequiredVersion -eq '*' ) { return $RequiredVersion } - - # validate that we can actually convert the received version to an allowed either a system.version or semanticversion - foreach ( $version in "RequiredVersion","MinimumVersion", "MaximumVersion" ) { - if ( $PSBoundParameters[$version] ) { - $v = $PSBoundParameters[$version] -as [System.Version] - $sv = $PSBoundParameters[$version] -match $semVerRegex - if ( ! ($v -or $sv) ) { - $val = $PSBoundParameters[$version] - throw "'$version' ($val) cannot be converted to System.Version or System.Management.Automation.SemanticVersion" - } - } - } - - # we've made sure that we've validated the string we got is correct, so just pass it back - # we've also made sure that we didn't mix min/max with required - if ( $RequiredVersion ) { - return "$RequiredVersion" - } + elseif ( $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { + return "$RequiredVersion" } # now return the appropriate string if ( $MinimumVersion -and ! $MaximumVersion ) { - if ( Get-VersionType $MinimumVersion ) { - return "$MinimumVersion" - } + return "[$MinimumVersion,)" } elseif ( ! $MinimumVersion -and $MaximumVersion ) { # no minimum version - if ( Get-VersionType $MaximumVersion ) { - return "(,${MaximumVersion}]" - } + return "(,${MaximumVersion}]" } else { $result = Compare-Version $MinimumVersion $MaximumVersion if ( $result -ge 0 ) { throw "'$MaximumVersion' must be greater than '$MinimumVersion'" } - return "[${MinimumVersion},${MaximumVersion}]" - - } -} -# we attempt to convert the location to a uri -# that way the user can do Register-PSRepository /tmp -function Convert-ToUri ( [string]$location ) { - $locationAsUri = $location -as [System.Uri] - if ( $locationAsUri.Scheme ) { - return $locationAsUri - } - # now determine if the path exists and is a directory - # if it exists, return it as a file uri - if ( Test-Path -PathType Container -LiteralPath $location ) { - $locationAsUri = "file://${location}" -as [System.Uri] - if( $locationAsUri.Scheme ) { - return $locationAsUri - } + return "[${MinimumVersion},${MaximumVersion}]" } - throw "Cannot convert '$location' to System.Uri" } - #### #### # Proxy functions @@ -248,77 +208,64 @@ param( [string[]] ${Repository}) -begin -{ - Write-Warning -Message "The cmdlet 'Find-Command' is deprecated, please use 'Find-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - $PSBoundParameters['Type'] = 'command' - # Parameter translations - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag'); $PSBoundParameters['Tags'] = $Tag } - if ( $PSBoundParameters['DscResource'] ) { $null = $PSBoundParameters.Remove('DscResource'); $PSBoundParameters['Type'] = "DscResource" } - if ( $PSBoundParameters['RoleCapability'] ) { $null = $PSBoundParameters.Remove('RoleCapability') ; $PSBoundParameters['Type'] = "RoleCapability"} - if ( $PSBoundParameters['Command'] ) { $null = $PSBoundParameters.Remove('Command') ; $PSBoundParameters['Type'] = "command" } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Includes'] ) { $null = $PSBoundParameters.Remove('Includes') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['Name'] ) { $null = $PSBoundParameters.Remove('Name'); $PSBoundParameters['CommandName'] = $Name } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['ModuleName'] ) { $null = $PSBoundParameters.Remove('ModuleName') } + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion') } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion') } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions') } + if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag') } + if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Find-Command -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Find-Command + .ForwardHelpCategory Function + #> } - function Find-DscResource { [CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkId=517196')] param( @@ -371,72 +318,62 @@ param( [string[]] ${Repository}) -begin -{ - Write-Warning -Message "The cmdlet 'Find-DscResource' is deprecated, please use 'Find-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - $PSBoundParameters['Type'] = 'DscResource' - # Parameter translations - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag'); $PSBoundParameters['Tags'] = $Tag } - if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['Name'] ) { $null = $PSBoundParameters.Remove('Name'); $PSBoundParameters['DscResourceName'] = $Name } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['ModuleName'] ) { $null = $PSBoundParameters.Remove('ModuleName') } + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion') } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion') } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions') } + if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag') } + if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Find-DscResource -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Find-DscResource + .ForwardHelpCategory Function + #> } function Find-Module { @@ -515,74 +452,70 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Find-Module' is deprecated, please use 'Find-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - $PSBoundParameters['Type'] = 'module' - # Parameter translations - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag'); $PSBoundParameters['Tags'] = $Tag } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - if ( $PSBoundParameters['DscResource'] ) { $null = $PSBoundParameters.Remove('DscResource'); $PSBoundParameters['Type'] = "DscResource" } - if ( $PSBoundParameters['RoleCapability'] ) { $null = $PSBoundParameters.Remove('RoleCapability'); $PSBoundParameters['Type'] = "RoleCapability" } - if ( $PSBoundParameters['Command'] ) { $null = $PSBoundParameters.Remove('Command'); $PSBoundParameters['Type'] = "command" } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Includes'] ) { $null = $PSBoundParameters.Remove('Includes') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # add new specifier + $PSBoundParameters['Type'] = 'module' + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $PSBoundParameters['Version'] = '*' } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } + if ( $PSBoundParameters['Includes'] ) { $null = $PSBoundParameters.Remove('Includes') } + if ( $PSBoundParameters['DscResource'] ) { $null = $PSBoundParameters.Remove('DscResource'); } + if ( $PSBoundParameters['RoleCapability'] ) { $null = $PSBoundParameters.Remove('RoleCapability'); } + if ( $PSBoundParameters['Command'] ) { $null = $PSBoundParameters.Remove('Command'); } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Find-Module -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Find-Module + .ForwardHelpCategory Function + #> } function Find-RoleCapability { @@ -637,70 +570,14 @@ param( [string[]] ${Repository}) -begin -{ - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - $PSBoundParameters['Type'] = 'RoleCapability' - # Parameter translations - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag'); $PSBoundParameters['Tags'] = $Tag } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} - -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + begin + { + # Find-RoleCability is no longer supported } -} - -end -{ - try { - $steppablePipeline.End() - } catch { - throw - } -} -<# - -.ForwardHelpTargetName Find-RoleCapability -.ForwardHelpCategory Function - -#> - + <# + .ForwardHelpTargetName Find-RoleCapability + .ForwardHelpCategory Function + #> } function Find-Script { @@ -771,74 +648,69 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Find-Script' is deprecated, please use 'Find-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - $PSBoundParameters['Type'] = 'script' - # Parameter translations - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - if ( $PSBoundParameters['Tag'] ) { $null = $PSBoundParameters.Remove('Tag'); $PSBoundParameters['Tags'] = $Tag } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } - if ( $PSBoundParameters['Includes'] ) { $null = $PSBoundParameters.Remove('Includes') } - if ( $PSBoundParameters['Command'] ) { $null = $PSBoundParameters.Remove('Command') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # add new specifier + $PSBoundParameters['Type'] = 'script' + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $PSBoundParameters['Version'] = '*' } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Filter'] ) { $null = $PSBoundParameters.Remove('Filter') } + if ( $PSBoundParameters['Includes'] ) { $null = $PSBoundParameters.Remove('Includes') } + if ( $PSBoundParameters['Command'] ) { $null = $PSBoundParameters.Remove('Command') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Find-Script -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Find-Script + .ForwardHelpCategory Function + #> } function Get-InstalledModule { @@ -870,59 +742,60 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Get-InstalledModule' is deprecated, please use 'Get-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion') } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion') } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions') } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw - } -} + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $PSBoundParameters['Version'] = '*' } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # END PARAMETER MAP -end -{ - try { - $steppablePipeline.End() - } catch { - throw - } -} -<# + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-InstalledPSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } -.ForwardHelpTargetName Get-InstalledModule -.ForwardHelpCategory Function + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } -#> + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Get-InstalledModule + .ForwardHelpCategory Function + #> } function Get-InstalledScript { @@ -951,60 +824,59 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Get-InstalledScript' is deprecated, please use 'Get-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # Parameter translations - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion') } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion') } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw - } -} + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # END PARAMETER MAP -end -{ - try { - $steppablePipeline.End() - } catch { - throw - } -} -<# + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-InstalledPSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } -.ForwardHelpTargetName Get-InstalledScript -.ForwardHelpCategory Function + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } -#> + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Get-InstalledScript + .ForwardHelpCategory Function + #> } function Get-PSRepository { @@ -1015,50 +887,46 @@ param( [string[]] ${Name}) -begin -{ - Write-Warning -Message "The cmdlet 'Get-PSRepository' is deprecated, please use 'Get-PSResourceRepository'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Get-PSRepository -.ForwardHelpCategory Function - -#> - + <# + .ForwardHelpTargetName Get-PSRepository + .ForwardHelpCategory Function + #> } function Install-Module { @@ -1132,77 +1000,65 @@ param( [switch] ${PassThru}) -begin -{ - Write-Warning -Message "The cmdlet 'Install-Module' is deprecated, please use 'Install-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter translations - if ( $PSBoundParameters['AllowClobber'] ) { $null = $PSBoundParameters.Remove('AllowClobber') } - $PSBoundParameters['NoClobber'] = ! $AllowClobber - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['SkipPublisherCheck'] ) { $null = $PSBoundParameters.Remove('SkipPublisherCheck') } - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + if ( $PSBoundParameters['SkipPublisherCheck'] ) { $null = $PSBoundParameters.Remove('SkipPublisherCheck'); $PSBoundParameters['AuthenticodeCheck'] = $SkipPublisherCheck } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['AllowClobber'] ) { $null = $PSBoundParameters.Remove('AllowClobber') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Install-Module -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Install-Module + .ForwardHelpCategory Function + #> } function Install-Script { @@ -1273,73 +1129,198 @@ param( [switch] ${PassThru}) -begin -{ - Write-Warning -Message "The cmdlet 'Install-Script' is deprecated, please use 'Install-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - # Parameter translations - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - if ( $PSBoundParameters['NoPathUpdate'] ) { $null = $PSBoundParameters.Remove('NoPathUpdate') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['NoPathUpdate'] ) { $null = $PSBoundParameters.Remove('NoPathUpdate') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } + <# + .ForwardHelpTargetName Install-Script + .ForwardHelpCategory Function + #> } -<# -.ForwardHelpTargetName Install-Script -.ForwardHelpCategory Function +function New-ScriptFileInfo { +[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess=$true, HelpUri='https://go.microsoft.com/fwlink/?LinkId=619792')] +param( + [Parameter(Position=0, Mandatory=$false, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [ValidateNotNullOrEmpty()] + [string] + ${Version}, + + [ValidateNotNullOrEmpty()] + [string] + ${Author}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Description}, -#> + [ValidateNotNullOrEmpty()] + [Guid] + ${Guid}, + [ValidateNotNullOrEmpty()] + [string] + ${CompanyName}, + + [ValidateNotNullOrEmpty()] + [string] + ${Copyright}, + + [ValidateNotNullOrEmpty()] + [Object[]] + ${RequiredModules}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalModuleDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${RequiredScripts}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalScriptDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${Tags}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${ProjectUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${LicenseUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${IconUri}, + + [string[]] + ${ReleaseNotes}, + + [ValidateNotNullOrEmpty()] + [string] + ${PrivateData}, + + [switch] + ${PassThru}, + + [switch] + ${Force}) + + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # Parameter translations + if ( !$PSBoundParameters['Path'] ) { + $RandomScriptPath = Join-Path -Path . -ChildPath "$(Get-Random).ps1"; + $PSBoundParameters['Path'] = $RandomScriptPath + } + # Translate from string[] to string + if ( $PSBoundParameters['ReleaseNotes'] ) { + $PSBoundParameters['ReleaseNotes'] = $PSBoundParameters['ReleaseNotes'] -join "; " + } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('New-PSScriptFile', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } + + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Test-ScriptFileInfo + .ForwardHelpCategory Function + #> } function Publish-Module { @@ -1373,7 +1354,6 @@ param( [System.Management.Automation.CredentialAttribute()] ${Credential}, - [ValidateSet('2.0')] [version] ${FormatVersion}, @@ -1411,63 +1391,64 @@ param( [switch] ${SkipAutomaticTags}) -begin -{ - Write-Warning -Message "The cmdlet 'Publish-Module' is deprecated, please use 'Publish-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # Parameter translations - if ( $PSBoundParameters['NuGetApiKey'] ) { $null = $PSBoundParameters.Remove('NuGetApiKey'); $PSBoundParameters['APIKey'] = $NuGetApiKey } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Name'] ) { $null = $PSBoundParameters.Remove('Name') } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } - if ( $PSBoundParameters['Repository'] ) { $null = $PSBoundParameters.Remove('Repository') } - if ( $PSBoundParameters['FormatVersion'] ) { $null = $PSBoundParameters.Remove('FormatVersion') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } - if ( $PSBoundParameters['SkipAutomaticTags'] ) { $null = $PSBoundParameters.Remove('SkipAutomaticTags') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['NuGetApiKey'] ) { $null = $PSBoundParameters.Remove('NuGetApiKey'); $PSBoundParameters['APIKey'] = $NuGetApiKey } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Name'] ) { $null = $PSBoundParameters.Remove('Name') } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion') } + if ( $PSBoundParameters['FormatVersion'] ) { $null = $PSBoundParameters.Remove('FormatVersion') } + if ( $PSBoundParameters['ReleaseNotes'] ) { $null = $PSBoundParameters.Remove('ReleaseNotes') } + if ( $PSBoundParameters['Tags'] ) { $null = $PSBoundParameters.Remove('Tags') } + if ( $PSBoundParameters['LicenseUri'] ) { $null = $PSBoundParameters.Remove('LicenseUri') } + if ( $PSBoundParameters['IconUri'] ) { $null = $PSBoundParameters.Remove('IconUri') } + if ( $PSBoundParameters['ProjectUri'] ) { $null = $PSBoundParameters.Remove('ProjectUri') } + if ( $PSBoundParameters['Exclude'] ) { $null = $PSBoundParameters.Remove('Exclude') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } + if ( $PSBoundParameters['SkipAutomaticTags'] ) { $null = $PSBoundParameters.Remove('SkipAutomaticTags') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Publish-Module -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Publish-Module + .ForwardHelpCategory Function + #> } function Publish-Script { @@ -1500,58 +1481,54 @@ param( [switch] ${Force}) -begin -{ - Write-Warning -Message "The cmdlet 'Publish-Script' is deprecated, please use 'Publish-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # Parameter translations - if ( $PSBoundParameters['NuGetApiKey'] ) { $null = $PSBoundParameters.Remove('NuGetApiKey'); $PSBoundParameters['APIKey'] = $NuGetApiKey } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } + if ( $PSBoundParameters['NuGetApiKey'] ) { $null = $PSBoundParameters.Remove('NuGetApiKey'); $PSBoundParameters['APIKey'] = $NuGetApiKey } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Publish-Script -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Publish-Script + .ForwardHelpCategory Function + #> } function Register-PSRepository { @@ -1610,70 +1587,66 @@ param( [string] ${PackageManagementProvider}) -begin -{ - Write-Warning -Message "The cmdlet 'Register-PSRepository' is deprecated, please use 'Register-PSResourceRepository'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } - # PARAMETER MAP - # Parameter translations - if ( $PSBoundParameters['InstallationPolicy'] ) { - $null = $PSBoundParameters.Remove('InstallationPolicy') - if ( $InstallationPolicy -eq "Trusted" ) { - $PSBoundParameters['Trusted'] = $true + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['InstallationPolicy'] ) { + $null = $PSBoundParameters.Remove('InstallationPolicy') + if ( $InstallationPolicy -eq "Trusted" ) { + $PSBoundParameters['Trusted'] = $true + } + } + if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = $SourceLocation } + if ( $PSBoundParameters['Default'] ) { $null = $PSBoundParameters.Remove('Default'); $PSBoundParameters['PSGallery'] = $Default } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['PublishLocation'] ) { $null = $PSBoundParameters.Remove('PublishLocation') } + if ( $PSBoundParameters['ScriptSourceLocation'] ) { $null = $PSBoundParameters.Remove('ScriptSourceLocation') } + if ( $PSBoundParameters['ScriptPublishLocation'] ) { $null = $PSBoundParameters.Remove('ScriptPublishLocation') } + if ( $PSBoundParameters['Credential'] ) { $null = $PSBoundParameters.Remove('Credential') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['PackageManagementProvider'] ) { $null = $PSBoundParameters.Remove('PackageManagementProvider') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Register-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw } } - if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = Convert-ToUri -location $SourceLocation } - if ( $PSBoundParameters['Default'] ) { $null = $PSBoundParameters.Remove('Default'); $PSBoundParameters['PSGallery'] = $Default } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['PublishLocation'] ) { $null = $PSBoundParameters.Remove('PublishLocation') } - if ( $PSBoundParameters['ScriptSourceLocation'] ) { $null = $PSBoundParameters.Remove('ScriptSourceLocation') } - if ( $PSBoundParameters['ScriptPublishLocation'] ) { $null = $PSBoundParameters.Remove('ScriptPublishLocation') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PackageManagementProvider'] ) { $null = $PSBoundParameters.Remove('PackageManagementProvider') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Register-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Register-PSRepository -.ForwardHelpCategory Function - -#> - + <# + .ForwardHelpTargetName Register-PSRepository + .ForwardHelpCategory Function + #> } function Save-Module { @@ -1752,76 +1725,65 @@ param( [switch] ${AcceptLicense}) -begin -{ - Write-Warning -Message "The cmdlet 'Save-Module' is deprecated, please use 'Save-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # remove until available - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter translations - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - if ( $PSBoundParameters['AcceptLicense'] ) { $null = $PSBoundParameters.Remove('AcceptLicense') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + if ( $PSBoundParameters['AcceptLicense'] ) { $null = $PSBoundParameters.Remove('AcceptLicense') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Save-Module -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Save-Module + .ForwardHelpCategory Function + #> } function Save-Script { @@ -1900,75 +1862,64 @@ param( [switch] ${AcceptLicense}) -begin -{ - Write-Warning -Message "The cmdlet 'Save-Script' is deprecated, please use 'Save-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifiers - - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter translations - # LiteralPath needs to be converted to Path - we know they won't be used together because they're in different parameter sets - if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + if ( $PSBoundParameters['AcceptLicense'] ) { $null = $PSBoundParameters.Remove('AcceptLicense') } + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Save-Script -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Save-Script + .ForwardHelpCategory Function + #> } function Set-PSRepository { @@ -2019,75 +1970,129 @@ param( [string] ${PackageManagementProvider}) -begin -{ - Write-Warning -Message "The cmdlet 'Set-PSRepository' is deprecated, please use 'Set-PSResourceRepository'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['InstallationPolicy'] ) { + $null = $PSBoundParameters.Remove('InstallationPolicy') + if ( $InstallationPolicy -eq "Trusted" ) { + $PSBoundParameters['Trusted'] = $true + } + else { + $PSBoundParameters['Trusted'] = $false + } + } + if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = $SourceLocation } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['PublishLocation'] ) { $null = $PSBoundParameters.Remove('PublishLocation') } + if ( $PSBoundParameters['ScriptSourceLocation'] ) { $null = $PSBoundParameters.Remove('ScriptSourceLocation') } + if ( $PSBoundParameters['ScriptPublishLocation'] ) { $null = $PSBoundParameters.Remove('ScriptPublishLocation') } + if ( $PSBoundParameters['Credential'] ) { $null = $PSBoundParameters.Remove('Credential') } + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['PackageManagementProvider'] ) { $null = $PSBoundParameters.Remove('PackageManagementProvider') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Set-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw } + } - # PARAMETER MAP - # add new specifier - # Parameter translations - if ( $PSBoundParameters['InstallationPolicy'] ) { - $null = $PSBoundParameters.Remove('InstallationPolicy') - if ( $InstallationPolicy -eq "Trusted" ) { - $PSBoundParameters['Trusted'] = $true + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw } - else { - $PSBoundParameters['Trusted'] = $false + } + + end + { + try { + $steppablePipeline.End() + } catch { + throw } } - if ( $PSBoundParameters['SourceLocation'] ) { $null = $PSBoundParameters.Remove('SourceLocation'); $PSBoundParameters['Uri'] = Convert-ToUri -location $SourceLocation } - if ( $PSBoundParameters['Default'] ) { $null = $PSBoundParameters.Remove('Default'); $PSBoundParameters['PSGallery'] = $Default } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['PublishLocation'] ) { $null = $PSBoundParameters.Remove('PublishLocation') } - if ( $PSBoundParameters['ScriptSourceLocation'] ) { $null = $PSBoundParameters.Remove('ScriptSourceLocation') } - if ( $PSBoundParameters['ScriptPublishLocation'] ) { $null = $PSBoundParameters.Remove('ScriptPublishLocation') } - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PackageManagementProvider'] ) { $null = $PSBoundParameters.Remove('PackageManagementProvider') } + <# + .ForwardHelpTargetName Set-PSRepository + .ForwardHelpCategory Function + #> +} + +function Test-ScriptFileInfo { +[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'PathParameterSet', HelpUri = 'https://go.microsoft.com/fwlink/?LinkId=619791')] +param( + [Parameter(ParameterSetName='PathParameterSet', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, - # END PARAMETER MAP + [Parameter(ParameterSetName='LiteralPathParameterSet', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [Alias('PSPath')] + [string] + ${LiteralPath}) - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Set-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + # PARAMETER MAP + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } + # END PARAMETER MAP -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw - } -} + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Test-PSScriptFile', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } -end -{ - try { - $steppablePipeline.End() - } catch { - throw + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Set-PSRepository -.ForwardHelpCategory Function -#> + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Test-ScriptFileInfo + .ForwardHelpCategory Function + #> } function Uninstall-Module { @@ -2129,67 +2134,62 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Uninstall-Module' is deprecated, please use 'Uninstall-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # add new specifier - # Parameter translations - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $PSBoundParameters['Version'] = '*' } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Uninstall-Module -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Uninstall-Module + .ForwardHelpCategory Function + #> } function Uninstall-Script { @@ -2227,67 +2227,61 @@ param( [switch] ${AllowPrerelease}) -begin -{ - Write-Warning -Message "The cmdlet 'Uninstall-Script' is deprecated, please use 'Uninstall-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - # Parameter translations - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinumumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - if ( $PSBoundParameters['AllVersions'] ) { $null = $PSBoundParameters.Remove('AllVersions'); $verArgs['RequiredVersion'] = '*' } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['InputObject'] ) { $null = $PSBoundParameters.Remove('InputObject') } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw - } -} + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Uninstall-Script -.ForwardHelpCategory Function - -#> + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Uninstall-Script + .ForwardHelpCategory Function + #> } function Unregister-PSRepository { @@ -2298,54 +2292,50 @@ param( [string[]] ${Name}) -begin -{ - Write-Warning -Message "The cmdlet 'Unregister-PSRepository' is deprecated, please use 'Unregister-PSResourceRepository'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } - # PARAMETER MAP - # No changes between Unregister-PSRepository and Unregister-PSResourceRepository - # END PARAMETER MAP + # PARAMETER MAP + # No changes between Unregister-PSRepository and Unregister-PSResourceRepository + # END PARAMETER MAP - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Unregister-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Unregister-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Unregister-PSRepository -.ForwardHelpCategory Function - -#> - + <# + .ForwardHelpTargetName Unregister-PSRepository + .ForwardHelpCategory Function + #> } function Update-Module { @@ -2397,72 +2387,62 @@ param( [switch] ${PassThru}) -begin -{ - Write-Warning -Message "The cmdlet 'Update-Module' is deprecated, please use 'Update-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - $PSBoundParameters['Type'] = 'module' - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter translations - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } -} -<# - -.ForwardHelpTargetName Update-Module -.ForwardHelpCategory Function - -#> - + <# + .ForwardHelpTargetName Update-Module + .ForwardHelpCategory Function + #> } function Update-Script { @@ -2510,71 +2490,202 @@ param( [switch] ${PassThru}) -begin -{ - Write-Warning -Message "The cmdlet 'Update-Script' is deprecated, please use 'Update-PSResource'." - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - # PARAMETER MAP - $PSBoundParameters['Type'] = 'script' - # handle version changes - $verArgs = @{} - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } - $ver = Convert-VersionsToNugetVersion @verArgs - if ( $ver ) { - $PSBoundParameters['Version'] = $ver - } - - # Parameter translations - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - # Parameter Deletions (unsupported in v3) - if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } - if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } - - # END PARAMETER MAP - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline() - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # Parameter translations + $verArgs = @{} + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + $ver = Convert-VersionParamaters @verArgs + if ( $ver ) { + $PSBoundParameters['Version'] = $ver + } + # Parameter translations + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } + if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } } -} -process -{ - try { - $steppablePipeline.Process($_) - } catch { - throw + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } -} -end -{ - try { - $steppablePipeline.End() - } catch { - throw + end + { + try { + $steppablePipeline.End() + } catch { + throw + } } + <# + .ForwardHelpTargetName Update-Script + .ForwardHelpCategory Function + #> } -<# -.ForwardHelpTargetName Update-Script -.ForwardHelpCategory Function +function Update-ScriptFileInfo { +[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'PathParameterSet', SupportsShouldProcess = $true, HelpUri = 'https://go.microsoft.com/fwlink/?LinkId=619793')] +param( + [Parameter(ParameterSetName = 'PathParameterSet', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName = 'LiteralPathParameterSet', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('PSPath')] + [ValidateNotNullOrEmpty()] + [string] + ${LiteralPath}, + + [ValidateNotNullOrEmpty()] + [string] + ${Version}, + + [ValidateNotNullOrEmpty()] + [string] + ${Author}, + + [ValidateNotNullOrEmpty()] + [string] + ${Description}, + + [ValidateNotNullOrEmpty()] + [Guid] + ${Guid}, + + [ValidateNotNullOrEmpty()] + [string] + ${CompanyName}, + + [ValidateNotNullOrEmpty()] + [string] + ${Copyright}, + + [ValidateNotNullOrEmpty()] + [Object[]] + ${RequiredModules}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalModuleDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${RequiredScripts}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalScriptDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${Tags}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${ProjectUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${LicenseUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${IconUri}, + + [string[]] + ${ReleaseNotes}, + + [ValidateNotNullOrEmpty()] + [string] + ${PrivateData}, -#> + [switch] + ${PassThru}, + + [switch] + ${Force}) + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # Parameter translations + if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } + # Translate from string[] to string + if ( $PSBoundParameters['ReleaseNotes'] ) { + $PSBoundParameters['ReleaseNotes'] = $PSBoundParameters['ReleaseNotes'] -join "; " + } + # Parameter Deletions (unsupported in v3) + if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } + if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } + if ( $PSBoundParameters['WhatIf'] ) { $null = $PSBoundParameters.Remove('WhatIf') } + if ( $PSBoundParameters['Confirm'] ) { $null = $PSBoundParameters.Remove('Confirm') } + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } + + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Update-ScriptFileInfo + .ForwardHelpCategory Function + #> } $functionsToExport = @( @@ -2588,17 +2699,20 @@ $functionsToExport = @( "Get-PSRepository", "Install-Module", "Install-Script", + "New-ScriptFileInfo", "Publish-Module", "Publish-Script", "Register-PSRepository", "Save-Module", "Save-Script", "Set-PSRepository", + "Test-ScriptFileInfo", "Uninstall-Module", "Uninstall-Script", "Unregister-PSRepository", "Update-Module", - "Update-Script" + "Update-Script", + "Update-ScriptFileInfo" ) -export-ModuleMember -Function $functionsToExport +export-ModuleMember -Function $functionsToExport \ No newline at end of file From bdb599f8a1ec663b3dd5a718bbc0989c62af36ba Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 3 May 2023 15:37:12 -0700 Subject: [PATCH 12/74] Update compat tests --- Test/FindPSResource.Tests.ps1 | 201 +++++ Test/GetInstalledPSResource.Tests.ps1 | 141 ++++ Test/GetPSResourceRepository.Tests.ps1 | 125 +++ Test/InstallPSResource.Tests.ps1 | 406 ++++++++++ Test/NewPSScriptFile.Tests.ps1 | 251 ++++++ Test/PSGetTestUtils.psm1 | 734 ++++++++++++++++++ Test/PublishPSResource.Tests.ps1 | 371 +++++++++ Test/RegisterPSResourceRepository.Tests.ps1 | 171 ++++ Test/SavePSResource.Tests.ps1 | 159 ++++ Test/SetPSResourceRepository.ps1 | 122 +++ Test/TestPSScriptFile.Tests.ps1 | 88 +++ Test/UninstallPSResource.Tests.ps1 | 298 +++++++ Test/UnregisterPSResourceRepository.Tests.ps1 | 91 +++ Test/UpdatePSResource.Tests.ps1 | 358 +++++++++ Test/UpdatePSScriptFileInfo.Tests.ps1 | 314 ++++++++ 15 files changed, 3830 insertions(+) create mode 100644 Test/FindPSResource.Tests.ps1 create mode 100644 Test/GetInstalledPSResource.Tests.ps1 create mode 100644 Test/GetPSResourceRepository.Tests.ps1 create mode 100644 Test/InstallPSResource.Tests.ps1 create mode 100644 Test/NewPSScriptFile.Tests.ps1 create mode 100644 Test/PSGetTestUtils.psm1 create mode 100644 Test/PublishPSResource.Tests.ps1 create mode 100644 Test/RegisterPSResourceRepository.Tests.ps1 create mode 100644 Test/SavePSResource.Tests.ps1 create mode 100644 Test/SetPSResourceRepository.ps1 create mode 100644 Test/TestPSScriptFile.Tests.ps1 create mode 100644 Test/UninstallPSResource.Tests.ps1 create mode 100644 Test/UnregisterPSResourceRepository.Tests.ps1 create mode 100644 Test/UpdatePSResource.Tests.ps1 create mode 100644 Test/UpdatePSScriptFileInfo.Tests.ps1 diff --git a/Test/FindPSResource.Tests.ps1 b/Test/FindPSResource.Tests.ps1 new file mode 100644 index 0000000..2c3b34a --- /dev/null +++ b/Test/FindPSResource.Tests.ps1 @@ -0,0 +1,201 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Find-PSResource' -tags 'CI' { + + BeforeAll{ + $PSGalleryName = Get-PSGalleryName + $testModuleName = "test_module" + $testScriptName = "test_script" + $testModuleName2 = "testmodule99" + $commandName = "Get-TargetResource" + $dscResourceName = "SystemLocale" + $parentModuleName = "SystemLocaleDsc" + Get-NewPSResourceRepositoryFile + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + It "Find-Module without any parameter values" { + $psgetItemInfo = Find-Module -Repository PSGallery + $psgetItemInfo.Count | Should -BeGreaterOrEqual 1 + } + + It "Find a specific module" { + $res = Find-Module "testModule99" -Repository PSGallery + $res | Should -Not -BeNullOrEmpty + $res.Name | Should -Be "testModule99" + } + + It "Find-Module with range wildcards" { + $res = Find-Module -Name "TestModule9*" -Repository PSGallery + $res | Should -Not -BeNullOrEmpty + $res.Name | Should -Be "TestModule99" + } + + It "Find not available module with wildcards" { + $res = Find-Module -Name "TestModule5test*" -Repository PSGallery + $res | Should -BeNullOrEmpty + } + + It "Find-Module with min version" { + $res = Find-Module TestModule99 -MinimumVersion 0.0.3 -Repository PSGallery + $res.Name | Should -Contain "TestModule99" + $res | ForEach-Object { $_.Version | Should -BeGreaterOrEqual ([System.Version]"0.0.3") } + } + + It "Find-Module with min version not available" { + $res = Find-Module TestModule99 -MinimumVersion 10.0 -Repository PSGallery + $res | Should -BeNullOrEmpty + } + + It "Find-Module with required version not available" { + $res = Find-Module TestModule99 -RequiredVersion 12.0 -Repository PSGallery -ErrorVariable ev -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + } + + It "Find-Module with required version" { + $res = Find-Module TestModule99 -RequiredVersion 0.0.2 -Repository PSGallery + $res | Should -Not -BeNullOrEmpty + $res.Name | Should -Be "TestModule99" + $res.Version | Should -Be ([System.Version]"0.0.2") + } + + It "Find-Module with multiple module names and required version" { + $res = Find-Module TestModuleWithDependencyB, TestModuleWithDependencyC -RequiredVersion 3.0 -Repository PSGallery + $res | Should -HaveCount 2 + $res | ForEach-Object { $_.Version | Should -Be ([System.Version]"3.0") } + } + + It "Find-Module with module name and minimum version" { + $res = Find-Module TestModule99 -MinimumVersion 0.5 -Repository PSGallery + $res | Should -HaveCount 0 + } + + It "Find-Module with multiple module names and minimum version" { + $res = Find-Module TestModule99, TestModuleWithDependencyB -MinimumVersion 0.5 -Repository PSGallery + $res | Should -HaveCount 2 + $res.Name | Should -Not -Contain "TestModule99" + $res | ForEach-Object { $_.Version | Should -BeGreaterOrEqual ([System.Version]"0.5") } + } + + It "Find-Module with wildcard name and minimum version" { + $res = Find-Module TestModule9* -MinimumVersion 0.0.3 -Repository PSGallery -ErrorAction SilentlyContinue -ErrorVariable err + $err | Should -Not -BeNullOrEmpty + $res | Should -BeNullOrEmpty + } + + It "Find-Module with multinames" { + $res = Find-Module TestModuleWithDependencyB, TestModuleWithDependencyC, TestModuleWithDependencyD -Repository PSGallery + $res | Should -HaveCount 3 + } + + It "Find-Module with all versions" { + $res = Find-Module TestModule99 -Repository PSGallery -AllVersions + $res.Count | Should -BeGreaterThan 1 + } + + It "Find-DscResource with single resource name" { + $res = Find-DscResource -Name SystemLocale -Repository $PSGalleryName + Foreach ($dscresource in $res) { + $dscresource.Names | Should -Be "SystemLocale" + $dscresource.ParentResource | Should -Be ("ComputerManagementDsc" -or "SystemLocaleDsc") + } + } + + It "Find-DscResource with two resource names" { + $res = Find-DscResource -Name "SystemLocale", "MSFT_PackageManagement" -Repository $PSGalleryName + Foreach ($dscresource in $res) { + $dscresource.Names | Should -Be ("SystemLocale" -or "MSFT_PackageManagement") + $dscresource.ParentResource | Should -Be ("ComputerManagementDsc" -or "SystemLocaleDsc" -or "PackageManagement") + } + } + + It "Find-Command with single command name" { + $res = Find-Command -Name $commandName -Repository $PSGalleryName + $res | ForEach-Object { $_.Names | Should -Be $commandName } + } + + It "Find-Module with IncludeDependencies" { + $ModuleName = "TestModuleWithDependencyE" + + $res = Find-Module -Name $ModuleName -IncludeDependencies + $res.Count | Should -BeGreaterOrEqual 2 + } + + It "find module given specific Name, Version null" { + $res = Find-Module -Name $testModuleName2 -Repository $PSGalleryName + $res.Name | Should -Be $testModuleName2 + $res.Version | Should -Be "0.0.93" + } + + It "should not find module given nonexistant Name" { + $res = Find-Module -Name NonExistantModule -Repository $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "FindNameResponseConversionFail,Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource" + $res | Should -BeNullOrEmpty + } + + It "find script(s) given wildcard Name" { + $foundScript = $False + $res = Find-Script -Name "test_scri*" -Repository $PSGalleryName + $res | Should -HaveCount 1 + foreach ($item in $res) + { + if ($item.Type -eq "Script") + { + $foundScript = $true + } + } + + $foundScript | Should -BeTrue + } + + It "find all versions of module when given specific Name, Version not null --> '*'" { + $res = Find-Module -Name $testModuleName2 -AllVersions -Repository $PSGalleryName + $res | ForEach-Object { + $_.Name | Should -Be $testModuleName2 + } + + $res.Count | Should -BeGreaterThan 1 + } + + It "find module with latest (including prerelease) version given Prerelease parameter" { + # test_module resource's latest version is a prerelease version, before that it has a non-prerelease version + $res = Find-Module -Name $testModuleName2 -Repository $PSGalleryName + $res.Version | Should -Be "0.0.93" + + $resPrerelease = Find-Module -Name $testModuleName2 -AllowPrerelease -Repository $PSGalleryName + $resPrerelease.Version | Should -Be "1.0.0" + $resPrerelease.Prerelease | Should -Be "beta2" + } + + It "find script from PSGallery" { + $resScript = Find-Script -Name $testScriptName -Repository $PSGalleryName + $resScript.Name | Should -Be $testScriptName + $resScriptType = Out-String -InputObject $resScript.Type + $resScriptType.Replace(",", " ").Split() | Should -Contain "Script" + } + + It "find module from PSGallery" { + $resModule = Find-Module -Name $testModuleName -Repository $PSGalleryName + $resModule.Name | Should -Be $testModuleName + $resModuleType = Out-String -InputObject $resModule.Type + $resModuleType.Replace(",", " ").Split() | Should -Contain "Module" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/GetInstalledPSResource.Tests.ps1 b/Test/GetInstalledPSResource.Tests.ps1 new file mode 100644 index 0000000..c627626 --- /dev/null +++ b/Test/GetInstalledPSResource.Tests.ps1 @@ -0,0 +1,141 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Get-InstalledPSResource' -tags 'CI' { + + BeforeAll{ + $PSGalleryName = Get-PSGalleryName + $testModuleName = "testmodule99" + $testScriptName = "test_script" + Get-NewPSResourceRepositoryFile + Set-PSResourceRepository PSGallery -Trusted + + Install-PSResource -Name $testModuleName -Repository $PSGalleryName + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -Version "0.0.2" + Install-PSResource -Name $testModuleName -Repository $PSGalleryName -Version "0.0.3" + Install-PSResource -Name $testScriptName -Repository $PSGalleryName -SkipDependencyCheck + } + + AfterAll { + Uninstall-PSResource -Name $testModuleName -Version "*" -ErrorAction SilentlyContinue + Uninstall-PSResource -Name $testScriptName -Version "*" -ErrorAction SilentlyContinue + Get-RevertPSResourceRepositoryFile + } + + It "Get-InstalledModule with MinimumVersion available" { + $res = Get-InstalledModule -Name $testModuleName -MinimumVersion "0.0.1" + $res.Count | Should -BeGreaterThan 1 + foreach ($pkg in $res) + { + $pkg.Version | Should -BeGreaterOrEqual ([System.Version] "0.0.1") + } + } + + It "Get-InstalledScript with MinimumVersion available" { + $res = Get-InstalledScript -Name $testScriptName -MinimumVersion "1.0.0" + $res.Count | Should -BeGreaterOrEqual 1 + foreach ($pkg in $res) + { + $pkg.Version | Should -BeGreaterOrEqual ([System.Version] "1.0.0") + } + } + + It "Get-InstalledModule with MinimumVersion not available" { + $res = Get-InstalledModule -Name $testModuleName -MinimumVersion "1.0.0" + $res | Should -HaveCount 0 + } + + It "Get-InstalledModule with min/max range" { + $res = Get-InstalledModule -Name $testModuleName -MinimumVersion "0.0.15" -MaximumVersion "0.0.25" + foreach ($pkg in $res) + { + $pkg.Version | Should -BeGreaterOrEqual ([System.Version] "0.0.2") + } + } + + It "Get-InstalledModule with -RequiredVersion" { + $version = "0.0.2" + $res = Get-InstalledModule -Name $testModuleName -RequiredVersion $version + $res.Version | Should -Be $version + } + + It "Get prerelease version module when version with correct prerelease label is specified" { + Install-PSResource -Name $testModuleName -Version "1.0.0-beta2" -Repository $PSGalleryName + $res = Get-InstalledModule -Name $testModuleName -RequiredVersion "1.0.0" + $res | Should -BeNullOrEmpty + $res = Get-InstalledModule -Name $testModuleName -RequiredVersion "1.0.0-beta2" + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "1.0.0" + $res.Prerelease | Should -Be "beta2" + } + + It "Get prerelease version script when version with correct prerelease label is specified" { + Install-PSResource -Name $testScriptName -Version "3.0.0-alpha" -Repository $PSGalleryName -TrustRepository + $res = Get-InstalledScript -Name $testScriptName -RequiredVersion "3.0.0" + $res | Should -BeNullOrEmpty + $res = Get-InstalledScript -Name $testScriptName -RequiredVersion "3.0.0-alpha" + $res.Name | Should -Be $testScriptName + $res.Version | Should -Be "3.0.0" + $res.Prerelease | Should -Be "alpha" + } + + It "Get-InstalledModule with Wildcard" { + $module = Get-InstalledModule -Name "testmodule9*" + $module.Count | Should -BeGreaterOrEqual 3 + } + + It "Get-InstalledModule with Wildcard" { + $module = Get-InstalledScript -Name "test_scri*" + $module.Count | Should -BeGreaterOrEqual 1 + } + + It "Get modules without any parameter values" { + $pkgs = Get-InstalledScript + $pkgs.Count | Should -BeGreaterThan 1 + } + + It "Get scripts without any parameter values" { + $pkgs = Get-InstalledModule + $pkgs.Count | Should -BeGreaterThan 1 + } + + It "Get specific module resource by name" { + $pkg = Get-InstalledModule -Name $testModuleName + $pkg.Name | Should -Contain $testModuleName + } + + It "Get specific script resource by name" { + $pkg = Get-InstalledScript -Name $testScriptName + $pkg.Name | Should -Be $testScriptName + } + + It "Get resource when given Name to " { + $pkgs = Get-InstalledModule -Name "*estmodul*" + $pkgs.Name | Should -Contain $testModuleName + } + + It "Get resource when given Name to " -TestCases @( + @{Name="*estmodul*"; Reason="validate name, with wildcard at beginning and end of name: *estmodul*"}, + @{Name="testmod*"; Reason="validate name, with wildcard at end of name: testmod*"}, + @{Name="*estmodule99"; Reason="validate name, with wildcard at beginning of name: *estmodule99"}, + @{Name="tes*ule99"; Reason="validate name, with wildcard in middle of name: tes*ule99"} + ) { + param($Name) + $pkgs = Get-InstalledModule -Name $Name + $pkgs.Name | Should -Contain $testModuleName + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/GetPSResourceRepository.Tests.ps1 b/Test/GetPSResourceRepository.Tests.ps1 new file mode 100644 index 0000000..ead4981 --- /dev/null +++ b/Test/GetPSResourceRepository.Tests.ps1 @@ -0,0 +1,125 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe "Test CompatPowerShellGet: Get-PSResourceRepository" -tags 'CI' { + BeforeEach { + $TestRepoName1 = "testRepository" + $TestRepoName2 = "testRepository2" + $TestRepoName3 = "testRepository3" + Get-NewPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path) + Get-NewTestDirs($tmpDirPaths) + } + AfterEach { + Get-RevertPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path) + Get-RemoveTestDirs($tmpDirPaths) + } + + It "get single already registered repo" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + $res = Get-PSRepository -Name $TestRepoName1 + $res | Should -Not -BeNullOrEmpty + $res.Name | Should -Be $TestRepoName1 + } + + It "get all repositories matching single wildcard name" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Register-PSResourceRepository -Name $TestRepoName2 -Uri $tmpDir2Path + Register-PSResourceRepository -Name $TestRepoName3 -Uri $tmpDir3Path + $res = Get-PSRepository -Name "testReposit*" + foreach ($entry in $res) { + $entry.Name | Should -Match "testReposit" + } + } + + It "get all repositories matching multiple wildcard names" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Register-PSResourceRepository -Name $TestRepoName2 -Uri $tmpDir2Path + Register-PSResourceRepository -Name "MyGallery" -Uri $tmpDir3Path + + $res = Get-PSRepository -Name "testReposit*","*Gallery" + foreach ($entry in $res) { + $entry.Name | Should -Match "testReposit|Gallery" + } + } + It "get all repositories matching multiple valid names provided" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Register-PSResourceRepository -Name "MyGallery" -Uri $tmpDir2Path + + $res = Get-PSRepository -Name $TestRepoName1,"MyGallery" + foreach ($entry in $res) { + $entry.Name | Should -BeIn $TestRepoName1,"MyGallery" + } + } + + It "not get repository that hasn't been registered/invalid name" { + $nonRegisteredRepoName = "nonRegisteredRepository" + $res = Get-PSRepository -Name $nonRegisteredRepoName -ErrorVariable err -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository" + } + + It "given invalid and valid Names, get valid ones and write error for non valid ones" { + $nonRegisteredRepoName = "nonRegisteredRepository" + + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Register-PSResourceRepository -Name $TestRepoName2 -Uri $tmpDir2Path + + $res = Get-PSRepository -Name $TestRepoName1,$nonRegisteredRepoName,$TestRepoName2 -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository" + + # should have successfully got the other valid/registered repositories with no error + foreach ($entry in $res) { + $entry.Name | Should -BeIn $TestRepoName1,$TestRepoName2 + } + } + + It "given invalid and valid CredentialInfo, get valid ones and write error for non valid ones" { + Get-NewPSResourceRepositoryFileWithCredentialInfo + + $res = Get-PSRepository -Name "localtestrepo*" -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository" + + # should have successfully got the other valid/registered repositories with no error + foreach ($entry in $res) { + $entry.Name | Should -BeIn "localtestrepo1","localtestrepo2" + } + } + + It "throw error and get no repositories when provided null Name" { + # $errorMsg = "Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + {Get-PSRepository -Name $null -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Get-PSRepository" + } + + It "throw error and get no repositories when provided empty string Name" { + # $errorMsg = "Cannot validate argument on parameter 'Name'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again." + {Get-PSRepository -Name "" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Get-PSRepository" + } + + It "find all repositories if no Name provided" { + $res = Get-PSRepository + $res.Count | Should -BeGreaterThan 0 + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/InstallPSResource.Tests.ps1 b/Test/InstallPSResource.Tests.ps1 new file mode 100644 index 0000000..1fdad79 --- /dev/null +++ b/Test/InstallPSResource.Tests.ps1 @@ -0,0 +1,406 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Install-PSResource' -tags 'CI' { + + BeforeAll { + $PSGalleryName = Get-PSGalleryName + $PSGalleryUri = Get-PSGalleryLocation + $NuGetGalleryName = Get-NuGetGalleryName + $testModuleName = "test_module" + $testModuleName2 = "TestModule99" + $testScriptName = "test_script" + $RequiredResourceJSONFileName = "TestRequiredResourceFile.json" + $RequiredResourcePSD1FileName = "TestRequiredResourceFile.psd1" + Get-NewPSResourceRepositoryFile + Register-LocalRepos + + Set-PSResourceRepository -Name PSGallery -Trusted + Unregister-PSResourceRepository -Name "psgettestlocal" + } + + AfterEach { + Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithDependencyB", "TestModuleWithDependencyC","TestModuleWithDependencyD", "TestModuleWithDependencyF", ` + "newTestModule", "test_script", "RequiredModule1", "RequiredModule2", "RequiredModule3", "RequiredModule4", "RequiredModule5" -SkipDependencyCheck -ErrorAction SilentlyContinue -Version "*" + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + It "Install-Module testmodule99 should return" { + Install-Module -Name $testModuleName2 -Repository PSGallery + + $res = Get-InstalledPSResource -Name $testModuleName2 + $res.Name | Should be $testModuleName2 + } + + It "Install-Module testmodule99 -PassThru should return output" { + Install-Module -Name $testModuleName2 -Repository PSGallery -PassThru + + $res = Get-InstalledPSResource -Name $testModuleName2 + $res.Name | Should be $testModuleName2 + } + + It "Install-Module should not install with wildcard" { + Install-Module -Name "testmodule9*" -Repository PSGallery -ErrorAction SilentlyContinue + + $res = Get-InstalledPSResource -Name $testModuleName2 + $res | Should -HaveCount 0 + } + + It "Install-Module with version params" { + Install-Module $testModuleName2 -MinimumVersion 0.0.1 -MaximumVersion 0.0.9 -Repository PSGallery + + $res = Get-InstalledPSResource -Name $testModuleName2 + $res.Name | Should be $testModuleName2 + $res.Version | Should be "0.0.9" + } + + It "Install-Module multiple names" { + Install-Module "TestModuleWithDependencyB", "testmodule99" -Repository PSGallery + + $res = Get-InstalledPSResource "TestModuleWithDependencyB", "testmodule99" + $res.Count | Should -BeGreaterOrEqual 2 + } + + It "Install-Module multiple names with RequiredVersion" { + Install-Module "newTestModule", "testmodule99" -RequiredVersion 0.0.1 -Repository PSGallery + + $res = Get-InstalledPSResource "newTestModule", "testmodule99" + $res | Should -HaveCount 2 + } + + It "Install-Multiple names with MinimumVersion" { + Install-Module "TestModuleWithDependencyB", "TestModuleWithDependencyD" -MinimumVersion 1.0 -Repository PSGallery + + $res = Get-InstalledPSResource "TestModuleWithDependencyB", "TestModuleWithDependencyD" + $res | Should -HaveCount 2 + foreach ($pkg in $res) + { + $pkg.Version | Should -BeGreaterOrEqual ([System.Version] "1.0") + } + } + + It "Install-Module with MinimumVersion" { + Install-Module $testModuleName2 -MinimumVersion 0.0.3 -Repository PSGallery + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + $res.Version | Should -BeGreaterOrEqual ([System.Version]"0.0.3") + } + + It "Install-Module with RequiredVersion" { + Install-Module $testModuleName2 -RequiredVersion 0.0.3 -Repository PSGallery + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + $res.Version | Should -Be ([System.Version]"0.0.3") + } + + It "Install-Module should fail if RequiredVersion is already installed" { + Install-Module $testModuleName2 -RequiredVersion 0.0.93 -Repository PSGallery + + Install-Module $testModuleName2 -RequiredVersion 0.0.93 -WarningVariable wv -Repository PSGallery + $wv[0] | Should -Be "Resource 'testmodule99' with version '0.0.93' is already installed. If you would like to reinstall, please run the cmdlet again with the -Reinstall parameter" + } + + It "Install-Module should fail if MinimumVersion is already installed" { + Install-Module $testModuleName2 -RequiredVersion 0.0.93 -Repository PSGallery + + Install-Module $testModuleName2 -MinimumVersion 0.0.2 -WarningVariable wv -Repository PSGallery + $wv[0] | Should -Be "Resource 'testmodule99' with version '0.0.93' is already installed. If you would like to reinstall, please run the cmdlet again with the -Reinstall parameter" + } + + It "Install-Module with -Force" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + Install-Module $testModuleName2 -RequiredVersion 0.0.93 -Force -Repository PSGallery + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 2 + $res.Version | Should -Contain ([System.Version]"0.0.91") + $res.Version | Should -Contain ([System.Version]"0.0.93") } + + It "Install-Module same version with -Force" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Force -Repository PSGallery + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + $res.Version | Should -Contain ([System.Version]"0.0.91") + } + + It "Install-Module with nonexistent module" { + Install-Module NonExistentModule -Repository PSGallery -ErrorVariable ev -ErrorAction SilentlyContinue + + $ev | Should -HaveCount 1 + } + + It "Install-Module with PipelineInput" { + Find-Module $testModuleName2 -Repository PSGallery | Install-Module + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + } + + It "Install-Module with PipelineInput" { + Find-Module $testModuleName2 -Repository PSGallery | Install-Module + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + } + + It "Install-Module multiple modules with PipelineInput" { + Find-Module $testModuleName2, "newTestModule" -Repository PSGallery | Install-Module + $res = Get-InstalledPSResource $testModuleName2 , "newTestModule" + $res | Should -HaveCount 2 + } + + It "Install-Module multiple module using InputObjectParam" -Pending { + $items = Find-Module $testModuleName2 -Repository PSGallery + Install-Module -InputObject $items + $res = Get-InstalledPSResource $testModuleName2 + $res.Count | Should -BeGreaterOrEqual 1 + } + + It "InstallToCurrentUserScope" { + Install-Module $testModuleName2 -Scope CurrentUser -Repository PSGallery + + $mod = Get-Module $testModuleName2 -ListAvailable + $mod.ModuleBase.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) + } + + It "Install-Module using Find-DscResource output" { + $moduleName = 'SystemLocaleDsc' + Find-DscResource -Name 'SystemLocale' -Repository PSGallery | Install-Module + $res = Get-Module $moduleName -ListAvailable + $res.Name | Should -Be $moduleName + } + + It "Install-Module using Find-Command Output" { + $cmd = "Get-WUJob" + $module = "PSWindowsUpdate" + Find-Command -Name $cmd | Install-Module + + $res = Get-Module $module -ListAvailable + $res.Name | Should -Contain $module + } + + It "Install-Module with Dependencies" { + $parentModule = "TestModuleWithDependencyC" + $childModule1 = "TestModuleWithDependencyB" + $childModule2 = "TestModuleWithDependencyD" + $childModule3 = "TestModuleWithDependencyF" + Install-Module $parentModule -Repository PSGallery + + $res = Get-InstalledPSResource $parentModule, $childModule1, $childModule2, $childModule3 + $res.Count | Should -BeGreaterOrEqual 4 + } + + $testCases = @{Name="*"; ErrorId="NameContainsWildcard"}, + @{Name="Test_Module*"; ErrorId="NameContainsWildcard"}, + @{Name="Test?Module","Test[Module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} + + It "Should not install resource with wildcard in name" -TestCases $testCases { + param($Name, $ErrorId) + Install-Module -Name $Name -Repository $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + } + + It "Install specific module resource by name" { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "0.0.93" + } + + It "Install specific script resource by name" { + Install-Script -Name $testScriptName -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testScriptName + $pkg.Name | Should -Be $testScriptName + $pkg.Version | Should -Be "3.5.0.0" + } + + It "Install multiple resources by name" { + $pkgNames = @($testModuleName, $testModuleName2) + Install-Module -Name $pkgNames -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $pkgNames + $pkg.Name | Should -Be $pkgNames + } + + It "Should not install module given nonexistant name" { + Install-Module -Name "NonExistantModule" -Repository $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + $pkg = Get-InstalledPSResource "NonExistantModule" + $pkg.Name | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + } + + It "Should install module given name and exact version" { + Install-Module -Name $testModuleName2 -RequiredVersion "0.0.2" -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "0.0.2" + } + + It "Install module with latest (including prerelease) version given Prerelease parameter" { + Install-Module -Name $testModuleName2 -AllowPrerelease -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "1.0.0" + $pkg.Prerelease | Should -Be "beta2" + } + + It "Install module via InputObject by piping from Find-PSresource" { + Find-PSResource -Name $testModuleName2 -Repository $PSGalleryName | Install-Module + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.Version | Should -Be "0.0.93" + } + + It "Install module under specified in PSModulePath" { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + ($env:PSModulePath).Contains($pkg.InstalledLocation) + } + + # Windows only + It "Install module under CurrentUser scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Windows only + It "Install module under AllUsers scope - Windows only" -Skip:(!((Get-IsWindows) -and (Test-IsAdmin))) { + Install-Module -Name "testmodule99" -Repository $PSGalleryName -Scope AllUsers + $pkg = Get-Module "testmodule99" -ListAvailable + $pkg.Name | Should -Be "testmodule99" + $pkg.Path.ToString().Contains("Program Files") + } + + # Windows only + It "Install module under no specified scope - Windows only" -Skip:(!(Get-IsWindows)) { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.InstalledLocation.ToString().Contains("Documents") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install module under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName -Scope CurrentUser + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Install module under no specified scope - Unix only" -Skip:(Get-IsWindows) { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + $pkg.InstalledLocation.ToString().Contains("$env:HOME/.local") | Should -Be $true + } + + It "Should not install module that is already installed" { + Install-Module -Name $testModuleName2 -Repository $PSGalleryName + $pkg = Get-InstalledPSResource $testModuleName2 + $pkg.Name | Should -Be $testModuleName2 + Install-Module -Name $testModuleName2 -Repository $PSGalleryName -WarningVariable WarningVar -warningaction SilentlyContinue + $WarningVar | Should -Not -BeNullOrEmpty + } + + It "Install resource that requires accept license with -AcceptLicense flag" -Pending { + Install-Module -Name "testModuleWithlicense" -Repository $PSGalleryName -AcceptLicense + $pkg = Get-InstalledPSResource "testModuleWithlicense" + $pkg.Name | Should -Be "testModuleWithlicense" + $pkg.Version | Should -Be "0.0.3.0" + } + + It "Install resource with cmdlet names from a module already installed (should clobber)" { + Install-Module -Name "ClobberTestModule1" -Repository $PSGalleryName + $pkg = Get-InstalledPSResource "ClobberTestModule1" + $pkg.Name | Should -Be "ClobberTestModule1" + $pkg.Version | Should -Be "0.0.1" + + Install-Module -Name "ClobberTestModule2" -Repository $PSGalleryName -AllowClobber + $pkg = Get-InstalledPSResource "ClobberTestModule2" + $pkg.Name | Should -Be "ClobberTestModule2" + $pkg.Version | Should -Be "0.0.1" + } + + It "Install module using -WhatIf, should not install the module" { + Install-Module -Name $testModuleName2 -WhatIf + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -BeNullOrEmpty + } + + It "Validates that a module with module-name script files (like Pester) installs under Modules path" { + Install-Module -Name "testModuleWithScript" -Repository $PSGalleryName + + $res = Get-InstalledPSResource "testModuleWithScript" + $res.InstalledLocation.ToString().Contains("Modules") | Should -Be $true + } + + It "Install module using -NoClobber, should throw clobber error and not install the module" -Pending { + Install-Module -Name "ClobberTestModule1" -Repository $PSGalleryName + + $res = Get-InstalledPSResource "ClobberTestModule1" + $res.Name | Should -Be "ClobberTestModule1" + + Install-Module -Name "ClobberTestModule2" -Repository $PSGalleryName -TrustRepository -NoClobber -ErrorAction SilentlyContinue -ErrorVariable ev + $ev | Should -be "CommandAlreadyExists,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + } + + It "Install PSResourceInfo object piped in" { + Find-PSResource -Name $testModuleName2 -Version "0.0.2" -Repository $PSGalleryName | Install-Module + $res = Get-InstalledPSResource -Name $testModuleName2 + $res.Name | Should -Be $testModuleName2 + $res.Version | Should -Be "0.0.2" + } + + # Install module 1.4.3 (is authenticode signed and has catalog file) + # Should install successfully + It "Install modules with catalog file using publisher validation" -Skip:(!(Get-IsWindows)) { + $PackageManagement = "PackageManagement" + Install-Module -Name $PackageManagement -RequiredVersion "1.4.3" -Repository $PSGalleryName + + $res1 = Get-InstalledPSResource $PackageManagement -Version "1.4.3" + $res1.Name | Should -Be $PackageManagement + $res1.Version | Should -Be "1.4.3" + } + + # Install 1.4.4.1 (with incorrect catalog file) + # Should FAIL to install the module + It "Install module with incorrect catalog file" -Skip:(!(Get-IsWindows)) { + { Install-Module -Name $PackageManagement -RequiredVersion "1.4.4.1" -Repository $PSGalleryName } | Should -Throw -ErrorId "ParameterArgumentValidationError,Install-Module" + } + + # Install script that is signed + # Should install successfully + It "Install script that is authenticode signed" -Skip:(!(Get-IsWindows)) { + Install-Script -Name "Install-VSCode" -RequiredVersion "1.4.2" -Repository $PSGalleryName + + $res1 = Get-InstalledPSResource "Install-VSCode" -Version "1.4.2" + $res1.Name | Should -Be "Install-VSCode" + $res1.Version | Should -Be "1.4.2" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/NewPSScriptFile.Tests.ps1 b/Test/NewPSScriptFile.Tests.ps1 new file mode 100644 index 0000000..e585cf9 --- /dev/null +++ b/Test/NewPSScriptFile.Tests.ps1 @@ -0,0 +1,251 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe "Test CompatPowerShellGet: New-PSScriptFile" -tags 'CI' { + BeforeAll { + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDirPaths = @($tmpDir1Path) + Get-NewTestDirs($tmpDirPaths) + } + BeforeEach { + $script:PSScriptInfoName = "test_script" + $script:testScriptFilePath = Join-Path -Path $tmpDir1Path -ChildPath "$script:PSScriptInfoName.ps1" + } + AfterEach { + if (Test-Path -Path $script:testScriptFilePath) + { + Remove-Item $script:testScriptFilePath + } + } + + It "Create .ps1 file with minimal required fields" { + $description = "Test description" + New-ScriptFileInfo -Path $script:testScriptFilePath -Description $description + Test-PSScriptFile -Path $script:testScriptFilePath | Should -BeTrue + } + + It "Create .ps1 file with relative path" { + $relativeCurrentPath = Get-Location + $scriptFilePath = Join-Path -Path $relativeCurrentPath -ChildPath "$script:PSScriptInfoName.ps1" + + $description = "Test description" + New-ScriptFileInfo -Path $scriptFilePath -Description $description + + Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + Remove-Item -Path $scriptFilePath + } + + It "Create new .ps1 given Version parameter" { + $version = "2.0.0.0" + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Version $version -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($version) | Should -BeTrue + $results.Contains(".VERSION $version") | Should -BeTrue + } + + It "Create new .ps1 given Guid parameter" { + $guid = [guid]::NewGuid() + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Guid $guid -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($guid) | Should -BeTrue + $results.Contains(".GUID $guid") | Should -BeTrue + } + + It "Create new .ps1 given Author parameter" { + $author = "Test Author" + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Author $author -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($author) | Should -BeTrue + $results.Contains(".AUTHOR $author") | Should -BeTrue + } + + It "Create new .ps1 given Description parameter" { + $description = "PowerShellGet test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($description) | Should -BeTrue + $results -like "*.DESCRIPTION$script:newline*$description*" | Should -BeTrue + } + + It "Create new .ps1 given CompanyName parameter" { + $companyName = "Microsoft" + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -CompanyName $companyName -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($companyName) | Should -BeTrue + $results.Contains(".COMPANYNAME $companyname") | Should -BeTrue + } + + It "Create new .ps1 given Copyright parameter" { + $copyright = "(c) Test Corporation" + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Copyright $copyright -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($copyright) | Should -BeTrue + $results.Contains(".COPYRIGHT $copyright") | Should -BeTrue + } + + It "Create new .ps1 given RequiredModules parameter" { + $requiredModuleName = 'TestModuleName' + $requiredModuleVersion = '1.0.0.0' + $RequiredModules = @(@{ModuleName = $requiredModuleName; ModuleVersion = $requiredModuleVersion }) + + $description = "Test description" + + New-ScriptFileInfo -Path $script:testScriptFilePath -RequiredModules $RequiredModules -Description $Description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($requiredModuleName) | Should -BeTrue + $results.Contains($requiredModuleVersion) | Should -BeTrue + $results -like "*#Requires -Module @{ModuleVersion = '$requiredModuleVersion'; ModuleName = '$requiredModuleName'}*" | Should -BeTrue + } + + It "Create new .ps1 given ReleaseNotes parameter" { + $description = "Test Description" + $releaseNotes = "Release notes for script." + + New-ScriptFileInfo -Path $script:testScriptFilePath -ReleaseNotes $releaseNotes -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($releaseNotes) | Should -BeTrue + $results -like "*.RELEASENOTES$script:newline*$ReleaseNotes*" | Should -BeTrue + } + + It "Create new .ps1 given Tags parameter" { + $description = "Test Description" + $tag1 = "tag1" + $tag2 = "tag2" + + New-ScriptFileInfo -Path $script:testScriptFilePath -Tags $tag1, $tag2 -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($tag1) | Should -BeTrue + $results.Contains($tag2) | Should -BeTrue + $results.Contains(".TAGS $tag1 $tag2") | Should -BeTrue + } + + It "Create new .ps1 given ProjectUri parameter" { + $description = "Test Description" + $projectUri = "https://www.testprojecturi.com/" + + New-ScriptFileInfo -Path $script:testScriptFilePath -ProjectUri $projectUri -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($projectUri) | Should -BeTrue + $results.Contains(".PROJECTURI $projectUri") | Should -BeTrue + } + + It "Create new .ps1 given LicenseUri parameter" { + $description = "Test Description" + $licenseUri = "https://www.testlicenseuri.com/" + + New-ScriptFileInfo -Path $script:testScriptFilePath -LicenseUri $licenseUri -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($licenseUri) | Should -BeTrue + $results.Contains(".LICENSEURI $licenseUri") | Should -BeTrue + } + + It "Create new .ps1 given IconUri parameter" { + $description = "Test Description" + $iconUri = "https://www.testiconuri.com/" + + New-ScriptFileInfo -Path $script:testScriptFilePath -IconUri $iconUri -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($iconUri) | Should -BeTrue + $results.Contains(".ICONURI $iconUri") | Should -BeTrue + } + + It "Create new .ps1 given ExternalModuleDependencies parameter" { + $description = "Test Description" + $externalModuleDep1 = "ExternalModuleDep1" + $externalModuleDep2 = "ExternalModuleDep2" + + New-ScriptFileInfo -Path $script:testScriptFilePath -ExternalModuleDependencies $externalModuleDep1, $externalModuleDep2 -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($externalModuleDep1) | Should -BeTrue + $results.Contains($externalModuleDep2) | Should -BeTrue + $results -like "*.EXTERNALMODULEDEPENDENCIES*$externalModuleDep1*$externalModuleDep2*" | Should -BeTrue + } + + It "Create new .ps1 given RequiredScripts parameter" { + $description = "Test Description" + $requiredScript1 = "RequiredScript1" + $requiredScript2 = "RequiredScript2" + + New-ScriptFileInfo -Path $script:testScriptFilePath -RequiredScripts $requiredScript1, $requiredScript2 -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($requiredScript1) | Should -BeTrue + $results.Contains($requiredScript2) | Should -BeTrue + $results -like "*.REQUIREDSCRIPTS*$requiredScript1*$requiredScript2*" | Should -BeTrue + } + + It "Create new .ps1 given ExternalScriptDependencies parameter" { + $description = "Test Description" + $externalScriptDep1 = "ExternalScriptDep1" + $externalScriptDep2 = "ExternalScriptDep2" + + New-ScriptFileInfo -Path $script:testScriptFilePath -ExternalScriptDependencies $externalScriptDep1, $externalScriptDep2 -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($externalScriptDep1) | Should -BeTrue + $results.Contains($externalScriptDep2) | Should -BeTrue + $results -like "*.EXTERNALSCRIPTDEPENDENCIES*$externalScriptDep1*$externalScriptDep2*" | Should -BeTrue + } + + It "Create new .ps1 given PrivateData parameter" { + $description = "Test Description" + $privateData = @{"PrivateDataEntry1" = "PrivateDataValue1"} + New-ScriptFileInfo -Path $script:testScriptFilePath -PrivateData $privateData -Description $description + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($privateData) | Should -BeTrue + $results -like "*.PRIVATEDATA*$privateData*" | Should -BeTrue + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/PSGetTestUtils.psm1 b/Test/PSGetTestUtils.psm1 new file mode 100644 index 0000000..8b194f9 --- /dev/null +++ b/Test/PSGetTestUtils.psm1 @@ -0,0 +1,734 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$script:DotnetCommandPath = @() +$script:EnvironmentVariableTarget = @{ Process = 0; User = 1; Machine = 2 } +$script:EnvPATHValueBackup = $null + +$script:PowerShellGet = 'PowerShellGet' +$script:IsInbox = $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase) +$script:IsWindows = $IsWindows +if ($IsWindows -eq $null) { + $script:IsWindows = ($PSVersionTable.PSVersion.Major -eq 5) +} + +$script:IsLinux = (Get-Variable -Name IsLinux -ErrorAction Ignore) -and $IsLinux +$script:IsMacOS = (Get-Variable -Name IsMacOS -ErrorAction Ignore) -and $IsMacOS +$script:IsCoreCLR = $PSVersionTable.ContainsKey('PSEdition') -and $PSVersionTable.PSEdition -eq 'Core' + +$script:PSGalleryName = 'PSGallery' +$script:PSGalleryLocation = 'https://www.powershellgallery.com/api/v2' + +$script:NuGetGalleryName = 'NuGetGallery' +$script:NuGetGalleryLocation = 'https://api.nuget.org/v3/index.json' + +if($script:IsInbox) +{ + $script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell" +} +elseif($script:IsCoreCLR){ + if($script:IsWindows) { + $script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath 'PowerShell' + } + else { + $script:ProgramFilesPSPath = Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('SHARED_MODULES')) -Parent + } +} + +try +{ + $script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments") +} +catch +{ + $script:MyDocumentsFolderPath = $null +} + +if($script:IsInbox) +{ + $script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath) + { + Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell" + } + else + { + Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell" + } +} +elseif($script:IsCoreCLR) { + if($script:IsWindows) + { + $script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath) + { + Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath 'PowerShell' + } + else + { + Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath "Documents\PowerShell" + } + } + else + { + $script:MyDocumentsPSPath = Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('USER_MODULES')) -Parent + } +} + +$script:ProgramFilesModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Modules' +$script:MyDocumentsModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Modules' +$script:ProgramFilesScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Scripts' +$script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Scripts' +$script:TempPath = [System.IO.Path]::GetTempPath() + +if($script:IsWindows) { + $script:PSGetProgramDataPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramData -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' + $script:PSGetAppLocalPath = Microsoft.PowerShell.Management\Join-Path -Path $env:LOCALAPPDATA -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' +} else { + $script:PSGetProgramDataPath = Join-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('CONFIG')) -ChildPath 'PowerShellGet' + $script:PSGetAppLocalPath = Join-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('CACHE')) -ChildPath 'PowerShellGet' +} + +$script:ProgramDataExePath = Microsoft.PowerShell.Management\Join-Path -Path $script:PSGetProgramDataPath -ChildPath $script:NuGetExeName +$script:ApplocalDataExePath = Microsoft.PowerShell.Management\Join-Path -Path $script:PSGetAppLocalPath -ChildPath $script:NuGetExeName +$script:moduleSourcesFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:PSGetAppLocalPath -ChildPath 'PSRepositories.xml' + +# PowerShellGetFormatVersion will be incremented when we change the .nupkg format structure. +# PowerShellGetFormatVersion is in the form of Major.Minor. +# Minor is incremented for the backward compatible format change. +# Major is incremented for the breaking change. +$script:CurrentPSGetFormatVersion = "1.0" +$script:PSGetFormatVersionPrefix = "PowerShellGetFormatVersion_" + +function Test-IsAdmin { + [OutputType([bool])] + param() + + [System.Security.Principal.WindowsPrincipal]::new( + [Security.Principal.WindowsIdentity]::GetCurrent() + ).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) +} + +function Get-IsWindows { + return $script:IsWindows +} + +function Get-AllUsersModulesPath { + return $script:ProgramFilesModulesPath +} + +function Get-CurrentUserModulesPath { + return $script:MyDocumentsModulesPath +} + +function Get-AllUsersScriptsPath { + return $script:ProgramFilesScriptsPath +} + +function Get-CurrentUserScriptsPath { + return $script:MyDocumentsScriptsPath +} + +function Get-TempPath { + return $script:TempPath +} + +function Get-PSGetLocalAppDataPath { + return $script:PSGetAppLocalPath +} + +function Get-NuGetGalleryName +{ + return $script:NuGetGalleryName +} + +function Get-NuGetGalleryLocation +{ + return $script:NuGetGalleryLocation +} + +function Get-PSGalleryName +{ + return $script:PSGalleryName +} + +function Get-PSGalleryLocation { + return $script:PSGalleryLocation +} +function Get-NewTestDirs { + Param( + [string[]] + $listOfPaths + ) + foreach($path in $listOfPaths) + { + $null = New-Item -Path $path -ItemType Directory + } +} + +function Get-RemoveTestDirs { + Param( + [string[]] + $listOfPaths + ) + foreach($path in $listOfPaths) + { + if(Test-Path -Path $path) + { + Remove-Item -Path $path -Force -ErrorAction Ignore + } + } +} + +function Get-NewPSResourceRepositoryFile { + # register our own repositories with desired priority + $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PowerShellGet" + $originalXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" + $tempXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "temp.xml" + + if (Test-Path -Path $originalXmlFilePath) { + Copy-Item -Path $originalXmlFilePath -Destination $tempXmlFilePath + Remove-Item -Path $originalXmlFilePath -Force -ErrorAction Ignore + } + + if (! (Test-Path -Path $powerShellGetPath)) { + $null = New-Item -Path $powerShellGetPath -ItemType Directory -Verbose + } + + $fileToCopy = Join-Path -Path $PSScriptRoot -ChildPath "testRepositories.xml" + Copy-Item -Path $fileToCopy -Destination $originalXmlFilePath -Force -Verbose +} + +function Get-RevertPSResourceRepositoryFile { + $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PowerShellGet" + $originalXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" + $tempXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "temp.xml" + + if (Test-Path -Path $tempXmlFilePath) { + Remove-Item -Path $originalXmlFilePath -Force -ErrorAction Ignore + Copy-Item -Path $tempXmlFilePath -Destination $originalXmlFilePath -Force + Remove-Item -Path $tempXmlFilePath -Force -ErrorAction Ignore + } +} + +function Get-NewPSResourceRepositoryFileWithCredentialInfo { + # register our own repositories with desired priority + $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PowerShellGet" + $originalXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" + $tempXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "temp.xml" + + if (Test-Path -Path $originalXmlFilePath) { + Copy-Item -Path $originalXmlFilePath -Destination $tempXmlFilePath + Remove-Item -Path $originalXmlFilePath -Force -ErrorAction Ignore + } + + if (! (Test-Path -Path $powerShellGetPath)) { + $null = New-Item -Path $powerShellGetPath -ItemType Directory -Verbose + } + + $fileToCopy = Join-Path -Path $PSScriptRoot -ChildPath "testRepositoriesWithCredentialInfo.xml" + Copy-Item -Path $fileToCopy -Destination $originalXmlFilePath -Force -Verbose +} + +function Register-LocalRepos { + $repoUriAddress = Join-Path -Path $TestDrive -ChildPath "testdir" + $null = New-Item $repoUriAddress -ItemType Directory -Force + $localRepoParams = @{ + Name = "psgettestlocal" + Uri = $repoUriAddress + Priority = 40 + Trusted = $false + } + Register-PSResourceRepository @localRepoParams + + $repoUriAddress2 = Join-Path -Path $TestDrive -ChildPath "testdir2" + $null = New-Item $repoUriAddress2 -ItemType Directory -Force + $localRepoParams2 = @{ + Name = "psgettestlocal2" + Uri = $repoUriAddress2 + Priority = 50 + Trusted = $false + } + Register-PSResourceRepository @localRepoParams2 + Write-Verbose("registered psgettestlocal, psgettestlocal2") +} + +function Register-PSGallery { + $PSGalleryRepoParams = @{ + Name = $script:PSGalleryName + Uri = $script:PSGalleryLocation + Priority = 1 + Trusted = $false + } + Register-PSResourceRepository @PSGalleryRepoParams + + Write-Verbose("registered PSGallery") +} + +function Unregister-LocalRepos { + if(Get-PSResourceRepository -Name "psgettestlocal"){ + Unregister-PSResourceRepository -Name "psgettestlocal" + } + if(Get-PSResourceRepository -Name "psgettestlocal2"){ + Unregister-PSResourceRepository -Name "psgettestlocal2" + } +} +function Get-TestDriveSetUp +{ + $testResourcesFolder = Join-Path $TestDrive -ChildPath "TestLocalDirectory" + + $script:testIndividualResourceFolder = Join-Path -Path $testResourcesFolder -ChildPath "PSGet_$(Get-Random)" + $null = New-Item -Path $testIndividualResourceFolder -ItemType Directory -Force +} + +function Get-RoleCapabilityResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $roleCapName + ) + + Get-TestDriveSetUp + + $publishModuleName = $roleCapName + $publishModuleBase = Join-Path $script:testIndividualResourceFolder $publishModuleName + $null = New-Item -Path $publishModuleBase -ItemType Directory -Force + + $version = "1.0" + New-PSRoleCapabilityFile -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psrc") + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" -NestedModules "$publishModuleName.psm1" -DscResourcesToExport @('DefaultGatewayAddress', 'WINSSetting') -Tags @('PSDscResource_', 'DSC') + + Publish-PSResource -Path $publishModuleBase -Repository psgettestlocal +} + +function Get-DSCResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $dscName + ) + + Get-TestDriveSetUp + + $publishModuleName = $dscName + $publishModuleBase = Join-Path $script:testIndividualResourceFolder $publishModuleName + $null = New-Item -Path $publishModuleBase -ItemType Directory -Force + + $version = "1.0" + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" -NestedModules "$publishModuleName.psm1" -DscResourcesToExport @('DefaultGatewayAddress', 'WINSSetting') -Tags @('PSDscResource_', 'DSC') + + Publish-PSResource -Path $publishModuleBase -Repository psgettestlocal +} + +function Get-ScriptResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $scriptName, + + [string] + $scriptRepoName, + + [string] + $scriptVersion + ) + Get-TestDriveSetUp + + $scriptFilePath = Join-Path -Path $script:testIndividualResourceFolder -ChildPath "$scriptName.ps1" + $null = New-Item -Path $scriptFilePath -ItemType File -Force + + $params = @{ + Version = $scriptVersion + GUID = [guid]::NewGuid() + Author = 'Jane' + CompanyName = 'Microsoft Corporation' + Copyright = '(c) 2020 Microsoft Corporation. All rights reserved.' + Description = "Description for the $scriptName script" + LicenseUri = "https://$scriptName.com/license" + IconUri = "https://$scriptName.com/icon" + ProjectUri = "https://$scriptName.com" + Tags = @('Tag1','Tag2', "Tag-$scriptName-$scriptVersion") + ReleaseNotes = "$scriptName release notes" + } + + $scriptMetadata = Create-PSScriptMetadata @params + Set-Content -Path $scriptFilePath -Value $scriptMetadata + Publish-PSResource -Path $scriptFilePath -Repository $scriptRepoName -Verbose +} + +function Get-CommandResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $cmdName + ) + Get-TestDriveSetUp + + $publishModuleName = $cmdName + $publishModuleBase = Join-Path $script:testIndividualResourceFolder $publishModuleName + $null = New-Item -Path $publishModuleBase -ItemType Directory -Force + + $version = "1.0" + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" -NestedModules "$publishModuleName.psm1" -CmdletsToExport @('Get-Test', 'Set-Test') + + Publish-PSResource -Path $publishModuleBase -Repository psgettestlocal +} + +function Get-ModuleResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $moduleName, + + [string] + $repoName + ) + Get-TestDriveSetUp + + $publishModuleName = $moduleName + $publishModuleBase = Join-Path $script:testIndividualResourceFolder $publishModuleName + $null = New-Item -Path $publishModuleBase -ItemType Directory -Force + + $version = "1.0" + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" + + Publish-PSResource -Path $publishModuleBase -Repository $repoName +} + +function Create-TagsStringEntry +{ + Param( + [string[]] + $tags + ) + + if (!$tags) + { + return "" + } + + $tagsString = "Tags = @(" + ($tags -join ",") + ")" + return $tagsString +} + +function New-TestModule +{ + Param( + [string] + $path = "$TestDrive", + + [string] + $moduleName = "TestModule", + + [string] + $repoName, + + [string] + $packageVersion, + + [string] + $prereleaseLabel, + + [string[]] + $tags + ) + + $modulePath = Join-Path -Path $path -ChildPath $ModuleName + $moduleMan = Join-Path $modulePath -ChildPath ($ModuleName + '.psd1') + + if ( Test-Path -Path $modulePath) { + Remove-Item -Path $modulePath -Recurse -Force + } + + $null = New-Item -Path $modulePath -ItemType Directory -Force + $tagsEntry = Create-TagsStringEntry -tags $tags + $prereleaseEntry = "" + if ($prereleaseLabel) + { + $prereleaseEntry = "Prerelease = '{0}'" -f $prereleaseLabel + } + + @' + @{{ + ModuleVersion = '{0}' + Author = 'None' + Description = 'None' + GUID = '0c2829fc-b165-4d72-9038-ae3a71a755c1' + FunctionsToExport = @() + RequiredModules = @() + PrivateData = @{{ + PSData = @{{ + {1} + {2} + }} + }} + }} +'@ -f $packageVersion, $prereleaseEntry, $tagsEntry | Out-File -FilePath $moduleMan + + Publish-PSResource -Path $modulePath -Repository $repoName +} + +function Get-ModuleResourcePublishedToLocalRepoTestDrive +{ + Param( + [string] + $moduleName, + + [string] + $repoName, + + [string] + $packageVersion, + + [string] + $prereleaseLabel, + + [string[]] + $tags + ) + Get-TestDriveSetUp + + $publishModuleName = $moduleName + $publishModuleBase = Join-Path $script:testIndividualResourceFolder $publishModuleName + $null = New-Item -Path $publishModuleBase -ItemType Directory -Force + + $version = $packageVersion + if (!$tags -or ($tags.Count -eq 0)) + { + if (!$prereleaseLabel) + { + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" + } + else + { + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Prerelease $prereleaseLabel -Description "$publishModuleName module" + } + } + else { + # tags is not null or is empty + if (!$prereleaseLabel) + { + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Description "$publishModuleName module" -Tags $tags + } + else + { + New-ModuleManifest -Path (Join-Path -Path $publishModuleBase -ChildPath "$publishModuleName.psd1") -ModuleVersion $version -Prerelease $prereleaseLabel -Description "$publishModuleName module" -Tags $tags + } + } + + Publish-PSResource -Path $publishModuleBase -Repository $repoName +} + +function Register-LocalRepos { + $repoUriAddress = Join-Path -Path $TestDrive -ChildPath "testdir" + $null = New-Item $repoUriAddress -ItemType Directory -Force + $localRepoParams = @{ + Name = "psgettestlocal" + Uri = $repoUriAddress + Priority = 40 + Trusted = $false + } + + Register-PSResourceRepository @localRepoParams + + $repoUriAddress2 = Join-Path -Path $TestDrive -ChildPath "testdir2" + $null = New-Item $repoUriAddress2 -ItemType Directory -Force + $localRepoParams2 = @{ + Name = "psgettestlocal2" + Uri = $repoUriAddress2 + Priority = 50 + Trusted = $false + } + + Register-PSResourceRepository @localRepoParams2 +} +function RemoveItem +{ + Param( + [string] + $path + ) + + if($path -and (Test-Path $path)) + { + Remove-Item $path -Force -Recurse -ErrorAction SilentlyContinue + } +} + +function Create-PSScriptMetadata +{ + [OutputType([String])] + [CmdletBinding(PositionalBinding=$false, + SupportsShouldProcess=$true)] + + Param + ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $Version, + + [Parameter()] + #[ValidateNotNullOrEmpty()] + [Guid] + $Guid, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $Author, + + [Parameter()] + [String] + $CompanyName, + + [Parameter()] + [string] + $Copyright, + + [Parameter()] + [string] + $Description, + + [Parameter()] + [String[]] + $ExternalModuleDependencies, + + [Parameter()] + [string[]] + $RequiredScripts, + + [Parameter()] + [String[]] + $ExternalScriptDependencies, + + [Parameter()] + [string[]] + $Tags, + + [Parameter()] + [Uri] + $ProjectUri, + + [Parameter()] + [Uri] + $LicenseUri, + + [Parameter()] + [Uri] + $IconUri, + + [Parameter()] + [string[]] + $ReleaseNotes, + + [Parameter()] + [string] + $PrivateData + ) + + Process + { + $PSScriptInfoString = @" + +<#PSScriptInfo + +.VERSION$(if ($Version) {" $Version"}) + +.GUID$(if ($Guid) {" $Guid"}) + +.AUTHOR$(if ($Author) {" $Author"}) + +.COMPANYNAME$(if ($CompanyName) {" $CompanyName"}) + +.COPYRIGHT$(if ($Copyright) {" $Copyright"}) + +.TAGS$(if ($Tags) {" $Tags"}) + +.LICENSEURI$(if ($LicenseUri) {" $LicenseUri"}) + +.PROJECTURI$(if ($ProjectUri) {" $ProjectUri"}) + +.ICONURI$(if ($IconUri) {" $IconUri"}) + +.EXTERNALMODULEDEPENDENCIES$(if ($ExternalModuleDependencies) {" $($ExternalModuleDependencies -join ',')"}) + +.REQUIREDSCRIPTS$(if ($RequiredScripts) {" $($RequiredScripts -join ',')"}) + +.EXTERNALSCRIPTDEPENDENCIES$(if ($ExternalScriptDependencies) {" $($ExternalScriptDependencies -join ',')"}) + +.RELEASENOTES +$($ReleaseNotes -join "`r`n") + +.PRIVATEDATA$(if ($PrivateData) {" $PrivateData"}) + +#> + +<# + +.DESCRIPTION +$(if ($Description) {" $Description"}) + +#> +"@ + return $PSScriptInfoString + } +} + +<# +Checks that provided PSGetInfo object contents match the expected data +from the test information file: PSGetModuleInfo.xml +#> + +function CheckForExpectedPSGetInfo +{ + param ($psGetInfo) + + $psGetInfo.AdditionalMetadata.Keys | Should -HaveCount 22 + $psGetInfo.AdditionalMetadata['copyright'] | Should -BeExactly '(c) Microsoft Corporation. All rights reserved.' + $psGetInfo.AdditionalMetadata['description'] | Should -BeLike 'This module provides a convenient way for a user to store and retrieve secrets*' + $psGetInfo.AdditionalMetadata['requireLicenseAcceptance'] | Should -BeExactly 'False' + $psGetInfo.AdditionalMetadata['isLatestVersion'] | Should -BeExactly 'True' + $psGetInfo.AdditionalMetadata['isAbsoluteLatestVersion'] | Should -BeExactly 'True' + $psGetInfo.AdditionalMetadata['versionDownloadCount'] | Should -BeExactly '0' + $psGetInfo.AdditionalMetadata['downloadCount'] | Should -BeExactly '15034' + $psGetInfo.AdditionalMetadata['packageSize'] | Should -BeExactly '55046' + $psGetInfo.AdditionalMetadata['published'] | Should -BeExactly '3/25/2021 6:08:10 PM -07:00' + $psGetInfo.AdditionalMetadata['created'] | Should -BeExactly '3/25/2021 6:08:10 PM -07:00' + $psGetInfo.AdditionalMetadata['lastUpdated'] | Should -BeExactly '3/25/2021 6:08:10 PM -07:00' + $psGetInfo.AdditionalMetadata['tags'] | Should -BeLike 'PSModule PSEdition_Core PSCmdlet_Register-SecretVault*' + $psGetInfo.AdditionalMetadata['developmentDependency'] | Should -BeExactly 'False' + $psGetInfo.AdditionalMetadata['updated'] | Should -BeExactly '2021-03-25T18:08:10Z' + $psGetInfo.AdditionalMetadata['NormalizedVersion'] | Should -BeExactly '1.1.0-preview2' + $psGetInfo.AdditionalMetadata['Authors'] | Should -BeExactly 'Microsoft Corporation' + $psGetInfo.AdditionalMetadata['IsPrerelease'] | Should -Be $True + $psGetInfo.AdditionalMetadata['ItemType'] | Should -BeExactly 'Module' + $psGetInfo.AdditionalMetadata['FileList'] | Should -BeLike 'Microsoft.PowerShell.SecretManagement.nuspec|Microsoft.PowerShell.SecretManagement.dll*' + $psGetInfo.AdditionalMetadata['GUID'] | Should -BeExactly 'a5c858f6-4a8e-41f1-b1ee-0ff8f6ad69d3' + $psGetInfo.AdditionalMetadata['PowerShellVersion'] | Should -BeExactly '5.1' + $psGetInfo.AdditionalMetadata['CompanyName'] | Should -BeExactly 'Microsoft Corporation' + # + $psGetInfo.Author | Should -BeExactly 'Microsoft Corporation' + $psGetInfo.CompanyName | Should -BeExactly 'Microsoft Corporation' + $psGetInfo.Copyright | Should -BeExactly '(c) Microsoft Corporation. All rights reserved.' + $psGetInfo.Dependencies | Should -HaveCount 0 + $psGetInfo.Description | Should -BeLike 'This module provides a convenient way for a user to store*' + $psGetInfo.IconUri | Should -BeNullOrEmpty + $psGetInfo.IsPrerelease | Should -Be $True + $psGetInfo.Prerelease | Should -Be "preview2" + $psGetInfo.Includes.Cmdlet | Should -HaveCount 10 + $psGetInfo.Includes.Cmdlet[0] | Should -BeExactly 'Register-SecretVault' + $psGetInfo.InstalledDate.Year | Should -BeExactly 2021 + $psGetInfo.InstalledLocation | Should -BeLike 'C:\Users\*' + $psGetInfo.LicenseUri | Should -BeExactly 'https://github.com/PowerShell/SecretManagement/blob/master/LICENSE' + $psGetInfo.Name | Should -BeExactly 'Microsoft.PowerShell.SecretManagement' + $psGetInfo.PackageManagementProvider | Should -BeExactly 'NuGet' + $psGetInfo.PowerShellGetFormatVersion | Should -BeNullOrEmpty + $psGetInfo.ProjectUri | Should -BeExactly 'https://github.com/powershell/secretmanagement' + $psGetInfo.PublishedDate.Year | Should -BeExactly 2021 + $psGetInfo.ReleasedNotes | Should -BeNullOrEmpty + $psGetInfo.Repository | Should -BeExactly 'PSGallery' + $psGetInfo.RepositorySourceLocation | Should -BeExactly 'https://www.powershellgallery.com/api/v2' + $psGetInfo.Tags | Should -BeExactly @('PSModule', 'PSEdition_Core') + $psGetInfo.Type | Should -BeExactly 'Module' + $psGetInfo.UpdatedDate.Year | Should -BeExactly 1 + $psGetInfo.Version | Should -Be "1.1.0" +} diff --git a/Test/PublishPSResource.Tests.ps1 b/Test/PublishPSResource.Tests.ps1 new file mode 100644 index 0000000..8fbdbcc --- /dev/null +++ b/Test/PublishPSResource.Tests.ps1 @@ -0,0 +1,371 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" +$testDir = (get-item $psscriptroot).parent.FullName + +function CreateTestModule +{ + param ( + [string] $Path = "$TestDrive", + [string] $ModuleName = 'TestModule' + ) + + $modulePath = Join-Path -Path $Path -ChildPath $ModuleName + $moduleMan = Join-Path $modulePath -ChildPath ($ModuleName + '.psd1') + $moduleSrc = Join-Path $modulePath -ChildPath ($ModuleName + '.psm1') + + if ( Test-Path -Path $modulePath) { + Remove-Item -Path $modulePath -Recurse -Force + } + + $null = New-Item -Path $modulePath -ItemType Directory -Force + + @' + @{{ + RootModule = "{0}.psm1" + ModuleVersion = '1.0.0' + Author = 'None' + Description = 'None' + GUID = '0c2829fc-b165-4d72-9038-ae3a71a755c1' + FunctionsToExport = @('Test1') + RequiredModules = @('NonExistentModule') + }} +'@ -f $ModuleName | Out-File -FilePath $moduleMan + + @' + function Test1 { + Write-Output 'Hello from Test1' + } +'@ | Out-File -FilePath $moduleSrc +} + +Describe "Test CompatPowerShellGet: Publish-PSResource" -tags 'CI' { + BeforeAll { + Get-NewPSResourceRepositoryFile + + # Register temporary repositories + $tmpRepoPath = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath" + New-Item $tmpRepoPath -Itemtype directory -Force + $testRepository = "testRepository" + Register-PSResourceRepository -Name $testRepository -Uri $tmpRepoPath -Priority 1 -ErrorAction SilentlyContinue + $script:repositoryPath = [IO.Path]::GetFullPath((get-psresourcerepository "testRepository").Uri.AbsolutePath) + + $tmpRepoPath2 = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath2" + New-Item $tmpRepoPath2 -Itemtype directory -Force + $testRepository2 = "testRepository2" + Register-PSResourceRepository -Name $testRepository2 -Uri $tmpRepoPath2 -ErrorAction SilentlyContinue + $script:repositoryPath2 = [IO.Path]::GetFullPath((get-psresourcerepository "testRepository2").Uri.AbsolutePath) + + # Create module + $script:tmpModulesPath = Join-Path -Path $TestDrive -ChildPath "tmpModulesPath" + $script:PublishModuleName = "PSGetTestModule" + $script:PublishModuleBase = Join-Path $script:tmpModulesPath -ChildPath $script:PublishModuleName + if(!(Test-Path $script:PublishModuleBase)) + { + New-Item -Path $script:PublishModuleBase -ItemType Directory -Force + } + + #Create dependency module + $script:DependencyModuleName = "PackageManagement" + $script:DependencyModuleBase = Join-Path $script:tmpModulesPath -ChildPath $script:DependencyModuleName + if(!(Test-Path $script:DependencyModuleBase)) + { + New-Item -Path $script:DependencyModuleBase -ItemType Directory -Force + } + + # Create temp destination path + $script:destinationPath = [IO.Path]::GetFullPath((Join-Path -Path $TestDrive -ChildPath "tmpDestinationPath")) + New-Item $script:destinationPath -ItemType directory -Force + + #Create folder where we shall place all script files to be published for these tests + $script:tmpScriptsFolderPath = Join-Path -Path $TestDrive -ChildPath "tmpScriptsPath" + if(!(Test-Path $script:tmpScriptsFolderPath)) + { + New-Item -Path $script:tmpScriptsFolderPath -ItemType Directory -Force + } + + # Path to folder, within our test folder, where we store invalid module and script files used for testing + $script:testFilesFolderPath = Join-Path $testDir -ChildPath "testFiles" + + # Path to specifically to that invalid test modules folder + $script:testModulesFolderPath = Join-Path $testFilesFolderPath -ChildPath "testModules" + + # Path to specifically to that invalid test scripts folder + $script:testScriptsFolderPath = Join-Path $testFilesFolderPath -ChildPath "testScripts" + + # Create test module with missing required module + CreateTestModule -Path $TestDrive -ModuleName 'ModuleWithMissingRequiredModule' + } + AfterAll { + Get-RevertPSResourceRepositoryFile + } + AfterEach { + # Delete all contents of the repository without deleting the repository directory itself + $pkgsToDelete = Join-Path -Path "$script:repositoryPath" -ChildPath "*" + Remove-Item $pkgsToDelete -Recurse + + $pkgsToDelete = Join-Path -Path "$script:repositoryPath2" -ChildPath "*" + Remove-Item $pkgsToDelete -Recurse + + $pkgsToDelete = Join-Path -Path $script:PublishModuleBase -ChildPath "*" + Remove-Item $pkgsToDelete -Recurse -ErrorAction SilentlyContinue + } + + It "Publish a module with -Path and -Repository" { + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $script:PublishModuleBase -Repository $testRepository2 -verbose + + $expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath + } + + + It "Publish a module with -Path pointing to a module directory (parent directory has same name)" { + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $script:PublishModuleBase -Repository $testRepository + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "Publish a module with -Path pointing to a module directory (parent directory has different name)" { + $version = "1.0.0" + $newModuleRoot = Join-Path -Path $script:PublishModuleBase -ChildPath "NewTestParentDirectory" + New-Item -Path $newModuleRoot -ItemType Directory + New-ModuleManifest -Path (Join-Path -Path $newModuleRoot -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $newModuleRoot -Repository $testRepository + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "Publish a module with -Path pointing to a .psd1 (parent directory has same name)" { + $version = "1.0.0" + $manifestPath = Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1" + New-ModuleManifest -Path $manifestPath -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $manifestPath -Repository $testRepository + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "Publish a module with -Path pointing to a .psd1 (parent directory has different name)" { + $version = "1.0.0" + $newModuleRoot = Join-Path -Path $script:PublishModuleBase -ChildPath "NewTestParentDirectory" + New-Item -Path $newModuleRoot -ItemType Directory + $manifestPath = Join-Path -Path $newModuleRoot -ChildPath "$script:PublishModuleName.psd1" + New-ModuleManifest -Path $manifestPath -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $manifestPath -Repository $testRepository + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "Publish a module with dependencies" { + # Create dependency module + $dependencyVersion = "2.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:DependencyModuleBase -ChildPath "$script:DependencyModuleName.psd1") -ModuleVersion $dependencyVersion -Description "$script:DependencyModuleName module" + + Publish-Module -Path $script:DependencyModuleBase + + # Create module to test + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" -RequiredModules @(@{ModuleName = 'PackageManagement'; ModuleVersion = '2.0.0' }) + + Publish-Module -Path $script:PublishModuleBase + + $nupkg = Get-ChildItem $script:repositoryPath | select-object -Last 1 + $nupkg.Name | Should Be "$script:PublishModuleName.$version.nupkg" + } + + It "Publish a module with a dependency that is not published, should throw" { + $version = "1.0.0" + $dependencyVersion = "2.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" -RequiredModules @(@{ModuleName = 'PackageManagement'; ModuleVersion = '1.4.4' }) + + {Publish-Module -Path $script:PublishModuleBase -ErrorAction Stop} | Should -Throw -ErrorId "FindVersionFail,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + } + + It "Publish a module and preserve file structure" { + $version = "1.0.0" + $testFile = Join-Path -Path "TestSubDirectory" -ChildPath "TestSubDirFile.ps1" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + New-Item -Path (Join-Path -Path $script:PublishModuleBase -ChildPath $testFile) -Force + + Publish-Module -Path $script:PublishModuleBase + + # Must change .nupkg to .zip so that Expand-Archive can work on Windows PowerShell + $nupkgPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + $zipPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.zip" + Rename-Item -Path $nupkgPath -NewName $zipPath + $unzippedPath = Join-Path -Path $TestDrive -ChildPath "$script:PublishModuleName" + New-Item $unzippedPath -Itemtype directory -Force + Expand-Archive -Path $zipPath -DestinationPath $unzippedPath + + Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True + } + + It "Publish a module to PSGallery without -APIKey, should throw" { + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $script:PublishModuleBase -Repository PSGallery -ErrorVariable ev -ErrorAction SilentlyContinue + $ev.FullyQualifiedErrorId | Should -be "APIKeyError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + } + + It "Publish a module to PSGallery using incorrect API key, should throw" { + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + Publish-Module -Path $script:PublishModuleBase -Repository PSGallery -NuGetApiKey "123456789" -ErrorAction SilentlyContinue + + $Error[0].FullyQualifiedErrorId | Should -be "403Error,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + } + + It "publish a script locally"{ + $scriptName = "PSGetTestScript" + $scriptVersion = "1.0.0" + + $params = @{ + Version = $scriptVersion + GUID = [guid]::NewGuid() + Author = 'Jane' + CompanyName = 'Microsoft Corporation' + Copyright = '(c) 2020 Microsoft Corporation. All rights reserved.' + Description = "Description for the $scriptName script" + LicenseUri = "https://$scriptName.com/license" + IconUri = "https://$scriptName.com/icon" + ProjectUri = "https://$scriptName.com" + Tags = @('Tag1','Tag2', "Tag-$scriptName-$scriptVersion") + ReleaseNotes = "$scriptName release notes" + } + + $scriptPath = (Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$scriptName.ps1") + New-PSScriptFile @params -Path $scriptPath + + Publish-Script -Path $scriptPath + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "should publish a script without lines in between comment blocks locally" { + $scriptName = "ScriptWithoutEmptyLinesBetweenCommentBlocks" + $scriptVersion = "1.0.0" + $scriptPath = (Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1") + + Publish-Script -Path $scriptPath + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "should publish a script without lines in help block locally" { + $scriptName = "ScriptWithoutEmptyLinesInMetadata" + $scriptVersion = "1.0.0" + $scriptPath = (Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1") + + Publish-Script -Path $scriptPath + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + + It "should write error and not publish script when Author property is missing" { + $scriptName = "InvalidScriptMissingAuthor.ps1" + $scriptVersion = "1.0.0" + + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + Publish-Script -Path $scriptFilePath -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "psScriptMissingAuthor,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + + $publishedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + Test-Path -Path $publishedPath | Should -Be $false + } + + It "should write error and not publish script when Version property is missing" { + $scriptName = "InvalidScriptMissingVersion.ps1" + + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + Publish-Script -Path $scriptFilePath -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "psScriptMissingVersion,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + + $publishedPkgs = Get-ChildItem -Path $script:repositoryPath -Filter *.nupkg + $publishedPkgs | Should -HaveCount 0 + } + + + It "should write error and not publish script when Guid property is missing" { + $scriptName = "InvalidScriptMissingGuid.ps1" + $scriptVersion = "1.0.0" + + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + Publish-Script -Path $scriptFilePath -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "psScriptMissingGuid,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + + $publishedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + Test-Path -Path $publishedPath | Should -Be $false + } + + It "should write error and not publish script when Description property is missing" { + $scriptName = "InvalidScriptMissingDescription.ps1" + $scriptVersion = "1.0.0" + + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + Publish-Script -Path $scriptFilePath -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "PSScriptInfoMissingDescription,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + + $publishedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + Test-Path -Path $publishedPath | Should -Be $false + } + + It "should write error and not publish script when Description block altogether is missing" { + # we expect .ps1 files to have a separate comment block for .DESCRIPTION property, not to be included in the PSScriptInfo commment block + $scriptName = "InvalidScriptMissingDescriptionCommentBlock.ps1" + $scriptVersion = "1.0.0" + + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + Publish-Script -Path $scriptFilePath -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "missingHelpInfoCommentError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + + $publishedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + Test-Path -Path $publishedPath | Should -Be $false + } + + It "Publish a module with that has an invalid version format, should throw" { + $moduleName = "incorrectmoduleversion" + $incorrectmoduleversion = Join-Path -Path $script:testModulesFolderPath -ChildPath $moduleName + + {Publish-Module -Path $incorrectmoduleversion -ErrorAction Stop} | Should -Throw -ErrorId "InvalidModuleManifest,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + } + + It "Publish a module with a dependency that has an invalid version format, should throw" { + $moduleName = "incorrectdepmoduleversion" + $incorrectdepmoduleversion = Join-Path -Path $script:testModulesFolderPath -ChildPath $moduleName + + {Publish-Module -Path $incorrectdepmoduleversion -ErrorAction Stop} | Should -Throw -ErrorId "InvalidModuleManifest,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/RegisterPSResourceRepository.Tests.ps1 b/Test/RegisterPSResourceRepository.Tests.ps1 new file mode 100644 index 0000000..e127475 --- /dev/null +++ b/Test/RegisterPSResourceRepository.Tests.ps1 @@ -0,0 +1,171 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe "Test CompatPowerShellGet: Register-PSResourceRepository" -tags 'CI' { + BeforeEach { + $PSGalleryName = Get-PSGalleryName + $PSGalleryUri = Get-PSGalleryLocation + $TestRepoName1 = "testRepository" + $TestRepoName2 = "testRepository2" + $TestRepoName3 = "testRepository3" + $TestRepoName4 = "testRepository4" + $relativeCurrentPath = Get-Location + Get-NewPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDir4Path = Join-Path -Path $TestDrive -ChildPath "tmpDir4" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path, $tmpDir4Path) + Get-NewTestDirs($tmpDirPaths) + + $relativeCurrentPath = Get-Location + + $randomSecret = [System.IO.Path]::GetRandomFileName() + $randomPassword = [System.IO.Path]::GetRandomFileName() + + $credentialInfo1 = New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", $randomSecret) + $secureString = ConvertTo-SecureString $randomPassword -AsPlainText -Force + $credential = New-Object pscredential ("testusername", $secureString) + $credentialInfo2 = New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", $randomSecret, $credential) + } + AfterEach { + Get-RevertPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDir4Path = Join-Path -Path $TestDrive -ChildPath "tmpDir4" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path, $tmpDir4Path) + Get-RemoveTestDirs($tmpDirPaths) + } + + It "register repository given Name, SourceLocation (bare minimum for NameParmaterSet)" { + Register-PSRepository -Name $TestRepoName1 -SourceLocation $tmpDir1Path + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $tmpDir1Path + $res.Trusted | Should -Be False + } + + It "register repository with Name, Uri, Trusted (NameParameterSet)" { + Register-PSRepository -Name $TestRepoName1 -SourceLocation $tmpDir1Path -InstallationPolicy Trusted + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $tmpDir1Path + $res.Trusted | Should -Be True + } + + It "register repository with PSGallery parameter (PSGalleryParameterSet)" { + Unregister-PSResourceRepository -Name $PSGalleryName + Register-PSRepository -Default + $res = Get-PSResourceRepository -Name $PSGalleryName + $res.Name | Should -Be $PSGalleryName + $res.Uri | Should -Be $PSGalleryUri + $res.Trusted | Should -Be False + } + + It "register repository with PSGallery, InstallationPolicy parameters (PSGalleryParameterSet)" { + Unregister-PSResourceRepository -Name $PSGalleryName + Register-PSRepository -Default -InstallationPolicy Trusted + $res = Get-PSResourceRepository -Name $PSGalleryName + $res.Name | Should -Be $PSGalleryName + $res.Uri | Should -Be $PSGalleryUri + $res.Trusted | Should -Be True + } + + It "not register repository when Name is provided but -SourceLocation is not" { + {Register-PSRepository -Name $TestRepoName1 -SourceLocation "" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository" + } + + It "not register repository when Name is empty but -SourceLocation is provided" { + {Register-PSRepository -Name "" -SourceLocation $tmpDir1Path -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Register-PSRepository" + } + + It "not register repository when Name is null but -SourceLocation is provided" { + {Register-PSRepository -Name $null -SourceLocation $tmpDir1Path -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Register-PSRepository" + } + + It "not register repository when Name is just whitespace but -SourceLocation is provided" { + {Register-PSRepository -Name " " -SourceLocation $tmpDir1Path -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository" + } + + It "not register PSGallery with NameParameterSet" { + {Register-PSRepository -Name $PSGalleryName -SourceLocation $PSGalleryUri -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository" + } + + # this error message comes from the parameter cmdlet tags (earliest point of detection) + It "not register PSGallery when PSGallery parameter provided with Name, Uri or CredentialInfo" { + {Register-PSRepository -PSGallery -Name $PSGalleryName -ErrorAction Stop} | Should -Throw -ErrorId "NamedParameterNotFound,Register-PSRepository" + {Register-PSRepository -PSGallery -SourceLocation $PSGalleryUri -ErrorAction Stop} | Should -Throw -ErrorId "NamedParameterNotFound,Register-PSRepository" + } + + It "should register repository with relative location provided as Uri" { + Register-PSRepository -Name $TestRepoName1 -SourceLocation ".\" + $res = Get-PSResourceRepository -Name $TestRepoName1 + + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $relativeCurrentPath + $res.Trusted | Should -Be False + $res.Priority | Should -Be 50 + } + + It "should register local file share NuGet based repository" { + Register-PSRepository -Name "localFileShareTestRepo" -SourceLocation "\\hcgg.rest.of.domain.name\test\ITxx\team\NuGet\" + $res = Get-PSResourceRepository -Name "localFileShareTestRepo" + + $res.Name | Should -Be "localFileShareTestRepo" + $res.Uri.LocalPath | Should -Contain "\\hcgg.rest.of.domain.name\test\ITxx\team\NuGet\" + } + + It 'Register-PSRepository File system location with special chars' { + $tmpdir = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'ps repo testing [$!@^&test(;)]' + if (-not (Test-Path -LiteralPath $tmpdir)) { + New-Item -Path $tmpdir -ItemType Directory > $null + } + try { + Register-PSRepository -Name 'Test Repo' -SourceLocation $tmpdir + try { + $repo = Get-PSRepository -Name 'Test Repo' + $repo.Name | Should -Be 'Test Repo' + $repo.Uri.ToString().EndsWith('ps repo testing [$!@^&test(;)]') | should be $true + } + finally { + Unregister-PSRepository -Name 'Test Repo' -ErrorAction SilentlyContinue + } + } + finally { + Remove-Item -LiteralPath $tmpdir -Force -Recurse + } + } + + It 'Reregister PSGallery again: Should fail' { + { Register-PSRepository -Default -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw 'Adding to repository store failed: The PSResource Repository 'PSGallery' already exists' + } + + It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation : Should fail' { + { Register-PSRepository $RepositoryName $SourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw "Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + } + + It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation -PublishLocation $PublishLocation : Should fail' { + { Register-PSRepository $RepositoryName $SourceLocation -PublishLocation $PublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw "Cannot validate argument on parameter 'PublishLocation'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + } + + It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation -ScriptPublishLocation $ScriptPublishLocation : Should fail' { + { Register-PSRepository -Name $RepositoryName $SourceLocation -ScriptPublishLocation $ScriptPublishLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw "Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + } + + It 'Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation -ScriptSourceLocation $ScriptSourceLocation : Should fail' { + { Register-PSRepository $RepositoryName -SourceLocation $SourceLocation -ScriptSourceLocation $ScriptSourceLocation -ErrorVariable ev -ErrorAction SilentlyContinue } | Should Throw "Cannot validate argument on parameter 'SourceLocation'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again." + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/SavePSResource.Tests.ps1 b/Test/SavePSResource.Tests.ps1 new file mode 100644 index 0000000..1785b30 --- /dev/null +++ b/Test/SavePSResource.Tests.ps1 @@ -0,0 +1,159 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Save-PSResource' -tags 'CI' { + + BeforeAll { + $PSGalleryName = Get-PSGalleryName + $testModuleName = "test_module" + $testScriptName = "test_script" + $testModuleName2 = "testmodule99" + $PackageManagement = "PackageManagement" + Get-NewPSResourceRepositoryFile + Set-PSResourceRepository -Name PSGallery -Trusted + + $SaveDir = Join-Path $TestDrive 'SavedResources' + New-Item -Item Directory $SaveDir -Force + } + + AfterEach { + # Delete contents of save directory + Remove-Item -Path (Join-Path $SaveDir '*') -Recurse -Force -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + It "Save-Module with Find-DscResource output" { + $DscResourceName = 'SystemLocale' + $ModuleName = 'SystemLocaleDsc' + $res1 = Find-DscResource -Name $DscResourceName + $res1 | Should -Not -BeNullOrEmpty + + Find-DscResource -Name $DscResourceName | Save-Module -Path $SaveDir + + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $ModuleName } + $pkgDirs | Should -HaveCount 1 + } + + It "Save-Module with Find-Command output" { + $cmdName = "Get-WUJob" + $ModuleName = "PSWindowsUpdate" + $res1 = Find-Command -Name $cmdName + $res1 | Should -Not -BeNullOrEmpty + + Find-Command -Name $cmdName | Save-Module -Path $SaveDir + + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $ModuleName } + $pkgDirs | Should -HaveCount 1 + } + + It "Save-Module with dependencies" { + $ModuleName = "test_module" + $dependency1 = "RequiredModule1" + $dependency2 = "RequiredModule2" + $dependency3 = "RequiredModule3" + $dependency4 = "RequiredModule4" + $dependency5 = "RequiredModule5" + + Save-Module -Name $ModuleName -Repository PSGallery -Path $SaveDir + + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $ModuleName -or $dependency1 -or $dependency2 -or $dependency3 -or $dependency4 -or $dependency5 } + $pkgDirs.Count | Should -BeGreaterOrEqual 6 + } + + It "Save-Module with Find-Module output" { + Find-PSResource -Name $testModuleName2 -Repository PSGallery | Save-Module -Path $SaveDir + + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $testModuleName2 } + $pkgDirs | Should -HaveCount 1 + } + + It "Save specific module resource by name" { + Save-Module -Name $testModuleName2 -Repository $PSGalleryName -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + $pkgDir | Should -Not -BeNullOrEmpty + (Get-ChildItem $pkgDir.FullName).Count | Should -HaveCount 1 + } + + It "Save specific script resource by name" { + Save-Script -Name $testScriptName -Repository $PSGalleryName -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "$testScriptName.ps1" + $pkgDir | Should -Not -BeNullOrEmpty + (Get-ChildItem $pkgDir.FullName).Count | Should -HaveCount 1 + } + + It "Save multiple resources by name" { + $pkgNames = @($testModuleName, $testModuleName2) + Save-Module -Name $pkgNames -Repository $PSGalleryName -Path $SaveDir + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq $testModuleName -or $_.Name -eq $testModuleName2 } + $pkgDirs | Should -HaveCount 2 + (Get-ChildItem $pkgDirs[0].FullName) | Should -HaveCount 1 + (Get-ChildItem $pkgDirs[1].FullName) | Should -HaveCount 1 + } + + It "Should not save resource given nonexistant name" { + Save-Module -Name NonExistentModule -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "NonExistentModule" + $pkgDir.Name | Should -BeNullOrEmpty + } + + It "Not Save module with Name containing wildcard" { + Save-Module -Name "TestModule*" -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "NameContainsWildcard,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" + } + + It "Should save resource given name and exact version" { + Save-Module -Name $testModuleName2 -RequiredVersion "0.0.2" -Repository $PSGalleryName -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + $pkgDir | Should -Not -BeNullOrEmpty + $pkgDirVersion = Get-ChildItem $pkgDir.FullName + $pkgDirVersion.Name | Should -Be "0.0.2" + } + + It "Save resource with latest (including prerelease) version given Prerelease parameter" { + Save-Module -Name $testModuleName2 -AllowPrerelease -Repository $PSGalleryName -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName2 + $pkgDir | Should -Not -BeNullOrEmpty + $pkgDirVersion = Get-ChildItem -Path $pkgDir.FullName + $pkgDirVersion.Name | Should -Be "1.0.0" + } + + It "Save a module with a dependency" { + Save-Module -Name "TestModuleWithDependencyE" -RequiredVersion "1.0.0.0" -Repository $PSGalleryName -Path $SaveDir + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModuleWithDependencyE" -or $_.Name -eq "TestModuleWithDependencyC" -or $_.Name -eq "TestModuleWithDependencyB" -or $_.Name -eq "TestModuleWithDependencyD"} + $pkgDirs.Count | Should -BeGreaterThan 1 + (Get-ChildItem $pkgDirs[0].FullName).Count | Should -BeGreaterThan 0 + (Get-ChildItem $pkgDirs[1].FullName).Count | Should -BeGreaterThan 0 + (Get-ChildItem $pkgDirs[2].FullName).Count | Should -BeGreaterThan 0 + (Get-ChildItem $pkgDirs[3].FullName).Count | Should -BeGreaterThan 0 + } + + It "Save a module with a dependency and skip saving the dependency" { + Save-Module -Name "TestModuleWithDependencyE" -RequiredVersion "1.0.0.0" -Repository $PSGalleryName -Path $SaveDir + $pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModuleWithDependencyE"} + $pkgDirs | Should -HaveCount 1 + (Get-ChildItem $pkgDirs[0].FullName) | Should -HaveCount 1 + } + + It "Save PSResourceInfo object piped in for prerelease version object" -Pending { + Find-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName | Save-Module -Path $SaveDir + $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName + $pkgDir | Should -Not -BeNullOrEmpty + (Get-ChildItem -Path $pkgDir.FullName) | Should -HaveCount 1 + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/SetPSResourceRepository.ps1 b/Test/SetPSResourceRepository.ps1 new file mode 100644 index 0000000..0395fe9 --- /dev/null +++ b/Test/SetPSResourceRepository.ps1 @@ -0,0 +1,122 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe "Test CompatPowerShellGet: Set-PSResourceRepository" -tags 'CI' { + BeforeEach { + $PSGalleryName = Get-PSGalleryName + $PSGalleryUri = Get-PSGalleryLocation + $TestRepoName1 = "testRepository" + $TestRepoName2 = "testRepository2" + $TestRepoName3 = "testRepository3" + $relativeCurrentPath = Get-Location + Get-NewPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDir4Path = Join-Path -Path $TestDrive -ChildPath "tmpDir4" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path, $tmpDir4Path) + Get-NewTestDirs($tmpDirPaths) + + $relativeCurrentPath = Get-Location + + $randomSecret = [System.IO.Path]::GetRandomFileName() + $randomPassword = [System.IO.Path]::GetRandomFileName() + + $credentialInfo1 = New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", $randomSecret) + $secureString = ConvertTo-SecureString $randomPassword -AsPlainText -Force + $credential = New-Object pscredential ("testusername", $secureString) + $credentialInfo2 = New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ("testvault", $randomSecret, $credential) + } + AfterEach { + Get-RevertPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDir4Path = Join-Path -Path $TestDrive -ChildPath "tmpDir4" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path, $tmpDir4Path) + Get-RemoveTestDirs($tmpDirPaths) + } + + It "set repository given Name and SourceLocation parameters" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Set-PSRepository -Name $TestRepoName1 -SourceLocation $tmpDir2Path + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $tmpDir2Path + $res.Trusted | Should -Be False + } + + It "set repository given Name and Trusted parameters" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Set-PSRepository -Name $TestRepoName1 -InstallationPolicy Trusted + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $tmpDir1Path + $res.Trusted | Should -Be True + } + + It "set repository given pipeline input ValueFromPipelineByPropertyName passed in" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Get-PSResourceRepository -Name $TestRepoName1 | Set-PSRepository -InstallationPolicy Trusted + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $Res.Uri.LocalPath | Should -Contain $tmpDir1Path + $res.Trusted | Should -Be True + } + + It "not set repository and write error given just Name parameter" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + {Set-PSRepository -Name $TestRepoName1 -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository" + } + + It "not set repository and throw error given Name contains * (NameParameterSet)" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + {Set-PSRepository -Name "test*Repository" -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository" + } + + It "not set repository and throw error given Name is null (NameParameterSet)" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + {Set-PSRepository -Name $null -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Set-PSRepository" + } + + It "not set repository and throw error given Name is whitespace (NameParameterSet)" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + {Set-PSRepository -Name " " -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository" + } + + It "not set and throw error for trying to set PSGallery Uri (NameParameterSet)" { + Unregister-PSResourceRepository -Name $PSGalleryName + Register-PSResourceRepository -PSGallery + {Set-PSRepository -Name $PSGalleryName -SourceLocation $tmpDir1Path -ErrorAction Stop} | Should -Throw -ErrorId "ErrorInNameParameterSet,Microsoft.PowerShell.PowerShellGet.Cmdlets.SetPSResourceRepository" + } + + It "should set repository with relative Uri provided" { + Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path + Set-PSRepository -Name $TestRepoName1 -SourceLocation $relativeCurrentPath.ToString() + $res = Get-PSResourceRepository -Name $TestRepoName1 + $res.Name | Should -Be $TestRepoName1 + $reformattedPath = ($relativeCurrentPath -replace "\\", "/") + $res.Uri.ToString().Contains($reformattedPath) | Should -Be $true + $res.Trusted | Should -Be False + } + + It "should set repository with local file share NuGet based Uri" { + Register-PSResourceRepository -Name "localFileShareTestRepo" -Uri $tmpDir1Path + Set-PSRepository -Name "localFileShareTestRepo" -SourceLocation "\\hcgg.rest.of.domain.name\test\ITxx\team\NuGet\" + $res = Get-PSResourceRepository -Name "localFileShareTestRepo" + $res.Name | Should -Be "localFileShareTestRepo" + $Res.Uri | Should -Contain "\\hcgg.rest.of.domain.name\test\ITxx\team\NuGet\" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/TestPSScriptFile.Tests.ps1 b/Test/TestPSScriptFile.Tests.ps1 new file mode 100644 index 0000000..b5ec6c5 --- /dev/null +++ b/Test/TestPSScriptFile.Tests.ps1 @@ -0,0 +1,88 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" +$testDir = (get-item $psscriptroot).parent.FullName + +Describe "Test CompatPowerShellGet: Test-PSScriptFile" -tags 'CI' { + BeforeAll { + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDirPaths = @($tmpDir1Path) + Get-NewTestDirs($tmpDirPaths) + + # Path to folder, within our test folder, where we store invalid module and script files used for testing + $script:testFilesFolderPath = Join-Path $testDir -ChildPath "testFiles" + + # Path to specifically to that invalid test scripts folder + $script:testScriptsFolderPath = Join-Path $testFilesFolderPath -ChildPath "testScripts" + } + + It "determine script file with minimal required fields as valid" { + $scriptFilePath = Join-Path -Path $tmpDir1Path -ChildPath "testscript.ps1" + $scriptDescription = "this is a test script" + $guid = [guid]::NewGuid() + $author = "Script Author" + $version = "1.0.0" + New-PSScriptFile -Path $scriptFilePath -Description $scriptDescription -Guid $guid -Author $author -Version $version + Test-ScriptFileInfo $scriptFilePath | Should -Be $true + } + + It "not determine script file with Author field missing as valid" { + $scriptName = "InvalidScriptMissingAuthor.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $false + } + + It "not determine script file with Description field missing as valid" { + $scriptName = "InvalidScriptMissingDescription.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $false + } + + It "not determine script that is missing Description block altogether as valid" { + $scriptName = "InvalidScriptMissingDescriptionCommentBlock.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $false + } + + It "not determine script file Guid as valid" { + $scriptName = "InvalidScriptMissingGuid.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $false + } + + It "not determine script file missing Version as valid" { + $scriptName = "InvalidScriptMissingVersion.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $false + } + + It "determine script without empty lines in PSScriptInfo comment content is valid" { + $scriptName = "ScriptWithoutEmptyLinesInMetadata.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $true + } + + It "determine script without empty lines between comment blocks is valid" { + $scriptName = "ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-ScriptFileInfo $scriptFilePath | Should -Be $true + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/UninstallPSResource.Tests.ps1 b/Test/UninstallPSResource.Tests.ps1 new file mode 100644 index 0000000..d911010 --- /dev/null +++ b/Test/UninstallPSResource.Tests.ps1 @@ -0,0 +1,298 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Uninstall-PSResource' -tags 'CI' { + BeforeAll{ + $PSGalleryName = Get-PSGalleryName + $testModuleName = "testmodule99" + $testModuleName2 = "test_module" + $testScriptName = "test_script" + Get-NewPSResourceRepositoryFile + Set-PSResourceRepository PSGallery -Trusted + Uninstall-PSResource -Name $testModuleName -Version "*" -ErrorAction SilentlyContinue + Uninstall-PSResource -Name $testScriptName -Version "*" -ErrorAction SilentlyContinue + } + + BeforeEach { + Install-PSResource $testModuleName -Repository $PSGalleryName -WarningAction SilentlyContinue + Install-PSResource $testModuleName2 -Repository $PSGalleryName -SkipDependencyCheck -WarningAction SilentlyContinue + Install-PSResource $testScriptName -Repository $PSGalleryName -WarningAction SilentlyContinue + } + + AfterEach { + Uninstall-PSResource -Name $testModuleName -Version "*" -ErrorAction SilentlyContinue + Uninstall-PSResource -Name $testScriptName -Version "*" -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + It "Uninstall-Module" { + Uninstall-Module -Name $testModuleName + + $res = Get-InstalledPSResource $testModuleName + $res.Count | Should -Be 0 + } + + It "Uninstall-Script" { + Uninstall-Script -Name $testScriptName + + $res = Get-InstalledPSResource $testScriptName + $res.Count | Should -Be 0 + } + + It "Uninstall-Module with -AllVersions" { + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -AllVersions + + $res = Get-InstalledPSResource $testModuleName + $res.Count | Should -Be 0 + } + + It "Uninstall-Module with -MinimumVersion" { + $minVersion = "0.0.2" + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -MinimumVersion $minVersion + + $res = Get-InstalledPSResource $testModuleName + $res.Version | Should -BeLessThan $minVersion + } + + It "Uninstall-Module with -MaximumVersion" { + $maxVersion = "0.0.2" + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -MaximumVersion $maxVersion + + $res = Get-InstalledPSResource $testModuleName + $res.Version | Should -Not -Contain "0.0.1" + } + + It "Uninstall-Script with -AllVersions" { + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -AllVersions + + $res = Get-InstalledPSResource $testModuleName + $res.Count | Should -Be 0 + } + + It "Uninstall-Module with -MinimumVersion" { + $minVersion = "0.0.2" + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -MinimumVersion $minVersion + + $res = Get-InstalledPSResource $testModuleName + $res.Version | Should -BeLessThan $minVersion + } + + It "Uninstall-Module with -MaximumVersion" { + $maxVersion = "0.0.2" + Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" + Uninstall-Module -Name $testModuleName -MaximumVersion $maxVersion + + $res = Get-InstalledPSResource $testModuleName + $res.Version | Should -Not -Contain "0.0.1" + } + + It "Uninstall a module when given name and specifying all versions" { + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.1" -TrustRepository + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.2" -TrustRepository + $null = Install-PSResource $testModuleName -Repository $PSGalleryName -Version "0.0.3" -TrustRepository + + Uninstall-Module -Name $testModuleName -AllVersions + $pkgs = Get-InstalledPSResource $testModuleName + $pkgs.Version | Should -Not -Contain "0.0.1" + $pkgs.Version | Should -Not -Contain "0.0.2" + $pkgs.Version | Should -Not -Contain "0.0.3" + } + + It "Uninstall a module when given name and using the default version (ie all versions, not explicitly specified)" { + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "1.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "3.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "5.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + + Uninstall-Module -Name $testModuleName2 + $pkgs = Get-InstalledPSResource $testModuleName2 + $pkgs.Version | Should -Not -Contain "1.0.0" + $pkgs.Version | Should -Not -Contain "3.0.0" + $pkgs.Version | Should -Not -Contain "5.0.0" + } + + It "Uninstall module when given Name and specifying exact version" { + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "1.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "3.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "5.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + + Uninstall-Module -Name $testModuleName2 -RequiredVersion "3.0.0" + $pkgs = Get-InstalledPSResource -Name $testModuleName2 + $pkgs.Version | Should -Not -Contain "1.0.0" + } + + $testCases = @{Version="[1.0.0.0]"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match"}, + @{Version="1.0.0.0"; ExpectedVersion="1.0.0.0"; Reason="validate version, exact match without bracket syntax"} + It "Uninstall module when given Name to " -TestCases $testCases { + param($Version, $ExpectedVersion) + Uninstall-Module -Name $testModuleName2 -AllVersions + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "1.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "3.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + $null = Install-PSResource $testModuleName2 -Repository $PSGalleryName -Version "5.0.0" -SkipDependencyCheck -WarningAction SilentlyContinue + + Uninstall-Module -Name $testModuleName2 -RequiredVersion $Version + $pkgs = Get-InstalledPSResource $testModuleName2 + $pkgs.Version | Should -Not -Contain $Version + } + + $testCases2 = @{Version='[5.*.0]'; Description="version with wilcard in middle"}, + @{Version='[*.0.0.0]'; Description="version with wilcard at start"}, + @{Version='[5.*.0.0]'; Description="version with wildcard at second digit"}, + @{Version='[5.0.*.0]'; Description="version with wildcard at third digit"} + @{Version='[5.0.0.*]'; Description="version with wildcard at end"}, + @{Version='[5..0.0]'; Description="version with missing digit in middle"}, + @{Version='[5.0.0.]'; Description="version with missing digit at end"}, + @{Version='[5.0.0.0.0]'; Description="version with more than 4 digits"} + + It "Do not uninstall module with incorrectly formatted version such as " -TestCases $testCases2 { + param($Version, $Description) + + {Uninstall-Module -Name $testModuleName2 -RequiredVersion $Version} | Should -Throw "Argument for -Version parameter is not in the proper format." + } + + $testCases3 = @{Version='(5.0.0.0)'; Description="exclusive version (1.0.0.0)"}, + @{Version='[5-0-0-0]'; Description="version formatted with invalid delimiter"} + + It "Do not uninstall module with incorrectly formatted version such as " -TestCases $testCases3 { + param($Version, $Description) + + try { + Uninstall-Module -Name $testModuleName2 -Version $Version -ErrorAction SilentlyContinue + } + catch + {} + $pkg = Get-InstalledPSResource $testModuleName2 -Version "5.0.0.0" + $pkg.Version | Should -Be "5.0.0.0" + } + + It "Uninstall prerelease version module when prerelease version specified" { + $version = "1.0.0-beta2" + Install-PSResource -Name $testModuleName -Version $version -Repository $PSGalleryName + Uninstall-Module -Name $testModuleName -RequiredVersion $version + $res = Get-InstalledPSResource $testModuleName -Version "1.0.0" + $res | Should -BeNullOrEmpty + } + + It "Not uninstall non-prerelease version module when similar prerelease version is specified" { + # testmodule99 has a version 0.0.1, but no version 0.0.1-preview. + # despite the core version part being the same this uninstall on a nonexistant prerelease version should not be successful + Install-PSResource -Name $testModuleName -Version "0.0.1" -Repository $PSGalleryName + Uninstall-Module -Name $testModuleName -RequiredVersion "0.0.1-preview" -ErrorAction SilentlyContinue + $res = Get-InstalledPSResource -Name $testModuleName -Version "0.0.1" + $res.Name | Should -Be $testModuleName + $res.Version | Should -Be "0.0.1" + } + + It "Uninstall prerelease version script when prerelease version specified" { + Install-PSResource -Name $testScriptName -Version "3.0.0-alpha" -Repository $PSGalleryName -TrustRepository + Uninstall-Script -Name $testScriptName -RequiredVersion "3.0.0-alpha" + $res = Get-InstalledPSResource -Name $testScriptName + $res | Should -BeNullOrEmpty + } + + It "Not uninstall non-prerelease version module when prerelease version specified" { + Install-PSResource -Name $testScriptName -Version "2.5.0.0" -Repository $PSGalleryName -TrustRepository + Uninstall-Script -Name $testScriptName -RequiredVersion "2.5.0-alpha001" -ErrorAction SilentlyContinue + $res = Get-InstalledPSResource -Name $testScriptName -Version "2.5.0.0" + $res.Name | Should -Be $testScriptName + $res.Version | Should -Be "2.5" + } + + $testCases = @{Name="Test?Module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"}, + @{Name="Test[Module"; ErrorId="ErrorFilteringNamesForUnsupportedWildcards"} + + It "not uninstall module given Name with invalid wildcard characters" -TestCases $testCases { + param($Name, $ErrorId) + Uninstall-Module -Name $Name -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -Not -Be 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "$ErrorId,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource" + } + + It "Uninstall a list of modules by name" { + $null = Install-PSResource "testmodule99" -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue -SkipDependencyCheck + + Uninstall-Module -Name $testModuleName, "testmodule99" + Get-InstalledPSResource $testModuleName, "testmodule99" | Should -BeNullOrEmpty + } + + It "Uninstall a specific script by name" { + $null = Install-PSResource $testScriptName -Repository $PSGalleryName -TrustRepository + $res = Get-InstalledPSResource -Name $testScriptName + $res.Name | Should -Be $testScriptName + + Uninstall-Script -Name $testScriptName + $res = Get-InstalledPSResource -Name $testScriptName + $res | Should -BeNullOrEmpty + } + + It "Uninstall a list of scripts by name" { + $null = Install-PSResource $testScriptName, "Required-Script1" -Repository $PSGalleryName -TrustRepository + $res = Get-InstalledPSResource -Name $testScriptName + $res.Name | Should -Be $testScriptName + $res2 = Get-InstalledPSResource -Name "Required-Script1" + $res2.Name | Should -Be "Required-Script1" + + Uninstall-Script -Name $testScriptName, "Required-Script1" + $res = Get-InstalledPSResource -Name $testScriptName + $res | Should -BeNullOrEmpty + $res2 = Get-InstalledPSResource -Name "Required-Script1" + $res2 | Should -BeNullOrEmpty + } + + It "Uninstall module using -WhatIf, should not uninstall the module" { + Uninstall-Module -Name $testModuleName -WhatIf + $pkg = Get-InstalledPSResource $testModuleName + $pkg.Version | Should -Be "0.0.93" + } + + It "Do not Uninstall module that is a dependency for another module" { + $null = Install-PSResource "test_module" -Repository $PSGalleryName -TrustRepository -WarningAction SilentlyContinue + + Uninstall-Module -Name "RequiredModule1" -ErrorVariable ev -ErrorAction SilentlyContinue + + $pkg = Get-InstalledPSResource "RequiredModule1" + $pkg | Should -Not -Be $null + + $ev.FullyQualifiedErrorId | Should -BeExactly 'UninstallPSResourcePackageIsaDependency,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource', 'UninstallResourceError,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource' + } + + It "Uninstall PSResourceInfo object piped in" { + $version = "0.0.93" + Install-PSResource -Name $testModuleName -Version $version -Repository $PSGalleryName -TrustRepository + Get-InstalledPSResource -Name $testModuleName -Version $version | Uninstall-Module + $res = Get-InstalledPSResource -Name $testModuleName -Version $version + $res | Should -BeNullOrEmpty + } + + It "Uninstall PSResourceInfo object piped in for prerelease version object" { + Install-PSResource -Name $testModuleName -Version "1.0.0-beta2" -Repository $PSGalleryName -TrustRepository + Get-InstalledPSResource -Name $testModuleName -Version "1.0.0-beta2" | Uninstall-Module + $res = Get-InstalledPSResource -Name $testModuleName -Version "1.0.0-beta2" + $res | Should -BeNullOrEmpty + } + + It "Uninstall module that is not installed should throw error" { + Uninstall-Module -Name "NonInstalledModule" -ErrorVariable ev -ErrorAction SilentlyContinue + $ev.FullyQualifiedErrorId | Should -BeExactly 'UninstallResourceError,Microsoft.PowerShell.PowerShellGet.Cmdlets.UninstallPSResource' + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/UnregisterPSResourceRepository.Tests.ps1 b/Test/UnregisterPSResourceRepository.Tests.ps1 new file mode 100644 index 0000000..ca2a5b2 --- /dev/null +++ b/Test/UnregisterPSResourceRepository.Tests.ps1 @@ -0,0 +1,91 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe "Test CompatPowerShellGet: Unregister-PSResourceRepository" -tags 'CI' { + BeforeEach { + $PSGalleryName = Get-PSGalleryName + $PSGalleryUri = Get-PSGalleryLocation + Get-NewPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path) + Get-NewTestDirs($tmpDirPaths) + } + AfterEach { + Get-RevertPSResourceRepositoryFile + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2" + $tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3" + $tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path) + Get-RemoveTestDirs($tmpDirPaths) + } + + It "unregister single repository previously registered" { + Register-PSResourceRepository -Name "testRepository" -Uri $tmpDir1Path + Unregister-PSRepository -Name "testRepository" + + $res = Get-PSResourceRepository -Name "testRepository" -ErrorVariable err -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + } + + It "unregister multiple repositories previously registered" { + Register-PSResourceRepository -Name "testRepository" -Uri $tmpDir1Path + Register-PSResourceRepository -Name "testRepository2" -Uri $tmpDir2Path + Unregister-PSRepository -Name "testRepository","testRepository2" + + $res = Get-PSResourceRepository -Name "testRepository","testRepository2" -ErrorVariable err -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + } + + It "not unregister repo not previously registered and throw expected error message" { + $name = "nonRegisteredRepository" + {Unregister-PSRepository -Name $name -ErrorAction Stop} | Should -Throw -ErrorId "ErrorUnregisteringSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.UnregisterPSResourceRepository" + + } + + It "not register when -Name contains wildcard" { + Register-PSResourceRepository -Name "testRepository" -Uri $tmpDir1Path + Register-PSResourceRepository -Name "testRepository2" -Uri $tmpDir2Path + Unregister-PSRepository -Name "testRepository*" -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "nameContainsWildCardError,Microsoft.PowerShell.PowerShellGet.Cmdlets.UnregisterPSResourceRepository" + } + + It "when multiple repo Names provided, if one name isn't valid unregister the rest and write error message" { + $nonRegisteredRepoName = "nonRegisteredRepository" + Register-PSResourceRepository -Name "testRepository" -Uri $tmpDir1Path + Unregister-PSRepository -Name $nonRegisteredRepoName,"testRepository" -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorUnregisteringSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.UnregisterPSResourceRepository" + } + + It "throw error if Name is null or empty" { + {Unregister-PSRepository -Name "" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Unregister-PSRepository" + } + + It "throw error if Name is null" { + {Unregister-PSRepository -Name $null -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Unregister-PSRepository" + } + + It "unregister repository PSGallery" { + Unregister-PSRepository -Name $PSGalleryName + + $res = Get-PSResourceRepository -Name $PSGalleryName -ErrorVariable err -ErrorAction SilentlyContinue + $res | Should -BeNullOrEmpty + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/UpdatePSResource.Tests.ps1 b/Test/UpdatePSResource.Tests.ps1 new file mode 100644 index 0000000..3676663 --- /dev/null +++ b/Test/UpdatePSResource.Tests.ps1 @@ -0,0 +1,358 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Update-PSResource' -tags 'CI' { + + BeforeAll { + $PSGalleryName = Get-PSGalleryName + $NuGetGalleryName = Get-NuGetGalleryName + $testModuleName = "test_module" + $testModuleName2 = "TestModule99" + Get-NewPSResourceRepositoryFile + Get-PSResourceRepository + Set-PSResourceRepository -Name PSGallery -Trusted + } + + AfterEach { + Uninstall-PSResource "test_module", "TestModule99", "TestModuleWithLicense", "TestModuleWithDependencyB", "TestModuleWithDependencyD" -Version "*" -ErrorAction SilentlyContinue + } + + AfterAll { + Get-RevertPSResourceRepositoryFile + } + + It "Update-Module" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + Update-Module $testModuleName2 + + $res = Get-InstalledPSResource $testModuleName2 + $res.Version | Should -Contain "0.0.93" + } + + It "Update-Module with -RequiredVersion" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + Update-Module $testModuleName2 -RequiredVersion 0.0.93 -WarningVariable wv + $wv | Should -HaveCount 1 + + $res = Get-InstalledPSResource $testModuleName2 + $res.version | Should -Contain "0.0.93" + } + + It "Update-Module multiple modules" { + Install-Module "TestModuleWithDependencyB" -Repository PSGallery -RequiredVersion "2.0" + Install-Module "TestModuleWithDependencyD" -Repository PSGallery -RequiredVersion "1.0" + + Update-Module "TestModuleWithDependencyB", "TestModuleWithDependencyD" + $res = Get-InstalledPSResource "TestModuleWithDependencyB", "TestModuleWithDependencyD" + $res | Should -HaveCount 4 + $res.version | Should -Contain "2.0" + $res.version | Should -Contain "3.0" + } + + It "Update-Module with RequiredVersion and wildcard" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + Update-Module "testModule9*" + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 2 + $res.version | Should -Contain "0.0.93" + } + + It "Update-Module with -PassThru should return output" { + Install-Module $testModuleName2 -RequiredVersion 0.0.91 -Repository PSGallery + $res = Update-Module $testModuleName2 -PassThru + $res | Should -Not -BeNullOrEmpty + } + + It "Update-Module with lower -RequiredVersion should not update" { + Install-Module $testModuleName2 -Repository PSGallery + Update-Module $testModuleName2 -RequiredVersion 0.0.3 -ErrorAction SilentlyContinue + $res = Get-InstalledPSResource $testModuleName2 + $res.Count | Should -Be 1 + $res.version | Should -Be "0.0.93" + } + + It "UpdateAllModules" { + Install-Module $testModuleName2 -Repository PSGallery -RequiredVersion 0.0.7 + Install-Module "TestModuleWithDependencyB" -Repository PSGallery -RequiredVersion 2.0 + Install-Module "TestModuleWithDependencyD" -Repository PSGallery -RequiredVersion 1.0 + + Update-Module $testModuleName2, "TestModuleWithDependencyB", "TestModuleWithDependencyD" + $res = Get-InstalledPSResource $testModuleName2, "TestModuleWithDependencyB", "TestModuleWithDependencyD" + $res | Should -HaveCount 6 + $res.version | Should -Contain "0.0.93" + $res.version | Should -Contain "3.0" + $res.version | Should -Contain "2.0" + } + + It "Update-Module with not available -RequiredVersion" { + Install-Module $testModuleName2 -RequiredVersion "0.0.2" -Repository PSGallery + + Update-Module $testModuleName2 -RequiredVersion 10.0 -ErrorAction SilentlyContinue -ErrorVariable ev + + $res = Get-InstalledPSResource $testModuleName2 + $res | Should -HaveCount 1 + $res.Version | Should -Be ([System.Version]"0.0.2") + } + + It "Update-Module with Dependencies" { + $parentModule = "TestModuleWithDependencyC" + $childModule1 = "TestModuleWithDependencyB" + $childModule2 = "TestModuleWithDependencyD" + $childModule3 = "TestModuleWithDependencyF" + Install-Module $parentModule -Repository PSGallery -RequiredVersion "3.0" + Update-Module $parentModule + + $res = Get-InstalledPSResource $parentModule, $childModule1, $childModule2, $childModule3 + $res | Should -HaveCount 8 + $res.Version | Should -Contain "5.0" + } + + It "Update resource installed given Name and Version (specific) parameters" { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + + Update-Module -Name $testModuleName -RequiredVersion "5.0.0.0" + $res = Get-InstalledPSResource -Name $testModuleName + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -eq [System.Version]"5.0.0.0") + { + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -BeTrue + } + + $testCases2 = @{Version="[3.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, exact match"}, + @{Version="3.0.0.0"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, exact match without bracket syntax"}, + @{Version="[3.0.0.0, 5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range inclusive"}, + @{Version="(3.0.0.0, 6.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, exact range exclusive"}, + @{Version="(3.0.0.0,)"; ExpectedVersions=@("1.0.0.0", "5.0.0.0"); Reason="validate version, minimum version exclusive"}, + @{Version="[3.0.0.0,)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, minimum version inclusive"}, + @{Version="(,5.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, maximum version exclusive"}, + @{Version="(,5.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0", "5.0.0.0"); Reason="validate version, maximum version inclusive"}, + @{Version="[1.0.0.0, 5.0.0.0)"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, mixed inclusive minimum and exclusive maximum version"} + @{Version="(1.0.0.0, 3.0.0.0]"; ExpectedVersions=@("1.0.0.0", "3.0.0.0"); Reason="validate version, mixed exclusive minimum and inclusive maximum version"} + + It "Update resource when given Name to " -TestCases $testCases2{ + param($Version, $ExpectedVersions) + + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-Module -Name $testModuleName -RequiredVersion $Version + + $res = Get-InstalledPSResource -Name $testModuleName + + foreach ($item in $res) { + $item.Name | Should -Be $testModuleName + $ExpectedVersions | Should -Contain $item.Version + } + } + + $testCases = @( + @{Version='(3.0.0.0)'; Description="exclusive version (3.0.0.0)"}, + @{Version='[3-0-0-0]'; Description="version formatted with invalid delimiter [3-0-0-0]"} + ) + It "Should not update resource with incorrectly formatted version such as " -TestCases $testCases{ + param($Version, $Description) + + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-Module -Name $testModuleName -RequiredVersion $Version 2>$null + + $res = Get-InstalledPSResource -Name $testModuleName + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $false + } + + It "Update resource with latest (including prerelease) version given Prerelease parameter" { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-Module -Name $testModuleName -AllowPrerelease + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -ge [System.Version]"5.2.5") + { + $pkg.Prerelease | Should -Be "alpha001" + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + # Windows only + It "update resource under CurrentUser scope" -skip:(!($IsWindows -and (Test-IsAdmin))) { + # TODO: perhaps also install TestModule with the highest version (the one above 1.2.0.0) to the AllUsers path too + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + + Update-Module -Name $testModuleName -RequiredVersion "3.0.0.0" -Scope CurrentUser + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $pkg.InstalledLocation.Contains("Documents") | Should -Be $true + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + # Windows only + It "update resource under AllUsers scope" -skip:(!($IsWindows -and (Test-IsAdmin))) { + Install-PSResource -Name "testmodule99" -Version "0.0.91" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name "testmodule99" -Version "0.0.91" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + + Update-Module -Name "testmodule99" -RequiredVersion "0.0.93" -Scope AllUsers + + $res = Get-Module -Name "testmodule99" -ListAvailable + $res | Should -Not -BeNullOrEmpty + $res.Version | Should -Contain "0.0.93" + } + + # Windows only + It "Update resource under no specified scope" -skip:(!$IsWindows) { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-Module -Name $testModuleName -RequiredVersion "3.0.0.0" + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $pkg.InstalledLocation.Contains("Documents") | Should -Be $true + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Update resource under CurrentUser scope - Unix only" -Skip:(Get-IsWindows) { + # this line is commented out because AllUsers scope requires sudo and that isn't supported in CI yet + # Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + + Update-Module -Name $testModuleName -Scope CurrentUser + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $pkg.InstalledLocation.Contains("$env:HOME/.local") | Should -Be $true + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/usr/local/share/powershell/Modules' + # this test is skipped because it requires sudo to run and has yet to be resolved in CI + It "Update resource under AllUsers scope - Unix only" -Skip:($true) { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + + Update-Module -Name $testModuleName -Scope AllUsers + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $pkg.InstalledLocation.Contains("usr") | Should -Be $true + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + # Unix only + # Expected path should be similar to: '/home/janelane/.local/share/powershell/Modules' + It "Update resource under no specified scope - Unix only" -Skip:(Get-IsWindows) { + # this is commented out because it requires sudo to run with AllUsers scope and this hasn't been resolved in CI yet + # Install-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName -Scope AllUsers + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository -Scope CurrentUser + + Update-Module -Name $testModuleName + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $pkg.InstalledLocation.Contains("$env:HOME/.local") | Should -Be $true + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } + + It "Update module using -WhatIf, should not update the module" { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + Update-Module -Name $testModuleName -WhatIf + + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $false + } + + It "Update resource installed given -Name and -PassThru parameters" { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + + $res = Update-Module -Name $testModuleName -RequiredVersion "3.0.0.0" -PassThru + $res.Name | Should -Contain $testModuleName + $res.Version | Should -Contain "3.0.0.0" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file diff --git a/Test/UpdatePSScriptFileInfo.Tests.ps1 b/Test/UpdatePSScriptFileInfo.Tests.ps1 new file mode 100644 index 0000000..64adfbc --- /dev/null +++ b/Test/UpdatePSScriptFileInfo.Tests.ps1 @@ -0,0 +1,314 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" +$testDir = (get-item $psscriptroot).parent.FullName + +Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { + BeforeAll { + $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" + $tmpDirPaths = @($tmpDir1Path) + Get-NewTestDirs($tmpDirPaths) + + # Path to folder, within our test folder, where we store invalid module and script files used for testing + $script:testFilesFolderPath = Join-Path $testDir -ChildPath "testFiles" + + # Path to specifically to that invalid test scripts folder + $script:testScriptsFolderPath = Join-Path $testFilesFolderPath -ChildPath "testScripts" + + $script:newline = [System.Environment]::NewLine; + } + + BeforeEach { + $script:psScriptInfoName = "test_script" + $scriptDescription = "this is a test script" + $script:testScriptFilePath = Join-Path -Path $tmpDir1Path -ChildPath "$script:psScriptInfoName.ps1" + New-PSScriptFile -Path $script:testScriptFilePath -Description $scriptDescription + } + + AfterEach { + if (Test-Path -Path $script:testScriptFilePath) + { + Remove-Item $script:testScriptFilePath + } + } + + It "Update .ps1 file with relative path" { + $relativeCurrentPath = Get-Location + $scriptFilePath = Join-Path -Path $relativeCurrentPath -ChildPath "$script:psScriptInfoName.ps1" + $oldDescription = "Old description for test script" + $newDescription = "New description for test script" + New-PSScriptFile -Path $scriptFilePath -Description $oldDescription + + Update-ScriptFileInfo -Path $scriptFilePath -Description $newDescription + Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + + Test-Path -Path $scriptFilePath | Should -BeTrue + $results = Get-Content -Path $scriptFilePath -Raw + $results.Contains($newDescription) | Should -BeTrue + $results -like "*.DESCRIPTION$script:newline*$newDescription*" | Should -BeTrue + + Remove-Item -Path $scriptFilePath -Force + } + + It "Update script should not overwrite old script data unless that property is specified" { + $description = "Test Description" + $version = "3.0.0" + $author = "John Doe" + $newAuthor = "Jane Doe" + $projectUri = "https://testscript.com/" + + $relativeCurrentPath = Get-Location + $scriptFilePath = Join-Path -Path $relativeCurrentPath -ChildPath "$script:psScriptInfoName.ps1" + + New-PSScriptFile -Path $scriptFilePath -Description $description -Version $version -Author $author -ProjectUri $projectUri + Update-ScriptFileInfo -Path $scriptFilePath -Author $newAuthor + + Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + $results = Get-Content -Path $scriptFilePath -Raw + $results.Contains($newAuthor) | Should -BeTrue + $results.Contains(".AUTHOR $newAuthor") | Should -BeTrue + + # rest should be original data used when creating the script + $results.Contains($projectUri) | Should -BeTrue + $results.Contains(".PROJECTURI $projectUri") | Should -BeTrue + + $results.Contains($version) | Should -BeTrue + $results.Contains(".VERSION $version") | Should -BeTrue + + $results.Contains($description) | Should -BeTrue + $results -like "*.DESCRIPTION$script:newline*$description*" | Should -BeTrue + + Remove-Item -Path $scriptFilePath -Force + } + + It "update script file Author property" { + $author = "New Author" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Author $author + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($author) | Should -BeTrue + $results.Contains(".AUTHOR $author") | Should -BeTrue + } + + It "update script file Version property" { + $version = "2.0.0.0" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Version $version + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($version) | Should -BeTrue + $results.Contains(".VERSION $version") | Should -BeTrue + } + + It "update script file Version property with prerelease version" { + $version = "3.0.0-alpha" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Version $version + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($version) | Should -BeTrue + $results.Contains(".VERSION $version") | Should -BeTrue + } + + It "not update script file with invalid version" { + Update-ScriptFileInfo -Path $script:testScriptFilePath -Version "4.0.0.0.0" -ErrorVariable err -ErrorAction SilentlyContinue + $err.Count | Should -Not -Be 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly "VersionParseIntoNuGetVersion,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSScriptFileInfo" + } + + It "update script file Description property" { + $description = "this is an updated test script" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Description $description + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($description) | Should -BeTrue + $results -like "*.DESCRIPTION$script:newline*$description*" | Should -BeTrue + } + + It "update script file Guid property" { + $guid = [Guid]::NewGuid(); + Update-ScriptFileInfo -Path $script:testScriptFilePath -Guid $guid + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($guid) | Should -BeTrue + $results.Contains(".GUID $guid") | Should -BeTrue + } + + It "update script file CompanyName property" { + $companyName = "New Corporation" + Update-ScriptFileInfo -Path $script:testScriptFilePath -CompanyName $companyName + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($companyName) | Should -BeTrue + $results.Contains(".COMPANYNAME $companyName") | Should -BeTrue + } + + It "update script file Copyright property" { + $copyright = "(c) 2022 New Corporation. All rights reserved" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Copyright $copyright + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($copyright) | Should -BeTrue + $results.Contains(".COPYRIGHT $copyright") | Should -BeTrue + } + + It "update script file ExternalModuleDependencies property" { + $externalModuleDep1 = "ExternalModuleDep1" + $externalModuleDep2 = "ExternalModuleDep2" + Update-ScriptFileInfo -Path $script:testScriptFilePath -ExternalModuleDependencies $externalModuleDep1,$externalModuleDep2 + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($externalModuleDep1) | Should -BeTrue + $results.Contains($externalModuleDep2) | Should -BeTrue + $results -like "*.EXTERNALMODULEDEPENDENCIES*$externalModuleDep1*$externalModuleDep2*" | Should -BeTrue + } + + It "update script file ExternalScriptDependencies property" { + $externalScriptDep1 = "ExternalScriptDep1" + $externalScriptDep2 = "ExternalScriptDep2" + Update-ScriptFileInfo -Path $script:testScriptFilePath -ExternalScriptDependencies $externalScriptDep1,$externalScriptDep2 + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($externalScriptDep1) | Should -BeTrue + $results.Contains($externalScriptDep2) | Should -BeTrue + $results -like "*.EXTERNALMODULEDEPENDENCIES*$externalScriptDep1*$externalScriptDep2*" | Should -BeTrue + } + + It "update script file IconUri property" { + $iconUri = "https://testscript.com/icon" + Update-ScriptFileInfo -Path $script:testScriptFilePath -IconUri $iconUri + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($iconUri) | Should -BeTrue + $results.Contains(".ICONURI $iconUri") | Should -BeTrue + } + + It "update script file LicenseUri property" { + $licenseUri = "https://testscript.com/license" + Update-ScriptFileInfo -Path $script:testScriptFilePath -LicenseUri $licenseUri + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($licenseUri) | Should -BeTrue + $results.Contains(".LICENSEURI $licenseUri") | Should -BeTrue + } + + It "update script file ProjectUri property" { + $projectUri = "https://testscript.com/" + Update-ScriptFileInfo -Path $script:testScriptFilePath -ProjectUri $projectUri + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($projectUri) | Should -BeTrue + $results.Contains(".PROJECTURI $projectUri") | Should -BeTrue + } + + It "update script file PrivateData property" { + $privateData = "this is some private data" + Update-ScriptFileInfo -Path $script:testScriptFilePath -PrivateData $privateData + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($privateData) | Should -BeTrue + $results -like "*.PRIVATEDATA*$privateData*" | Should -BeTrue + } + + It "update script file ReleaseNotes property" { + $releaseNotes = "Release notes for script." + Update-ScriptFileInfo -Path $script:testScriptFilePath -ReleaseNotes $releaseNotes + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($releaseNotes) | Should -BeTrue + $results -like "*.RELEASENOTES$script:newline*$releaseNotes*" | Should -BeTrue + } + + It "update script file RequiredModules property" { + $hashtable1 = @{ModuleName = "RequiredModule1"} + $hashtable2 = @{ModuleName = "RequiredModule2"; ModuleVersion = "1.0.0.0"} + $hashtable3 = @{ModuleName = "RequiredModule3"; RequiredVersion = "2.5.0.0"} + $hashtable4 = @{ModuleName = "RequiredModule4"; ModuleVersion = "1.1.0.0"; MaximumVersion = "2.0.0.0"} + $requiredModules = @($hashtable1, $hashtable2, $hashtable3, $hashtable4) + + Update-ScriptFileInfo -Path $script:testScriptFilePath -RequiredModules $requiredModules + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + + $results.Contains("#Requires -Module RequiredModule1") | Should -BeTrue + $results -like "*#Requires*ModuleName*Version*" | Should -BeTrue + } + + It "update script file RequiredScripts property" { + $requiredScript1 = "RequiredScript1" + $requiredScript2 = "RequiredScript2" + Update-ScriptFileInfo -Path $script:testScriptFilePath -RequiredScripts $requiredScript1, $requiredScript2 + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($requiredScript1) | Should -BeTrue + $results.Contains($requiredScript2) | Should -BeTrue + $results -like "*.REQUIREDSCRIPTS*$requiredScript1*$requiredScript2*" | Should -BeTrue + } + + It "update script file Tags property" { + $tag1 = "tag1" + $tag2 = "tag2" + Update-ScriptFileInfo -Path $script:testScriptFilePath -Tags $tag1, $tag2 + Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + + Test-Path -Path $script:testScriptFilePath | Should -BeTrue + $results = Get-Content -Path $script:testScriptFilePath -Raw + $results.Contains($tag1) | Should -BeTrue + $results.Contains($tag2) | Should -BeTrue + $results.Contains(".TAGS $tag1 $tag2") | Should -BeTrue + } + + It "throw error when attempting to update a signed script without -RemoveSignature parameter" { + # Note: user should sign the script again once it's been updated + + $scriptName = "ScriptWithSignature.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + # use a copy of the signed script file so we can re-use for other tests + $null = Copy-Item -Path $scriptFilePath -Destination $TestDrive + $tmpScriptFilePath = Join-Path -Path $TestDrive -ChildPath $scriptName + + { Update-ScriptFileInfo -Path $tmpScriptFilePath -Version "2.0.0.0" } | Should -Throw -ErrorId "ScriptToBeUpdatedContainsSignature,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSScriptFileInfo" + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file From eb7854955e4cb71b83c4c100d803f9569e7f5479 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 3 May 2023 15:39:10 -0700 Subject: [PATCH 13/74] add test helper files --- Test/PSGetModuleInfo.xml | 153 ++++++++++++++++++ .../incorrectdepmoduleversion.psd1 | 132 +++++++++++++++ .../incorrectmoduleversion.psd1 | 132 +++++++++++++++ .../InvalidScriptMissingAuthor.ps1 | 43 +++++ .../InvalidScriptMissingAuthorAndVersion.ps1 | 43 +++++ .../InvalidScriptMissingDescription.ps1 | 42 +++++ ...idScriptMissingDescriptionCommentBlock.ps1 | 37 +++++ .../testScripts/InvalidScriptMissingGuid.ps1 | 43 +++++ .../InvalidScriptMissingVersion.ps1 | 43 +++++ .../ScriptWithInvalidProjectUri.ps1 | 39 +++++ .../testScripts/ScriptWithSignature.ps1 | 75 +++++++++ ...tWithoutEmptyLinesBetweenCommentBlocks.ps1 | 24 +++ .../ScriptWithoutEmptyLinesInMetadata.ps1 | 23 +++ Test/testRepositories.xml | 5 + 14 files changed, 834 insertions(+) create mode 100644 Test/PSGetModuleInfo.xml create mode 100644 Test/testFiles/testModules/incorrectdepmoduleversion/incorrectdepmoduleversion.psd1 create mode 100644 Test/testFiles/testModules/incorrectmoduleversion/incorrectmoduleversion.psd1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingAuthor.ps1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingAuthorAndVersion.ps1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingDescription.ps1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingDescriptionCommentBlock.ps1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingGuid.ps1 create mode 100644 Test/testFiles/testScripts/InvalidScriptMissingVersion.ps1 create mode 100644 Test/testFiles/testScripts/ScriptWithInvalidProjectUri.ps1 create mode 100644 Test/testFiles/testScripts/ScriptWithSignature.ps1 create mode 100644 Test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 create mode 100644 Test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 create mode 100644 Test/testRepositories.xml diff --git a/Test/PSGetModuleInfo.xml b/Test/PSGetModuleInfo.xml new file mode 100644 index 0000000..8f74623 --- /dev/null +++ b/Test/PSGetModuleInfo.xml @@ -0,0 +1,153 @@ + + + + Microsoft.PowerShell.Commands.PSRepositoryItemInfo + System.Management.Automation.PSCustomObject + System.Object + + + Microsoft.PowerShell.SecretManagement + 1.1.0-preview2 + Module + This module provides a convenient way for a user to store and retrieve secrets. The secrets are_x000D__x000A_stored in registered extension vaults. An extension vault can store secrets locally or remotely._x000D__x000A_SecretManagement coordinates access to the secrets through the registered vaults._x000D__x000A__x000D__x000A_Go to GitHub for more information about the module and to submit issues:_x000D__x000A_https://github.com/powershell/SecretManagement + Microsoft Corporation + Microsoft Corporation + (c) Microsoft Corporation. All rights reserved. +
2021-03-25T18:08:10-07:00
+ true + +
2021-03-25T11:12:41.7662015-07:00
+ + + + Microsoft.PowerShell.Commands.DisplayHintType + System.Enum + System.ValueType + System.Object + + DateTime + 2 + + +
+ + https://github.com/PowerShell/SecretManagement/blob/master/LICENSE + https://github.com/powershell/secretmanagement + + + + System.Object[] + System.Array + System.Object + + + PSModule + PSEdition_Core + + + + + System.Collections.Hashtable + System.Object + + + + DscResource + + + + + + + RoleCapability + + + + Function + + + + Cmdlet + + + + Register-SecretVault + Unregister-SecretVault + Get-SecretVault + Set-SecretVaultDefault + Test-SecretVault + Set-Secret + Set-SecretInfo + Get-Secret + Get-SecretInfo + Remove-Secret + + + + + Command + + + + Register-SecretVault + Unregister-SecretVault + Get-SecretVault + Set-SecretVaultDefault + Test-SecretVault + Set-Secret + Set-SecretInfo + Get-Secret + Get-SecretInfo + Remove-Secret + + + + + Workflow + + + + + + + + + + + https://www.powershellgallery.com/api/v2 + PSGallery + NuGet + + + System.Management.Automation.PSCustomObject + System.Object + + + (c) Microsoft Corporation. All rights reserved. + This module provides a convenient way for a user to store and retrieve secrets. The secrets are_x000D__x000A_stored in registered extension vaults. An extension vault can store secrets locally or remotely._x000D__x000A_SecretManagement coordinates access to the secrets through the registered vaults._x000D__x000A__x000D__x000A_Go to GitHub for more information about the module and to submit issues:_x000D__x000A_https://github.com/powershell/SecretManagement + False + True + True + 0 + 15034 + 55046 + 3/25/2021 6:08:10 PM -07:00 + 3/25/2021 6:08:10 PM -07:00 + 3/25/2021 6:08:10 PM -07:00 + PSModule PSEdition_Core PSCmdlet_Register-SecretVault PSCommand_Register-SecretVault PSCmdlet_Unregister-SecretVault PSCommand_Unregister-SecretVault PSCmdlet_Get-SecretVault PSCommand_Get-SecretVault PSCmdlet_Set-SecretVaultDefault PSCommand_Set-SecretVaultDefault PSCmdlet_Test-SecretVault PSCommand_Test-SecretVault PSCmdlet_Set-Secret PSCommand_Set-Secret PSCmdlet_Set-SecretInfo PSCommand_Set-SecretInfo PSCmdlet_Get-Secret PSCommand_Get-Secret PSCmdlet_Get-SecretInfo PSCommand_Get-SecretInfo PSCmdlet_Remove-Secret PSCommand_Remove-Secret PSIncludes_Cmdlet + False + 2021-03-25T18:08:10Z + 1.1.0-preview2 + Microsoft Corporation + true + Module + Microsoft.PowerShell.SecretManagement.nuspec|Microsoft.PowerShell.SecretManagement.dll|Microsoft.PowerShell.SecretManagement.format.ps1xml|Microsoft.PowerShell.SecretManagement.psd1|en-US\about_Microsoft.PowerShell.SecretManagement.help.txt|en-US\Microsoft.PowerShell.SecretManagement.dll-Help.xml + a5c858f6-4a8e-41f1-b1ee-0ff8f6ad69d3 + 5.1 + Microsoft Corporation + + + C:\Users\paulhi\OneDrive - Microsoft\Documents\PowerShell\Modules\Microsoft.PowerShell.SecretManagement\1.0.0 +
+
+
diff --git a/Test/testFiles/testModules/incorrectdepmoduleversion/incorrectdepmoduleversion.psd1 b/Test/testFiles/testModules/incorrectdepmoduleversion/incorrectdepmoduleversion.psd1 new file mode 100644 index 0000000..03769fd --- /dev/null +++ b/Test/testFiles/testModules/incorrectdepmoduleversion/incorrectdepmoduleversion.psd1 @@ -0,0 +1,132 @@ +# +# Module manifest for module 'testmodule-incorrect' +# +# Generated by: americks +# +# Generated on: 5/18/2022 +# + +@{ + + # Script module or binary module file associated with this manifest. + # RootModule = '' + + # Version number of this module. + ModuleVersion = '1.0.0.0' + + # Supported PSEditions + # CompatiblePSEditions = @() + + # ID used to uniquely identify this module + GUID = '4f56ed2b-72af-4c29-bda6-ef3dc91c1624' + + # Author of this module + Author = 'americks' + + # Company or vendor of this module + CompanyName = 'Unknown' + + # Copyright statement for this module + Copyright = '(c) americks. All rights reserved.' + + # Description of the functionality provided by this module + Description = 'incorrectdepmoduleversion module' + + # Minimum version of the PowerShell engine required by this module + # PowerShellVersion = '' + + # Name of the PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # ClrVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = @(@{ModuleName = 'PackageManagement'; ModuleVersion = '1..0.0'; }) + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = '*' + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = '*' + + # Variables to export from this module + VariablesToExport = '*' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = '*' + + # DSC resources to export from this module + # DscResourcesToExport = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + + } + \ No newline at end of file diff --git a/Test/testFiles/testModules/incorrectmoduleversion/incorrectmoduleversion.psd1 b/Test/testFiles/testModules/incorrectmoduleversion/incorrectmoduleversion.psd1 new file mode 100644 index 0000000..83f6245 --- /dev/null +++ b/Test/testFiles/testModules/incorrectmoduleversion/incorrectmoduleversion.psd1 @@ -0,0 +1,132 @@ +# +# Module manifest for module 'testmodule-incorrect' +# +# Generated by: americks +# +# Generated on: 5/18/2022 +# + +@{ + +# Script module or binary module file associated with this manifest. +# RootModule = '' + +# Version number of this module. +ModuleVersion = '1..0.0' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '4f56ed2b-72af-4c29-bda6-ef3dc91c1604' + +# Author of this module +Author = 'americks' + +# Company or vendor of this module +CompanyName = 'Unknown' + +# Copyright statement for this module +Copyright = '(c) americks. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'incorrectmoduleversion module' + +# Minimum version of the PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# ClrVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @(@{ModuleName = 'PackageManagement'; ModuleVersion = '1.0.0.0'; }) + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = '*' + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = '*' + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = '*' + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingAuthor.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingAuthor.ps1 new file mode 100644 index 0000000..11ecd96 --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingAuthor.ps1 @@ -0,0 +1,43 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() + + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingAuthorAndVersion.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingAuthorAndVersion.ps1 new file mode 100644 index 0000000..fc69050 --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingAuthorAndVersion.ps1 @@ -0,0 +1,43 @@ + +<#PSScriptInfo + +.VERSION + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() + + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingDescription.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingDescription.ps1 new file mode 100644 index 0000000..cdfed58 --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingDescription.ps1 @@ -0,0 +1,42 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR annavied + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + +#> +Param() + + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingDescriptionCommentBlock.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingDescriptionCommentBlock.ps1 new file mode 100644 index 0000000..b3cd98e --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingDescriptionCommentBlock.ps1 @@ -0,0 +1,37 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR annavied + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +Param() + + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingGuid.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingGuid.ps1 new file mode 100644 index 0000000..7cf637e --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingGuid.ps1 @@ -0,0 +1,43 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID + +.AUTHOR annavied + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() + + diff --git a/Test/testFiles/testScripts/InvalidScriptMissingVersion.ps1 b/Test/testFiles/testScripts/InvalidScriptMissingVersion.ps1 new file mode 100644 index 0000000..1c05323 --- /dev/null +++ b/Test/testFiles/testScripts/InvalidScriptMissingVersion.ps1 @@ -0,0 +1,43 @@ + +<#PSScriptInfo + +.VERSION + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR annavied + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() + + diff --git a/Test/testFiles/testScripts/ScriptWithInvalidProjectUri.ps1 b/Test/testFiles/testScripts/ScriptWithInvalidProjectUri.ps1 new file mode 100644 index 0000000..20a292f --- /dev/null +++ b/Test/testFiles/testScripts/ScriptWithInvalidProjectUri.ps1 @@ -0,0 +1,39 @@ +<#PSScriptInfo + +.VERSION 1.0.0.0 + +.GUID 465905fb-e242-4ead-a186-ea2ecf37d280 + +.AUTHOR alyssavu + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI www.powershellgallery.com/api/v2 + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + + +.PRIVATEDATA + + +#> +<# + +.DESCRIPTION +This is a test file for a script with invalid ProjectUri + +#> diff --git a/Test/testFiles/testScripts/ScriptWithSignature.ps1 b/Test/testFiles/testScripts/ScriptWithSignature.ps1 new file mode 100644 index 0000000..9bd193a --- /dev/null +++ b/Test/testFiles/testScripts/ScriptWithSignature.ps1 @@ -0,0 +1,75 @@ + +<#PSScriptInfo + +.VERSION 1.0 + +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd + +.AUTHOR annavied + +.COMPANYNAME + +.COPYRIGHT + +.TAGS + +.LICENSEURI + +.PROJECTURI + +.ICONURI + +.EXTERNALMODULEDEPENDENCIES + +.REQUIREDSCRIPTS + +.EXTERNALSCRIPTDEPENDENCIES + +.RELEASENOTES + +.PRIVATEDATA + +#> + +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() + + + +# SIG # Begin signature block +# MIIFbQYJKoZIhvcNAQcCoIIFXjCCBVoCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB +# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUhY04RvNe0Q8hliL7qS3/X9kr +# QVugggMIMIIDBDCCAeygAwIBAgIQN+zCRZRKiphJ5gGoRKvpeTANBgkqhkiG9w0B +# AQsFADAaMRgwFgYDVQQDDA9Db2RlU2lnbmluZ0NlcnQwHhcNMjIwNjIyMTgyODUx +# WhcNMjQwNjIyMTgzODUwWjAaMRgwFgYDVQQDDA9Db2RlU2lnbmluZ0NlcnQwggEi +# MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCf7gQAR4AVpVc4/4OlffaEQ6uE +# klG01+ga7sZbV7z9UkJFIDbntapCoXV85w/bNbmWSI+IUDisVBS7BIoicKagHskE +# YhRJv6WL/zxD2lWP21MRkEJBEMicbrj38F2R/khGDq/T5/a1XH+7QVAsf1kOG/oU +# d0CUDqgsR5+JdpaMt/QRM/jFLEUdvs+7zCvduciEEQRFFUbYYqy9RfmxMpPxZ6CM +# RjLVr5k4tirbg1YyBK6l7xPvT3BUejGvEYPOdAskPXMVbMO37DyEszudqOz9eEvp +# yHCKOgePLeq+9DbOQ+fAy30c79YNU5JfvgaDY+3c99WQXSeQuLYNDUeDDPGxAgMB +# AAGjRjBEMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNV +# HQ4EFgQUrmtlJTMGV5h8ksEMzPTPYk04g3IwDQYJKoZIhvcNAQELBQADggEBAAR3 +# sIiiVgSxUiPzGS/Ivwgjvqfsb6HXioE9VIJxQPwXc63LqC01TGJpeGayjr5zQ4p5 +# vt9q8WsiZvoUMofWzabz4BdprGWVDrO8hwksIixF8ojbfLuAra1cZ4qkDZtJH2Sn +# 0dUhvXabZqLuVghMiyqcSvs2hN8OiVI+tLzW8VQKzbFdj77c+lHxKBTkcKVpLiSI +# V2V8P4zRxyYE+CMlpTr58ErOGVxP1zITou7fwCAXdWEKWo5nlU22VNF6oGE9tghm +# S3M5PQT8lFCjZOPPKx+0oLDxwjluHENXZzH+61ugrszzRjK1rG3D3emrRYh/4BcG +# Wy7J1H41povt21JlzEExggHPMIIBywIBATAuMBoxGDAWBgNVBAMMD0NvZGVTaWdu +# aW5nQ2VydAIQN+zCRZRKiphJ5gGoRKvpeTAJBgUrDgMCGgUAoHgwGAYKKwYBBAGC +# NwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgor +# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUbfriqhB/ +# EKzgoXnVu2UFtaTb040wDQYJKoZIhvcNAQEBBQAEggEAiQa/HUhDP1HyrPh7mC5H +# 6IwOdxL4p3EIkGeuUh3ZqWRNFLNz0ob24vqmKBtaKTfJqqrxTIBYeoBKB3Y8Wcx2 +# rEaH31WqQM2U7mFvM2cVv6dcrdWmLcMwi3LSEMxJf6VbWpbmWZK6zMRW2H76P5wQ +# cs6BUOwKZq/5eQcQLjJ3h+Mh5dsENZ7scB4U1yihD7Ggvrgxf54+J/TS8XuDsx2o +# g0czxIjMBwT5wGh8BqbC50izZ3D0WRFe7UNnhMk7zKG/bvIRBxah+JV25hdoGYaR +# 2tdmgr4EMPoB1ti8DOFmYAicckDWfX7/X4NzeM234LSMLtOxO2lVj5jhkmJJdjKh +# WA== +# SIG # End signature block \ No newline at end of file diff --git a/Test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 b/Test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 new file mode 100644 index 0000000..8d8d2aa --- /dev/null +++ b/Test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 @@ -0,0 +1,24 @@ + +<#PSScriptInfo +.VERSION 1.0 +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd +.AUTHOR annavied +.COMPANYNAME +.COPYRIGHT +.TAGS +.LICENSEURI +.PROJECTURI +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +.PRIVATEDATA +#> +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() diff --git a/Test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 b/Test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 new file mode 100644 index 0000000..2b28db6 --- /dev/null +++ b/Test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 @@ -0,0 +1,23 @@ + +<#PSScriptInfo +.VERSION 1.0 +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd +.AUTHOR annavied +.COMPANYNAME +.COPYRIGHT +.TAGS +.LICENSEURI +.PROJECTURI +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +.PRIVATEDATA +#> + +<# +.DESCRIPTION + this is a test for a script that will be published remotely +#> +Param() diff --git a/Test/testRepositories.xml b/Test/testRepositories.xml new file mode 100644 index 0000000..1e330dd --- /dev/null +++ b/Test/testRepositories.xml @@ -0,0 +1,5 @@ + + + + + From c5d97df61b5a365dcde520833d33568c0f20dbdd Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 3 May 2023 15:42:31 -0700 Subject: [PATCH 14/74] update psd1 --- src/CompatPowerShellGet.psd1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CompatPowerShellGet.psd1 b/src/CompatPowerShellGet.psd1 index 30474ba..b5cfe62 100644 --- a/src/CompatPowerShellGet.psd1 +++ b/src/CompatPowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'CompatPowerShellGet.psm1' - ModuleVersion = '0.0.3' + ModuleVersion = '0.0.4' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -54,6 +54,10 @@ LicenseUri = 'https://github.com/PowerShell/CompatPowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/CompatPowerShellGet' ReleaseNotes = @' +### 0.0.4 +* Changes +- Update module to be compatible with latest version of PowerShellGet (3.0.21-beta21) + ### 0.0.3 * Changes - Updated reference to PowerShellGet 'Url' parameter to 'Uri' to reflect changes made in PowerShellGet From 0d37b897a455edf612ffc7cefbb833807e8d1572 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Mon, 8 May 2023 14:32:07 -0400 Subject: [PATCH 15/74] change image and set useMinimatch for ESRP sign task to true --- .ci/releaseBuild.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 2338f40..6b1bf15 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -33,7 +33,9 @@ stages: - stage: Build displayName: Build pool: - name: Package ES CodeHub Lab E + name: 1ES + demands: + - ImageOverride -equals PSMMS2019-Secure jobs: - job: Build_Job displayName: Build Microsoft.PowerShell.CompatPowerShellGet @@ -93,6 +95,7 @@ stages: pattern: | **\*.psd1 **\*.psm1 + useMinimatch: true # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. @@ -107,7 +110,9 @@ stages: jobs: - job: Compliance_Job pool: - name: Package ES CodeHub Lab E + name: 1ES + demands: + - ImageOverride -equals PSMMS2019-Secure steps: - checkout: self - checkout: ComplianceRepo From 023b3e615e2e2c6b43211df11a425ce58c4edb3f Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 12:18:10 -0700 Subject: [PATCH 16/74] Add publish tasks to release yaml --- .ci/releaseBuild.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 6b1bf15..78f90af 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -97,11 +97,26 @@ stages: **\*.psm1 useMinimatch: true - # finally publish the parts of the build which will be used in the next stages - # if it's not published, the subsequent stages will not be able to access it. - - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet" - artifact: build - displayName: publish build directory + # Register local folder as PSRepository + # Then publish-module to that folder + - pwsh: | + $localRepo = "$(Build.SourcesDirectory)/local" + New-Item -Path $localRepo -ItemType Directory -Force + $vstsCommandString = "vso[task.setvariable variable=localRepo]${localRepo}" + Write-Host "local repo is: " + $vstsCommandString + Write-Host "##$vstsCommandString" + + Register-PSRepository -Name local -SourceLocation $(localRepo) + Publish-Module -Path $(signOutPath) -Repository local + displayName: Publish module to local repository + + - task: NuGetCommand@2 + displayName: 'Push CompatPowerShellGet module artifacts to PSGallery feed' + inputs: + command: push + packagesToPush: '$(localRepo)' + nuGetFeedType: external + publishFeedCredentials: PSGalleryPush # Now on to the compliance stage - stage: compliance From f2562fba8dc1f22c778e5c34213edf7f6de627c1 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 12:52:58 -0700 Subject: [PATCH 17/74] Create new stage for publish tasks, and add upload task --- .ci/releaseBuild.yml | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 78f90af..458e9d2 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -110,13 +110,11 @@ stages: Publish-Module -Path $(signOutPath) -Repository local displayName: Publish module to local repository - - task: NuGetCommand@2 - displayName: 'Push CompatPowerShellGet module artifacts to PSGallery feed' - inputs: - command: push - packagesToPush: '$(localRepo)' - nuGetFeedType: external - publishFeedCredentials: PSGalleryPush + - pwsh: | + $nupkgPath = "$(localRepo)" + $artifactName = "CompatPowerShellGet" + Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$nupkgPath" + displayName: Upload module artifact # Now on to the compliance stage - stage: compliance @@ -148,3 +146,38 @@ stages: codeBaseName: 'CompatPowerShellGet_20200201' # selections APIScan: false # set to false when not using Windows APIs. + +stages: +- stage: Publish + displayName: Publish + pool: + name: 1ES + demands: + - ImageOverride -equals PSMMS2019-Secure + jobs: + - job: Publish_Job + displayName: Build Microsoft.PowerShell.CompatPowerShellGet + steps: + - checkout: self + + - task: DownloadPipelineArtifact@2 + displayName: 'Download PowerShellGet module artifacts' + inputs: + artifact: nupkg + patterns: '**/*.nupkg' + downloadPath: '$(Pipeline.Workspace)/nuget' + + - pwsh: | + $package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/CompatPowerShellGet.*.nupkg').FullName + $vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Capture PowerShellGet module NuGet package path and set environment variable' + + - task: NuGetCommand@2 + displayName: 'Push CompatPowerShellGet module artifacts to PSGallery feed' + inputs: + command: push + packagesToPush: '$(NugetPkgPath)' + nuGetFeedType: external + publishFeedCredentials: PSGalleryPush \ No newline at end of file From bf0214b81a414648b3511f0f465ecf6e60a78be2 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 13:12:01 -0700 Subject: [PATCH 18/74] Fix indentations --- .ci/releaseBuild.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 458e9d2..ea62661 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -110,7 +110,7 @@ stages: Publish-Module -Path $(signOutPath) -Repository local displayName: Publish module to local repository - - pwsh: | + - pwsh: | $nupkgPath = "$(localRepo)" $artifactName = "CompatPowerShellGet" Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$nupkgPath" @@ -161,18 +161,18 @@ stages: - checkout: self - task: DownloadPipelineArtifact@2 - displayName: 'Download PowerShellGet module artifacts' - inputs: - artifact: nupkg - patterns: '**/*.nupkg' - downloadPath: '$(Pipeline.Workspace)/nuget' + displayName: 'Download PowerShellGet module artifacts' + inputs: + artifact: nupkg + patterns: '**/*.nupkg' + downloadPath: '$(Pipeline.Workspace)/nuget' - pwsh: | - $package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/CompatPowerShellGet.*.nupkg').FullName - $vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}" - Write-Host "sending " + $vstsCommandString - Write-Host "##$vstsCommandString" - displayName: 'Capture PowerShellGet module NuGet package path and set environment variable' + $package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/CompatPowerShellGet.*.nupkg').FullName + $vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}" + Write-Host "sending " + $vstsCommandString + Write-Host "##$vstsCommandString" + displayName: 'Capture PowerShellGet module NuGet package path and set environment variable' - task: NuGetCommand@2 displayName: 'Push CompatPowerShellGet module artifacts to PSGallery feed' @@ -180,4 +180,4 @@ stages: command: push packagesToPush: '$(NugetPkgPath)' nuGetFeedType: external - publishFeedCredentials: PSGalleryPush \ No newline at end of file + publishFeedCredentials: PSGalleryPush From d13ab88892e61d7109f0a5a3af4ac7b79354c3b6 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 13:14:13 -0700 Subject: [PATCH 19/74] Update artifact name --- .ci/releaseBuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index ea62661..18c098c 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -163,7 +163,7 @@ stages: - task: DownloadPipelineArtifact@2 displayName: 'Download PowerShellGet module artifacts' inputs: - artifact: nupkg + artifact: CompatPowerShellGet patterns: '**/*.nupkg' downloadPath: '$(Pipeline.Workspace)/nuget' From 45a71ca6668da28eccbe9c0c269c6807a8831223 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 13:16:57 -0700 Subject: [PATCH 20/74] Add dependsOn to Publish stage --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 18c098c..49941fc 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -117,7 +117,7 @@ stages: displayName: Upload module artifact # Now on to the compliance stage -- stage: compliance +- stage: Compliance displayName: Compliance dependsOn: Build jobs: @@ -150,6 +150,7 @@ stages: stages: - stage: Publish displayName: Publish + dependsOn: Compliance pool: name: 1ES demands: From bb84bf2dc21a215b2ec6228b6a451c3f19bb95ba Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 15:49:14 -0700 Subject: [PATCH 21/74] Update yaml for broken pipeline --- .ci/releaseBuild.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 49941fc..cd82953 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -106,10 +106,16 @@ stages: Write-Host "local repo is: " + $vstsCommandString Write-Host "##$vstsCommandString" - Register-PSRepository -Name local -SourceLocation $(localRepo) + Register-PSRepository -Name local -SourceLocation $localRepo Publish-Module -Path $(signOutPath) -Repository local displayName: Publish module to local repository + # finally publish the parts of the build which will be used in the next stages + # if it's not published, the subsequent stages will not be able to access it. + - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet" + artifact: build + displayName: publish build directory + - pwsh: | $nupkgPath = "$(localRepo)" $artifactName = "CompatPowerShellGet" @@ -147,7 +153,6 @@ stages: # selections APIScan: false # set to false when not using Windows APIs. -stages: - stage: Publish displayName: Publish dependsOn: Compliance From 3fc7433db01aaab89cf1268747db95ca90c2293a Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 16:41:40 -0700 Subject: [PATCH 22/74] Update .ci/releaseBuild.yml Co-authored-by: Aditya Patwardhan --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index cd82953..f6236b3 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -112,7 +112,8 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - - publish: "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet" + - publish: "$(signOutPath)" + artifact: build displayName: publish build directory From 3e3a47c45bc7fca280fccef7527b247625e34ce8 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 10 May 2023 16:49:33 -0700 Subject: [PATCH 23/74] Remove unnecessary downloading of artifact in compliance stage --- .ci/releaseBuild.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index cd82953..20a89b9 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -135,8 +135,6 @@ stages: steps: - checkout: self - checkout: ComplianceRepo - - download: current - artifact: build # use the templates in the compliance repo # no assemblies, you should use script-module-compliance template From 4e8a07998b9a3017920905543f6bf57d0b99630b Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 14:55:27 -0700 Subject: [PATCH 24/74] Emit warning for deprecation of Find-RoleCapability --- Test/FindPSResource.Tests.ps1 | 6 ++++++ src/CompatPowerShellGet.psm1 | 1 + 2 files changed, 7 insertions(+) diff --git a/Test/FindPSResource.Tests.ps1 b/Test/FindPSResource.Tests.ps1 index 2c3b34a..066dc68 100644 --- a/Test/FindPSResource.Tests.ps1 +++ b/Test/FindPSResource.Tests.ps1 @@ -190,6 +190,12 @@ Describe 'Test CompatPowerShellGet: Find-PSResource' -tags 'CI' { $resModuleType = Out-String -InputObject $resModule.Type $resModuleType.Replace(",", " ").Split() | Should -Contain "Module" } + + It "Find-RoleCapability should emit warning" { + $results = Find-RoleCapability -Name $testModuleName -Repository $PSGalleryName -WarningVariable wv + $results | Should -BeNullOrEmpty + $wv[0] | Should -Be "The cmdlet 'Find-RoleCapability' is deprecated." + } } # Ensure that PSGet v2 was not loaded during the test via command discovery diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index bb2ac74..a89f95b 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -573,6 +573,7 @@ param( begin { # Find-RoleCability is no longer supported + Write-Warning -Message "The cmdlet 'Find-RoleCapability' is deprecated." } <# .ForwardHelpTargetName Find-RoleCapability From 3b425e3b533014e427c99cb7344ca3d780f01b66 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 15:20:40 -0700 Subject: [PATCH 25/74] Remove 'Force' param deletion from Update cmdlets --- src/CompatPowerShellGet.psm1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index bb2ac74..515098a 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -2409,7 +2409,6 @@ param( # Parameter Deletions (unsupported in v3) if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) @@ -2513,7 +2512,6 @@ param( # Parameter Deletions (unsupported in v3) if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } # END PARAMETER MAP $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) From 5028fd7b284114202cecf940707997c85c8715f7 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 15:24:31 -0700 Subject: [PATCH 26/74] add test --- Test/UpdatePSResource.Tests.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Test/UpdatePSResource.Tests.ps1 b/Test/UpdatePSResource.Tests.ps1 index 3676663..9e839f8 100644 --- a/Test/UpdatePSResource.Tests.ps1 +++ b/Test/UpdatePSResource.Tests.ps1 @@ -347,6 +347,24 @@ Describe 'Test CompatPowerShellGet: Update-PSResource' -tags 'CI' { $res.Name | Should -Contain $testModuleName $res.Version | Should -Contain "3.0.0.0" } + + It "Update resource installed given -Name and -Force parameters" { + Install-PSResource -Name $testModuleName -Version "1.0.0.0" -Repository $PSGalleryName -TrustRepository + + Update-Module -Name $testModuleName -RequiredVersion "3.0.0.0" -Foce + $res = Get-InstalledPSResource -Name $testModuleName + + $isPkgUpdated = $false + foreach ($pkg in $res) + { + if ([System.Version]$pkg.Version -gt [System.Version]"1.0.0.0") + { + $isPkgUpdated = $true + } + } + + $isPkgUpdated | Should -Be $true + } } # Ensure that PSGet v2 was not loaded during the test via command discovery From f0229733e8ae720c5ec4eeb556114b048ab45649 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 16:04:01 -0700 Subject: [PATCH 27/74] Add update-modulemanifest proxy --- src/CompatPowerShellGet.psm1 | 129 +++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index bb2ac74..2b7d686 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -2549,6 +2549,135 @@ param( #> } +function Update-ModuleManifest { +[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'PathParameterSet', SupportsShouldProcess = $true, HelpUri = 'https://go.microsoft.com/fwlink/?LinkId=619793')] +param( + [Parameter(ParameterSetName = 'PathParameterSet', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName = 'LiteralPathParameterSet', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('PSPath')] + [ValidateNotNullOrEmpty()] + [string] + ${LiteralPath}, + + [ValidateNotNullOrEmpty()] + [string] + ${Version}, + + [ValidateNotNullOrEmpty()] + [string] + ${Author}, + + [ValidateNotNullOrEmpty()] + [string] + ${Description}, + + [ValidateNotNullOrEmpty()] + [Guid] + ${Guid}, + + [ValidateNotNullOrEmpty()] + [string] + ${CompanyName}, + + [ValidateNotNullOrEmpty()] + [string] + ${Copyright}, + + [ValidateNotNullOrEmpty()] + [Object[]] + ${RequiredModules}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalModuleDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${RequiredScripts}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExternalScriptDependencies}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${Tags}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${ProjectUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${LicenseUri}, + + [ValidateNotNullOrEmpty()] + [Uri] + ${IconUri}, + + [string[]] + ${ReleaseNotes}, + + [ValidateNotNullOrEmpty()] + [string] + ${PrivateData}, + + [switch] + ${PassThru}, + + [switch] + ${Force}) + + begin + { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + # PARAMETER MAP + # No parameter translations + # END PARAMETER MAP + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSModuleManifest', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw + } + } + + process + { + try { + $steppablePipeline.Process($_) + } catch { + throw + } + } + + end + { + try { + $steppablePipeline.End() + } catch { + throw + } + } + <# + .ForwardHelpTargetName Update-ModuleManifest + .ForwardHelpCategory Function + #> +} + function Update-ScriptFileInfo { [CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'PathParameterSet', SupportsShouldProcess = $true, HelpUri = 'https://go.microsoft.com/fwlink/?LinkId=619793')] param( From 2d1c5e7e2d68c372548bd73dfe4e0ef4c6cc00ad Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 16:07:07 -0700 Subject: [PATCH 28/74] Add tests --- Test/UpdatePSModuleManifest.Tests.ps1 | 415 ++++++++++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 Test/UpdatePSModuleManifest.Tests.ps1 diff --git a/Test/UpdatePSModuleManifest.Tests.ps1 b/Test/UpdatePSModuleManifest.Tests.ps1 new file mode 100644 index 0000000..8baaeca --- /dev/null +++ b/Test/UpdatePSModuleManifest.Tests.ps1 @@ -0,0 +1,415 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +$ProgressPreference = "SilentlyContinue" +$modPath = "$psscriptroot/../PSGetTestUtils.psm1" +Import-Module $modPath -Force -Verbose +Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" + +Describe 'Test CompatPowerShellGet: Update-ModuleManifest' { + + BeforeEach { + # Create temp module manifest to be updated + $script:TempModulesPath = Join-Path $TestDrive "PSGet_$(Get-Random)" + $null = New-Item -Path $script:TempModulesPath -ItemType Directory -Force + + $script:UpdateModuleManifestName = "PSGetTestModule" + $script:UpdateModuleManifestBase = Join-Path $script:TempModulesPath $script:UpdateModuleManifestName + $null = New-Item -Path $script:UpdateModuleManifestBase -ItemType Directory -Force + + $script:testManifestPath = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath "$script:UpdateModuleManifestName.psd1" + } + + AfterEach { + RemoveItem "$script:TempModulesPath" + } + + It "Update module manifest given Path parameter" { + $description = "This is a PowerShellGet test" + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -Description $description + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Description | Should -Be $description + } + + It "Update module manifest given Guid parameter" { + $Guid = [guid]::NewGuid() + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -Guid $Guid + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Guid | Should -Be $Guid + } + + It "Update module manifest given Author parameter" { + $Author = "Test Author" + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -Author $Author + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Author | Should -Be $Author + } + + It "Update module manifest given Description parameter" { + $Description = "PowerShellGet test description" + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -Description $Description + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Description | Should -Be $Description + } + + It "Update module manifest given ModuleVersion parameter" { + $ModuleVersion = "7.0.0.0" + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -ModuleVersion $ModuleVersion + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Version.ToString() | Should -Be $ModuleVersion + } + + It "Update module manifest given RequiredModules parameter" { + $requiredModuleName = 'PackageManagement' + $requiredModuleVersion = '1.0.0.0' + $RequiredModules = @(@{ModuleName = $requiredModuleName; ModuleVersion = $requiredModuleVersion }) + New-ModuleManifest -Path $script:testManifestPath + Update-ModuleManifest -Path $script:testManifestPath -RequiredModules $RequiredModules -Description "test" + + $results = Test-ModuleManifest -Path $script:testManifestPath + foreach ($module in $results.RequiredModules) + { + $module | Should -Be $requiredModuleName + $module.Version | Should -Be $requiredModuleVersion + } + } + + It "Update module manifest given Prerelease parameter" { + $Description = "Test Description" + $ModuleVersion = "1.0.0" + $Prerelease = "preview" + New-ModuleManifest -Path $script:testManifestPath -Description $Description -ModuleVersion $ModuleVersion + Update-ModuleManifest -Path $script:testManifestPath -Prerelease $Prerelease + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.Prerelease | Should -Be $Prerelease + } + + It "Update module manifest given ReleaseNotes parameter" { + $Description = "Test Description" + $ReleaseNotes = "Release notes for module." + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -ReleaseNotes $ReleaseNotes + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.ReleaseNotes | Should -Be $ReleaseNotes + } + + It "Update module manifest given Tags parameter" { + $Description = "Test Description" + $Tag1 = "tag1" + $Tag2 = "tag2" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -Tags $Tag1, $Tag2 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.Tags | Should -Be @($Tag1, $Tag2) + } + + It "Update module manifest given ProjectUri parameter" { + $Description = "Test Description" + $ProjectUri = "https://www.testprojecturi.com/" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -ProjectUri $ProjectUri + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.ProjectUri | Should -Be $ProjectUri + } + + It "Update module manifest given LicenseUri parameter" { + $Description = "Test Description" + $LicenseUri = "https://www.testlicenseuri.com/" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -LicenseUri $LicenseUri + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.LicenseUri | Should -Be $LicenseUri + } + + It "Update module manifest given IconUri parameter" { + $Description = "Test Description" + $IconUri = "https://www.testiconuri.com/" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -IconUri $IconUri + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.IconUri | Should -Be $IconUri + } + + It "Update module manifest given RequireLicenseAcceptance parameter" { + $Description = "PowerShellGet test description" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -RequireLicenseAcceptance + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.RequireLicenseAcceptance | Should -Be $true + } + + It "Update module manifest given ExternalModuleDependencies parameter" { + $Description = "Test Description" + $ExternalModuleDep1 = "ExternalModuleDep1" + $ExternalModuleDep2 = "ExternalModuleDep2" + $ExternalModuleDep1FileName = "ExternalModuleDep1.psm1" + $ExternalModuleDep2FileName = "ExternalModuleDep2.psm1" + $ExternalModuleDepPath1 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $ExternalModuleDep1FileName + $ExternalModuleDepPath2 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $ExternalModuleDep2FileName + + $null = New-Item -Path $ExternalModuleDepPath1 -ItemType File -Force + $null = New-Item -Path $ExternalModuleDepPath2 -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description -NestedModules $ExternalModuleDep1, $ExternalModuleDep2 + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.ExternalModuleDependencies | Should -Be $null + + Update-ModuleManifest -Path $script:testManifestPath -ExternalModuleDependencies $ExternalModuleDep1, $ExternalModuleDep2 + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.PrivateData.PSData.ExternalModuleDependencies | Should -Be @($ExternalModuleDep1, $ExternalModuleDep2) + } + + It "Update module manifest given PowerShellHostName parameter" { + $Description = "PowerShellGet test description" + $PowerShellHostName = $Host.Name + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -PowerShellHostName $PowerShellHostName + + $results = Test-ModuleManifest -Path $script:testManifestPath -ErrorAction SilentlyContinue + $results.PowerShellHostName | Should -Be $PowerShellHostName + } + + It "Update module manifest given DefaultCommandPrefix parameter" { + $Description = "PowerShellGet test description" + $DefaultCommandPrefix = "testprefix" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -DefaultCommandPrefix $DefaultCommandPrefix + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Prefix | Should -Be $DefaultCommandPrefix + } + + It "Update module manifest given RootModule parameter" { + $Description = "Test Description" + $RootModuleName = $script:UpdateModuleManifestName + ".psm1" + $RootModulePath = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $RootModuleName + $null = New-Item -Path $RootModulePath -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -RootModule $RootModuleName + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.RootModule | Should -Be $RootModuleName + } + + It "Update module manifest given RequiredAssemblies parameter" { + $Description = "Test Description" + $RequiredAssembly1 = "RequiredAssembly1.dll" + $RequiredAssembly2 = "RequiredAssembly2.dll" + $RequiredAssemblyPath1 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $RequiredAssembly1 + $RequiredAssemblyPath2 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $RequiredAssembly2 + + $null = New-Item -Path $RequiredAssemblyPath1 -ItemType File -Force + $null = New-Item -Path $RequiredAssemblyPath2 -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -RequiredAssemblies $RequiredAssembly1, $RequiredAssembly2 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.RequiredAssemblies | Should -Be @($RequiredAssembly1, $RequiredAssembly2) + } + + It "Update module manifest given NestedModules parameter" { + $Description = "Test Description" + $NestedModule1 = "NestedModule1" + $NestedModule2 = "NestedModule2" + $NestModuleFileName1 = "NestedModule1.dll" + $NestModuleFileName2 = "NestedModule2.dll" + $NestedModulePath1 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $NestModuleFileName1 + $NestedModulePath2 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $NestModuleFileName2 + + $null = New-Item -Path $NestedModulePath1 -ItemType File -Force + $null = New-Item -Path $NestedModulePath2 -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -NestedModules $NestedModule1, $NestedModule2 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.NestedModules | Should -Be @($NestedModule1, $NestedModule2) + } + + It "Update module manifest given FileList parameter" { + $Description = "Test Description" + $FileList1 = "FileList1.cs" + $FileList2 = "FileList2.cs" + $FileListPath1 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $FileList1 + $FileListPath2 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $FileList2 + + $null = New-Item -Path $FileListPath1 -ItemType File -Force + $null = New-Item -Path $FileListPath2 -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -FileList $FileList1, $FileList2 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.FileList | Should -Be @($FileListPath1, $FileListPath2) + } + + It "Update module manifest given TypesToProcess parameter" { + $Description = "Test Description" + $TypeFile = "TypeFile.ps1xml" + $TypeFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $TypeFile + + $null = New-Item -Path $TypeFilePath -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -TypesToProcess $TypeFile + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.ExportedTypeFiles | Should -Be $TypeFilePath + } + + It "Update module manifest given FormatsToProcess parameter" { + $Description = "Test Description" + $FormatFile = "FormatFile.ps1xml" + $FormatFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $FormatFile + + $null = New-Item -Path $FormatFilePath -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -FormatsToProcess $FormatFile + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.ExportedFormatFiles | Should -Be $FormatFilePath + } + + It "Update module manifest given ScriptsToProcess parameter" { + $Description = "Test Description" + $Script1 = "Script1.ps1" + $Script2 = "Script2.ps1" + $ScriptPath1 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $Script1 + $ScriptPath2 = Microsoft.PowerShell.Management\Join-Path -Path $script:UpdateModuleManifestBase -ChildPath $Script2 + + $null = New-Item -Path $ScriptPath1 -ItemType File -Force + $null = New-Item -Path $ScriptPath2 -ItemType File -Force + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -ScriptsToProcess $Script1, $Script2 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Scripts | Should -Be @($ScriptPath1, $ScriptPath2) + } + + It "Update module manifest given ProcessorArchitecture parameter" { + $Description = "Test Description" + $ProcessorArchitecture = [System.Reflection.ProcessorArchitecture]::Amd64 + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -ProcessorArchitecture $ProcessorArchitecture + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.ProcessorArchitecture | Should -Be $ProcessorArchitecture + } + + It "Update module manifest given ModuleList parameter" { + $Description = "Test Description" + $ModuleList1 = "PowerShellGet" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -ModuleList $ModuleList1 + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.ModuleList | Should -Be $ModuleList1 + } + + It "Update module manifest given CompanyName, Copyright, PowerShellHostVersion, ClrVersion, DotnetFrameworkVersion, PowerShellVersion, HelpInfoUri, and CompatiblePSEditions" { + $Description = "Test Description" + $CompanyName = "Test CompanyName" + $Copyright = "Test Copyright" + $PowerShellHostVersion = "5.0" + $ClrVersion = "1.0" + $DotnetFrameworkVersion = "2.0" + $PowerShellVersion = "5.1" + $HelpInfoUri = "https://www.testhelpinfouri.com/" + $CompatiblePSEditions = @("Desktop", "Core") + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath ` + -CompanyName $CompanyName ` + -Copyright $Copyright ` + -PowerShellVersion $PowerShellVersion ` + -ClrVersion $ClrVersion ` + -DotNetFrameworkVersion $DotnetFrameworkVersion ` + -PowerShellHostVersion $PowerShellHostVersion ` + -HelpInfoUri $HelpInfoUri ` + -CompatiblePSEditions $CompatiblePSEditions + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.CompanyName | Should -Be $CompanyName + $results.Copyright | Should -Be $Copyright + $results.PowerShellVersion | Should -Be $PowerShellVersion + $results.ClrVersion | Should -Be $ClrVersion + $results.DotnetFrameworkVersion | Should -Be $DotnetFrameworkVersion + $results.PowerShellHostVersion | Should -Be $PowerShellHostVersion + $results.HelpInfoUri | Should -Be $HelpInfoUri + $results.CompatiblePSEditions | Should -Be $CompatiblePSEditions + } + + It "Update module manifest given FunctionsToExport, AliasesToExport, and VariablesToExport parameters" -Skip:(Get-IsWindows) { + $Description = "Test Description" + $ExportedFunctions = "FunctionToExport1", "FunctionToExport2" + $ExportedAliases = "AliasToExport1", "AliasToExport2" + $ExportedVariables = "VariablesToExport1", "Variables2Export2" + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath ` + -FunctionsToExport $ExportedFunctions ` + -AliasesToExport $ExportedAliases ` + -VariablesToExport $ExportedVariables + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.ExportedFunctions.Keys | Should -Be $ExportedFunctions + $results.ExportedAliases.Keys | Should -Be $ExportedAliases + $results.ExportedVariables.Keys | Should -Be $ExportedVariables + } + + It "Update module manifest given CmdletsToExport parameters" { + $Description = "Test Description" + $CmdletToExport1 = "CmdletToExport1" + $CmdletToExport2 = "CmdletToExport2" + + New-ModuleManifest -Path $script:testManifestPath -Description $Description + Update-ModuleManifest -Path $script:testManifestPath -CmdletsToExport $CmdletToExport1, $CmdletToExport2 + + $results = Get-Content -Path $script:testManifestPath -Raw + $results.Contains($CmdletToExport1) | Should -Be $true + $results.Contains($CmdletToExport2) | Should -Be $true + } + + It "Update module manifest should not overwrite over old data unless explcitly specified" { + $Description = "Test Description" + $ModuleVersion = "2.0.0" + $Author = "Leto Atriedes" + $ProjectUri = "https://www.arrakis.gov/" + $Prerelease = "Preview" + New-ModuleManifest -Path $script:testManifestPath -Description $Description -ModuleVersion $ModuleVersion -Author $Author -ProjectUri $ProjectUri + Update-ModuleManifest -Path $script:testManifestPath -Prerelease $Prerelease + + $results = Test-ModuleManifest -Path $script:testManifestPath + $results.Author | Should -Be $Author + $results.PrivateData.PSData.ProjectUri | Should -Be $ProjectUri + $results.PrivateData.PSData.Prerelease | Should -Be $Prerelease + } +} + +# Ensure that PSGet v2 was not loaded during the test via command discovery +$PSGetVersionsLoaded = (Get-Module powershellget).Version +Write-Host "PowerShellGet versions currently loaded: $PSGetVersionsLoaded" +if ($PSGetVersionsLoaded.Count -gt 1) { + throw "There was more than one version of PowerShellGet imported into the current session. ` + Imported versions include: $PSGetVersionsLoaded" +} \ No newline at end of file From 86e72a99b60621a7907aa6d2fd665283eeb5af50 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 18 May 2023 16:46:43 -0700 Subject: [PATCH 29/74] Update references to New and Test PSScriptFile --- Test/NewPSScriptFile.Tests.ps1 | 6 ++-- Test/PublishPSResource.Tests.ps1 | 2 +- Test/TestPSScriptFile.Tests.ps1 | 4 +-- Test/UpdatePSScriptFileInfo.Tests.ps1 | 44 +++++++++++++-------------- src/CompatPowerShellGet.psm1 | 4 +-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Test/NewPSScriptFile.Tests.ps1 b/Test/NewPSScriptFile.Tests.ps1 index e585cf9..a15e504 100644 --- a/Test/NewPSScriptFile.Tests.ps1 +++ b/Test/NewPSScriptFile.Tests.ps1 @@ -5,7 +5,7 @@ $modPath = "$psscriptroot/../PSGetTestUtils.psm1" Import-Module $modPath -Force -Verbose Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" -Describe "Test CompatPowerShellGet: New-PSScriptFile" -tags 'CI' { +Describe "Test CompatPowerShellGet: New-PSScriptFileInfo" -tags 'CI' { BeforeAll { $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" $tmpDirPaths = @($tmpDir1Path) @@ -25,7 +25,7 @@ Describe "Test CompatPowerShellGet: New-PSScriptFile" -tags 'CI' { It "Create .ps1 file with minimal required fields" { $description = "Test description" New-ScriptFileInfo -Path $script:testScriptFilePath -Description $description - Test-PSScriptFile -Path $script:testScriptFilePath | Should -BeTrue + Test-PSScriptFileInfo -Path $script:testScriptFilePath | Should -BeTrue } It "Create .ps1 file with relative path" { @@ -35,7 +35,7 @@ Describe "Test CompatPowerShellGet: New-PSScriptFile" -tags 'CI' { $description = "Test description" New-ScriptFileInfo -Path $scriptFilePath -Description $description - Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + Test-PSScriptFileInfo -Path $scriptFilePath | Should -BeTrue Remove-Item -Path $scriptFilePath } diff --git a/Test/PublishPSResource.Tests.ps1 b/Test/PublishPSResource.Tests.ps1 index 8fbdbcc..ec559dc 100644 --- a/Test/PublishPSResource.Tests.ps1 +++ b/Test/PublishPSResource.Tests.ps1 @@ -251,7 +251,7 @@ Describe "Test CompatPowerShellGet: Publish-PSResource" -tags 'CI' { } $scriptPath = (Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$scriptName.ps1") - New-PSScriptFile @params -Path $scriptPath + New-PSScriptFileInfo @params -Path $scriptPath Publish-Script -Path $scriptPath diff --git a/Test/TestPSScriptFile.Tests.ps1 b/Test/TestPSScriptFile.Tests.ps1 index b5ec6c5..f0d49c5 100644 --- a/Test/TestPSScriptFile.Tests.ps1 +++ b/Test/TestPSScriptFile.Tests.ps1 @@ -6,7 +6,7 @@ Import-Module $modPath -Force -Verbose Write-Verbose -Verbose -Message "PowerShellGet version currently loaded: $($(Get-Module powershellget).Version)" $testDir = (get-item $psscriptroot).parent.FullName -Describe "Test CompatPowerShellGet: Test-PSScriptFile" -tags 'CI' { +Describe "Test CompatPowerShellGet: Test-PSScriptFileInfo" -tags 'CI' { BeforeAll { $tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1" $tmpDirPaths = @($tmpDir1Path) @@ -25,7 +25,7 @@ Describe "Test CompatPowerShellGet: Test-PSScriptFile" -tags 'CI' { $guid = [guid]::NewGuid() $author = "Script Author" $version = "1.0.0" - New-PSScriptFile -Path $scriptFilePath -Description $scriptDescription -Guid $guid -Author $author -Version $version + New-PSScriptFileInfo -Path $scriptFilePath -Description $scriptDescription -Guid $guid -Author $author -Version $version Test-ScriptFileInfo $scriptFilePath | Should -Be $true } diff --git a/Test/UpdatePSScriptFileInfo.Tests.ps1 b/Test/UpdatePSScriptFileInfo.Tests.ps1 index 64adfbc..11bce59 100644 --- a/Test/UpdatePSScriptFileInfo.Tests.ps1 +++ b/Test/UpdatePSScriptFileInfo.Tests.ps1 @@ -25,7 +25,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $script:psScriptInfoName = "test_script" $scriptDescription = "this is a test script" $script:testScriptFilePath = Join-Path -Path $tmpDir1Path -ChildPath "$script:psScriptInfoName.ps1" - New-PSScriptFile -Path $script:testScriptFilePath -Description $scriptDescription + New-PSScriptFileInfo -Path $script:testScriptFilePath -Description $scriptDescription } AfterEach { @@ -40,10 +40,10 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $scriptFilePath = Join-Path -Path $relativeCurrentPath -ChildPath "$script:psScriptInfoName.ps1" $oldDescription = "Old description for test script" $newDescription = "New description for test script" - New-PSScriptFile -Path $scriptFilePath -Description $oldDescription + New-PSScriptFileInfo -Path $scriptFilePath -Description $oldDescription Update-ScriptFileInfo -Path $scriptFilePath -Description $newDescription - Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + Test-PSScriptFileInfo -Path $scriptFilePath | Should -BeTrue Test-Path -Path $scriptFilePath | Should -BeTrue $results = Get-Content -Path $scriptFilePath -Raw @@ -63,10 +63,10 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $relativeCurrentPath = Get-Location $scriptFilePath = Join-Path -Path $relativeCurrentPath -ChildPath "$script:psScriptInfoName.ps1" - New-PSScriptFile -Path $scriptFilePath -Description $description -Version $version -Author $author -ProjectUri $projectUri + New-PSScriptFileInfo -Path $scriptFilePath -Description $description -Version $version -Author $author -ProjectUri $projectUri Update-ScriptFileInfo -Path $scriptFilePath -Author $newAuthor - Test-PSScriptFile -Path $scriptFilePath | Should -BeTrue + Test-PSScriptFileInfo -Path $scriptFilePath | Should -BeTrue $results = Get-Content -Path $scriptFilePath -Raw $results.Contains($newAuthor) | Should -BeTrue $results.Contains(".AUTHOR $newAuthor") | Should -BeTrue @@ -87,7 +87,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Author property" { $author = "New Author" Update-ScriptFileInfo -Path $script:testScriptFilePath -Author $author - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -98,7 +98,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Version property" { $version = "2.0.0.0" Update-ScriptFileInfo -Path $script:testScriptFilePath -Version $version - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -109,7 +109,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Version property with prerelease version" { $version = "3.0.0-alpha" Update-ScriptFileInfo -Path $script:testScriptFilePath -Version $version - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -126,7 +126,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Description property" { $description = "this is an updated test script" Update-ScriptFileInfo -Path $script:testScriptFilePath -Description $description - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -137,7 +137,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Guid property" { $guid = [Guid]::NewGuid(); Update-ScriptFileInfo -Path $script:testScriptFilePath -Guid $guid - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -148,7 +148,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file CompanyName property" { $companyName = "New Corporation" Update-ScriptFileInfo -Path $script:testScriptFilePath -CompanyName $companyName - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -159,7 +159,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file Copyright property" { $copyright = "(c) 2022 New Corporation. All rights reserved" Update-ScriptFileInfo -Path $script:testScriptFilePath -Copyright $copyright - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -171,7 +171,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $externalModuleDep1 = "ExternalModuleDep1" $externalModuleDep2 = "ExternalModuleDep2" Update-ScriptFileInfo -Path $script:testScriptFilePath -ExternalModuleDependencies $externalModuleDep1,$externalModuleDep2 - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -184,7 +184,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $externalScriptDep1 = "ExternalScriptDep1" $externalScriptDep2 = "ExternalScriptDep2" Update-ScriptFileInfo -Path $script:testScriptFilePath -ExternalScriptDependencies $externalScriptDep1,$externalScriptDep2 - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -196,7 +196,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file IconUri property" { $iconUri = "https://testscript.com/icon" Update-ScriptFileInfo -Path $script:testScriptFilePath -IconUri $iconUri - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -207,7 +207,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file LicenseUri property" { $licenseUri = "https://testscript.com/license" Update-ScriptFileInfo -Path $script:testScriptFilePath -LicenseUri $licenseUri - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -218,7 +218,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file ProjectUri property" { $projectUri = "https://testscript.com/" Update-ScriptFileInfo -Path $script:testScriptFilePath -ProjectUri $projectUri - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -229,7 +229,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file PrivateData property" { $privateData = "this is some private data" Update-ScriptFileInfo -Path $script:testScriptFilePath -PrivateData $privateData - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -240,7 +240,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { It "update script file ReleaseNotes property" { $releaseNotes = "Release notes for script." Update-ScriptFileInfo -Path $script:testScriptFilePath -ReleaseNotes $releaseNotes - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -256,7 +256,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $requiredModules = @($hashtable1, $hashtable2, $hashtable3, $hashtable4) Update-ScriptFileInfo -Path $script:testScriptFilePath -RequiredModules $requiredModules - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -269,7 +269,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $requiredScript1 = "RequiredScript1" $requiredScript2 = "RequiredScript2" Update-ScriptFileInfo -Path $script:testScriptFilePath -RequiredScripts $requiredScript1, $requiredScript2 - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw @@ -282,7 +282,7 @@ Describe "Test CompatPowerShellGet: Update-PSScriptFileInfo" -tags 'CI' { $tag1 = "tag1" $tag2 = "tag2" Update-ScriptFileInfo -Path $script:testScriptFilePath -Tags $tag1, $tag2 - Test-PSScriptFile $script:testScriptFilePath | Should -Be $true + Test-PSScriptFileInfo $script:testScriptFilePath | Should -Be $true Test-Path -Path $script:testScriptFilePath | Should -BeTrue $results = Get-Content -Path $script:testScriptFilePath -Raw diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index bb2ac74..fa7dab8 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -1290,7 +1290,7 @@ param( if ( $PSBoundParameters['PassThru'] ) { $null = $PSBoundParameters.Remove('PassThru') } # END PARAMETER MAP - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('New-PSScriptFile', [System.Management.Automation.CommandTypes]::Cmdlet) + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('New-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } $steppablePipeline = $scriptCmd.GetSteppablePipeline() @@ -2062,7 +2062,7 @@ param( if ( $PSBoundParameters['LiteralPath'] ) { $null = $PSBoundParameters.Remove('LiteralPath'); $PSBoundParameters['Path'] = $LiteralPath } # END PARAMETER MAP - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Test-PSScriptFile', [System.Management.Automation.CommandTypes]::Cmdlet) + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Test-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } $steppablePipeline = $scriptCmd.GetSteppablePipeline() From d40714f0075010788a5a199a1d31701d8144937a Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Tue, 23 May 2023 12:47:14 -0500 Subject: [PATCH 30/74] Add aliases to match V2 user experience --- src/CompatPowerShellGet.psm1 | 68 +++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index 935b4c1..2cd556c 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -122,7 +122,7 @@ function Convert-VersionParamaters elseif ( ! $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { return $null } - elseif ( $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { + elseif ( $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { return "$RequiredVersion" } # now return the appropriate string @@ -462,7 +462,7 @@ param( } # PARAMETER MAP - # add new specifier + # add new specifier $PSBoundParameters['Type'] = 'module' # Parameter translations $verArgs = @{} @@ -659,7 +659,7 @@ param( } # PARAMETER MAP - # add new specifier + # add new specifier $PSBoundParameters['Type'] = 'script' # Parameter translations $verArgs = @{} @@ -1201,11 +1201,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] @@ -1222,11 +1222,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalModuleDependencies}, @@ -1234,7 +1234,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -1242,19 +1242,19 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, @@ -1753,7 +1753,7 @@ param( if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } if ( $PSBoundParameters['AcceptLicense'] ) { $null = $PSBoundParameters.Remove('AcceptLicense') } # END PARAMETER MAP - + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } @@ -2565,11 +2565,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [ValidateNotNullOrEmpty()] [string] ${Description}, @@ -2585,7 +2585,7 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, @@ -2597,7 +2597,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -2605,11 +2605,11 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, @@ -2617,7 +2617,7 @@ param( [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, @@ -2694,11 +2694,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [ValidateNotNullOrEmpty()] [string] ${Description}, @@ -2714,7 +2714,7 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, @@ -2726,7 +2726,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -2734,11 +2734,11 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, @@ -2746,7 +2746,7 @@ param( [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, @@ -2816,6 +2816,11 @@ param( #> } +New-Alias -Name fimo -Value Find-Module +New-Alias -Name inmo -Value Install-Module +New-Alias -Name pumo -Value Publish-Module +New-Alias -Name upmo -Value Update-Module + $functionsToExport = @( "Find-Command", "Find-DscResource", @@ -2843,4 +2848,11 @@ $functionsToExport = @( "Update-ScriptFileInfo" ) -export-ModuleMember -Function $functionsToExport \ No newline at end of file +$aliasesToExport = @(' + fimo', + 'inmo', + 'pumo', + 'upmo' +) + +export-ModuleMember -Function $functionsToExport -Alias $aliasesToExport From 55b62223c94e868336fd94eb643d274cf46028b7 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Tue, 23 May 2023 13:20:39 -0500 Subject: [PATCH 31/74] Fix logic for AllowClobber and SkipPublisherCheck --- src/CompatPowerShellGet.psm1 | 68 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/CompatPowerShellGet.psm1 b/src/CompatPowerShellGet.psm1 index 935b4c1..9e86ecb 100644 --- a/src/CompatPowerShellGet.psm1 +++ b/src/CompatPowerShellGet.psm1 @@ -122,7 +122,7 @@ function Convert-VersionParamaters elseif ( ! $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { return $null } - elseif ( $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { + elseif ( $RequiredVersion -and ! $MinimumVersion -and ! $MaximumVersion ) { return "$RequiredVersion" } # now return the appropriate string @@ -462,7 +462,7 @@ param( } # PARAMETER MAP - # add new specifier + # add new specifier $PSBoundParameters['Type'] = 'module' # Parameter translations $verArgs = @{} @@ -659,7 +659,7 @@ param( } # PARAMETER MAP - # add new specifier + # add new specifier $PSBoundParameters['Type'] = 'script' # Parameter translations $verArgs = @{} @@ -1021,11 +1021,13 @@ param( $PSBoundParameters['Version'] = $ver } if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } - if ( $PSBoundParameters['SkipPublisherCheck'] ) { $null = $PSBoundParameters.Remove('SkipPublisherCheck'); $PSBoundParameters['AuthenticodeCheck'] = $SkipPublisherCheck } + $PSBoundParameters['NoClobber'] = $true + if ( $PSBoundParameters['AllowClobber'] ) { $null = $PSBoundParameters.Remove('AllowClobber'); $PSBoundParameters['NoClobber'] = (-not $AllowClobber) } + $PSBoundParameters['AuthenticodeCheck'] = $true + if ( $PSBoundParameters['SkipPublisherCheck'] ) { $null = $PSBoundParameters.Remove('SkipPublisherCheck'); $PSBoundParameters['AuthenticodeCheck'] = (-not $SkipPublisherCheck) } # Parameter Deletions (unsupported in v3) if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } if ( $PSBoundParameters['ProxyCredential'] ) { $null = $PSBoundParameters.Remove('ProxyCredential') } - if ( $PSBoundParameters['AllowClobber'] ) { $null = $PSBoundParameters.Remove('AllowClobber') } if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } # END PARAMETER MAP @@ -1142,14 +1144,14 @@ param( # PARAMETER MAP # Parameter translations $verArgs = @{} - if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } - if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } - if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } + if ( $PSBoundParameters['MinimumVersion'] ) { $null = $PSBoundParameters.Remove('MinimumVersion'); $verArgs['MinimumVersion'] = $MinimumVersion } + if ( $PSBoundParameters['MaximumVersion'] ) { $null = $PSBoundParameters.Remove('MaximumVersion'); $verArgs['MaximumVersion'] = $MaximumVersion } + if ( $PSBoundParameters['RequiredVersion'] ) { $null = $PSBoundParameters.Remove('RequiredVersion'); $verArgs['RequiredVersion'] = $RequiredVersion } $ver = Convert-VersionParamaters @verArgs if ( $ver ) { $PSBoundParameters['Version'] = $ver } - if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } + if ( $PSBoundParameters['AllowPrerelease'] ) { $null = $PSBoundParameters.Remove('AllowPrerelease'); $PSBoundParameters['Prerelease'] = $AllowPrerelease } # Parameter Deletions (unsupported in v3) if ( $PSBoundParameters['NoPathUpdate'] ) { $null = $PSBoundParameters.Remove('NoPathUpdate') } if ( $PSBoundParameters['Proxy'] ) { $null = $PSBoundParameters.Remove('Proxy') } @@ -1201,11 +1203,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] @@ -1222,11 +1224,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalModuleDependencies}, @@ -1234,7 +1236,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -1242,19 +1244,19 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, @@ -1753,7 +1755,7 @@ param( if ( $PSBoundParameters['Force'] ) { $null = $PSBoundParameters.Remove('Force') } if ( $PSBoundParameters['AcceptLicense'] ) { $null = $PSBoundParameters.Remove('AcceptLicense') } # END PARAMETER MAP - + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } @@ -2565,11 +2567,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [ValidateNotNullOrEmpty()] [string] ${Description}, @@ -2585,7 +2587,7 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, @@ -2597,7 +2599,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -2605,11 +2607,11 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, @@ -2617,7 +2619,7 @@ param( [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, @@ -2694,11 +2696,11 @@ param( [ValidateNotNullOrEmpty()] [string] ${Version}, - + [ValidateNotNullOrEmpty()] [string] ${Author}, - + [ValidateNotNullOrEmpty()] [string] ${Description}, @@ -2714,7 +2716,7 @@ param( [ValidateNotNullOrEmpty()] [string] ${Copyright}, - + [ValidateNotNullOrEmpty()] [Object[]] ${RequiredModules}, @@ -2726,7 +2728,7 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${RequiredScripts}, - + [ValidateNotNullOrEmpty()] [string[]] ${ExternalScriptDependencies}, @@ -2734,11 +2736,11 @@ param( [ValidateNotNullOrEmpty()] [string[]] ${Tags}, - + [ValidateNotNullOrEmpty()] [Uri] ${ProjectUri}, - + [ValidateNotNullOrEmpty()] [Uri] ${LicenseUri}, @@ -2746,7 +2748,7 @@ param( [ValidateNotNullOrEmpty()] [Uri] ${IconUri}, - + [string[]] ${ReleaseNotes}, From c5eff5ff0661e8229617617b1e437fa2e28dd960 Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Wed, 13 Sep 2023 16:10:47 -0700 Subject: [PATCH 32/74] Change 'CompatPowerShellGet' to 'PowerShellGet' --- .ci/releaseBuild.yml | 22 +++++++++++----------- CHANGELOG.md | 6 ++++++ README.md | 24 ++++++++++++------------ SignConfig.xml | 6 +++--- src/CompatPowerShellGet.psd1 | 16 +++++++++------- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 49941fc..505ce63 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -1,5 +1,5 @@ # The name of the build that will be seen in mscodehub -name: CompatPowerShellget-Release-$(Build.BuildId) +name: PowerShellget-Release-$(Build.BuildId) # how is the build triggered # since this is a release build, no trigger as it's a manual release trigger: none @@ -38,7 +38,7 @@ stages: - ImageOverride -equals PSMMS2019-Secure jobs: - job: Build_Job - displayName: Build Microsoft.PowerShell.CompatPowerShellGet + displayName: Build Microsoft.PowerShell.PowerShellGet # note the variable reference to ESRP. # this must be created in Project -> Pipelines -> Library -> VariableGroups # where it describes the link to the SigningServer @@ -49,14 +49,14 @@ stages: # these are setting vso variables which will be persisted between stages - pwsh: | - $signSrcPath = "$(Build.SourcesDirectory)/CompatPowerShellGet/src" + $signSrcPath = "$(Build.SourcesDirectory)/PowerShellGet/src" dir # Set signing src path variable $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}" Write-Host "sending " + $vstsCommandString Write-Host "##$vstsCommandString" - $signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet/signed/CompatPowerShellGet" + $signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_CompatPowerShellGet/signed/PowerShellGet" $null = New-Item -ItemType Directory -Path $signOutPath # Set signing out path variable $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}" @@ -69,7 +69,7 @@ stages: Write-Host "##$vstsCommandString" # Get version and create a variable - $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/CompatPowerShellGet/src/CompatPowerShellGet.psd1" + $moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/PowerShellGet/src/PowerShellGet.psd1" $moduleVersion = $moduleData.ModuleVersion $vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}" Write-Host "sending " + $vstsCommandString @@ -112,7 +112,7 @@ stages: - pwsh: | $nupkgPath = "$(localRepo)" - $artifactName = "CompatPowerShellGet" + $artifactName = "PowerShellGet" Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$nupkgPath" displayName: Upload module artifact @@ -137,7 +137,7 @@ stages: - template: script-module-compliance.yml@ComplianceRepo parameters: # component-governance - the path to sources - sourceScanPath: '$(Build.SourcesDirectory)/CompatPowerShellGet' + sourceScanPath: '$(Build.SourcesDirectory)/PowerShellGet' # TermCheck optionsRulesDBPath: '' optionsFTPath: '' @@ -157,26 +157,26 @@ stages: - ImageOverride -equals PSMMS2019-Secure jobs: - job: Publish_Job - displayName: Build Microsoft.PowerShell.CompatPowerShellGet + displayName: Build Microsoft.PowerShell.PowerShellGet steps: - checkout: self - task: DownloadPipelineArtifact@2 displayName: 'Download PowerShellGet module artifacts' inputs: - artifact: CompatPowerShellGet + artifact: PowerShellGet patterns: '**/*.nupkg' downloadPath: '$(Pipeline.Workspace)/nuget' - pwsh: | - $package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/CompatPowerShellGet.*.nupkg').FullName + $package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/PowerShellGet.*.nupkg').FullName $vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}" Write-Host "sending " + $vstsCommandString Write-Host "##$vstsCommandString" displayName: 'Capture PowerShellGet module NuGet package path and set environment variable' - task: NuGetCommand@2 - displayName: 'Push CompatPowerShellGet module artifacts to PSGallery feed' + displayName: 'Push PowerShellGet module artifacts to PSGallery feed' inputs: command: push packagesToPush: '$(NugetPkgPath)' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e5c859..e0e216b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +### 0.9.0 + +### 0.0.4 +* Changes +- Update module to be compatible with latest version of PowerShellGet (3.0.21-beta21) + ### 0.0.3 * Changes - Updated reference to PowerShellGet 'Url' parameter to 'Uri' to reflect changes made in PowerShellGet diff --git a/README.md b/README.md index 1dbb56e..68198a6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# CompatPowerShellGet +# PowerShellGet -[![PowerShell Gallery - CompatPowerShellGet](https://img.shields.io/badge/PowerShell%20Gallery-PowerShellGet-blue.svg)](https://www.powershellgallery.com/packages/CompatPowerShellGet) -[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-3.0-blue.svg)](https://github.com/PowerShell/CompatPowerShellGet) +[![PowerShell Gallery - PowerShellGet](https://img.shields.io/badge/PowerShell%20Gallery-PowerShellGet-blue.svg)](https://www.powershellgallery.com/packages/PowerShellGet) +[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-5.1-blue.svg)](https://github.com/PowerShell/PowerShellGet) Introduction ============ -CompatPowerShellGet is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' +PowerShellGet v3 is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PSResourceGet functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) @@ -16,21 +16,21 @@ questions or comments. Documentation ============= -Documentation for CompatPowerShellGet has not yet been published, please +Documentation for PowerShellGet has not yet been published, please [Click here](https://docs.microsoft.com/powershell/module/PowerShellGet/?view=powershell-7) to reference the documentation for previous versions of PowerShellGet. Requirements ============ -- Windows PowerShell 3.0 or newer. +- Windows PowerShell 5.1 or newer. - PowerShell Core. -Get CompatPowerShellGet Module +Get PowerShellGet Module ======================== -Please refer to our [documentation](https://www.powershellgallery.com/packages/CompatPowerShellGet/) for the up-to-date version on how to get the CompatPowerShellGet Module. +Please refer to our [documentation](https://www.powershellgallery.com/packages/PowerShellGet/) for the up-to-date version on how to get the PowerShellGet Module. Get PowerShellGet Source @@ -38,17 +38,17 @@ Get PowerShellGet Source #### Steps * Obtain the source - - Download the latest source code from the release page (https://github.com/PowerShell/CompatPowerShellGet/releases) OR + - Download the latest source code from the release page (https://github.com/PowerShell/PowerShellGet/releases) OR - Clone the repository (needs git) ```powershell - git clone https://github.com/PowerShell/CompatPowerShellGet + git clone https://github.com/PowerShell/PowerShellGet ``` * Navigate to the source directory ```powershell -cd path/to/CompatPowerShellGet +cd path/to/PowerShellGet ``` * Import the module ```powershell -Import-Module src/CompatPowerShellGet +Import-Module src/PowerShellGet -Force ``` diff --git a/SignConfig.xml b/SignConfig.xml index 87b3d11..64d42f8 100644 --- a/SignConfig.xml +++ b/SignConfig.xml @@ -3,8 +3,8 @@ - - - + + + diff --git a/src/CompatPowerShellGet.psd1 b/src/CompatPowerShellGet.psd1 index b5cfe62..a330cf0 100644 --- a/src/CompatPowerShellGet.psd1 +++ b/src/CompatPowerShellGet.psd1 @@ -1,5 +1,5 @@ # -# Module manifest for module 'CompatPowerShellGet' +# Module manifest for module 'PowerShellGet' # # Generated by: americks # @@ -7,13 +7,13 @@ # @{ - RootModule = 'CompatPowerShellGet.psm1' - ModuleVersion = '0.0.4' + RootModule = 'PowerShellGet.psm1' + ModuleVersion = '0.9.0' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' Copyright = '(c) Microsoft Corporation. All rights reserved.' - Description = 'CompatPowerShellGet is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PowerShellGet 3.0 (and newer) functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' + Description = 'PowerShellGet is a compatibility module that allows use of PowerShellGet 2.x (and below) cmdlet syntax with PSResourceGet functionality by making a best effort mapping between the cmdlet interfaces of both versions of the module.' PowerShellVersion = '3.0' FunctionsToExport = @( "Find-Command", @@ -51,9 +51,11 @@ 'Mac', 'Windows') - LicenseUri = 'https://github.com/PowerShell/CompatPowerShellGet/blob/master/LICENSE' - ProjectUri = 'https://github.com/PowerShell/CompatPowerShellGet' + LicenseUri = 'https://github.com/PowerShell/PowerShellGet/blob/master/LICENSE' + ProjectUri = 'https://github.com/PowerShell/PowerShellGet' ReleaseNotes = @' +### 0.9.0 + ### 0.0.4 * Changes - Update module to be compatible with latest version of PowerShellGet (3.0.21-beta21) @@ -70,7 +72,7 @@ * Initial release ## For full history of release notes see changelog: -https://github.com/PowerShell/CompatPowerShellGet/blob/master/CHANGELOG.md +https://github.com/PowerShell/PowerShellGet/blob/master/CHANGELOG.md '@ } } From aa16919d6b98c08039274a5185e1064bef1bf779 Mon Sep 17 00:00:00 2001 From: Amber Erickson Date: Thu, 14 Sep 2023 08:48:12 -0700 Subject: [PATCH 33/74] Change file names --- src/{CompatPowerShellGet.psd1 => PowerShellGet.psd1} | 0 src/{CompatPowerShellGet.psm1 => PowerShellGet.psm1} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{CompatPowerShellGet.psd1 => PowerShellGet.psd1} (100%) rename src/{CompatPowerShellGet.psm1 => PowerShellGet.psm1} (100%) diff --git a/src/CompatPowerShellGet.psd1 b/src/PowerShellGet.psd1 similarity index 100% rename from src/CompatPowerShellGet.psd1 rename to src/PowerShellGet.psd1 diff --git a/src/CompatPowerShellGet.psm1 b/src/PowerShellGet.psm1 similarity index 100% rename from src/CompatPowerShellGet.psm1 rename to src/PowerShellGet.psm1 From 13b7b5586ef832461120a0a7fbb9f7c6c490cc39 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:15:34 -0700 Subject: [PATCH 34/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 32a771f..86b635e 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -113,7 +113,6 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" - artifact: build displayName: publish build directory From 97f9e0b3292fcd4b94c9f7e6537720f10b3f1751 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:15:59 -0700 Subject: [PATCH 35/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 86b635e..6445b3e 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -113,7 +113,8 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" - artifact: build + artifact: build + displayName: publish build directory - pwsh: | From d612e9c0a433ea547750b7a7339c329bea4aa013 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:16:25 -0700 Subject: [PATCH 36/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 6445b3e..c7810ba 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -115,7 +115,8 @@ stages: - publish: "$(signOutPath)" artifact: build - displayName: publish build directory + displayName: publish build directory + - pwsh: | $nupkgPath = "$(localRepo)" From fd954a7875ea03e919787f3effd2e7d6d5e52ac7 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:18:48 -0700 Subject: [PATCH 37/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index c7810ba..f1469d6 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -113,7 +113,8 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" - artifact: build + artifact: build + displayName: publish build directory From 9e254652a0f981ef649927aac2b627c32a762e50 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:19:03 -0700 Subject: [PATCH 38/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index f1469d6..e516da9 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -115,7 +115,6 @@ stages: - publish: "$(signOutPath)" artifact: build - displayName: publish build directory From 1b18cab04137de271e0ff0edeca7ef7cd224da9e Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:19:17 -0700 Subject: [PATCH 39/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index e516da9..0e99faa 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -114,7 +114,6 @@ stages: # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" artifact: build - displayName: publish build directory From b8125b779ff2be855cb39585fe1d3b41370d6547 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:19:34 -0700 Subject: [PATCH 40/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 0e99faa..960de07 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -114,7 +114,7 @@ stages: # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" artifact: build - displayName: publish build directory + displayName: publish build directory - pwsh: | From f079bf575f009b7f748d4dc68094a84cad646574 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:19:48 -0700 Subject: [PATCH 41/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 960de07..91c3abf 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -115,7 +115,6 @@ stages: - publish: "$(signOutPath)" artifact: build displayName: publish build directory - - pwsh: | $nupkgPath = "$(localRepo)" From 2e7d0db4ba8e264e37bf74c6060bb8a08016eda4 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:51:51 -0700 Subject: [PATCH 42/74] Update .ci/releaseBuild.yml --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 361e50d..e86f604 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -1,5 +1,6 @@ # The name of the build that will be seen in mscodehub -name: PowerShellget-Release-$(Build.BuildId) +name: PowerShellGet-Release-$(Build.BuildId) + # how is the build triggered # since this is a release build, no trigger as it's a manual release trigger: none From ab024d9c2f47d54ecbf567344b4b974b6be0520c Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Sep 2023 13:04:15 -0700 Subject: [PATCH 43/74] Fix whitespace --- .ci/releaseBuild.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index e86f604..dd3d526 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -114,8 +114,8 @@ stages: # finally publish the parts of the build which will be used in the next stages # if it's not published, the subsequent stages will not be able to access it. - publish: "$(signOutPath)" - artifact: build - displayName: publish build directory + artifact: build + displayName: publish build directory - pwsh: | $nupkgPath = "$(localRepo)" From 69ef15191b53694600adbf28fd8561210697a817 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Sep 2023 15:00:32 -0700 Subject: [PATCH 44/74] Update version for module --- CHANGELOG.md | 2 +- src/PowerShellGet.psd1 | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e216b..7ff9d21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -### 0.9.0 +### 2.9.0 ### 0.0.4 * Changes diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index a330cf0..eb814fb 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'PowerShellGet.psm1' - ModuleVersion = '0.9.0' + ModuleVersion = '2.9.0' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -54,22 +54,9 @@ LicenseUri = 'https://github.com/PowerShell/PowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/PowerShellGet' ReleaseNotes = @' -### 0.9.0 - -### 0.0.4 -* Changes -- Update module to be compatible with latest version of PowerShellGet (3.0.21-beta21) - -### 0.0.3 +### 2.9.0 * Changes -- Updated reference to PowerShellGet 'Url' parameter to 'Uri' to reflect changes made in PowerShellGet - -### 0.0.2 -* Bug Fix -- Remove -Force parameter when calling into v3 cmdlets - -### 0.0.1 -* Initial release +- This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' ## For full history of release notes see changelog: https://github.com/PowerShell/PowerShellGet/blob/master/CHANGELOG.md From dd9fa67ba23e4efe6fcb356b7d32cbd687bd8d08 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Sep 2023 15:23:59 -0700 Subject: [PATCH 45/74] Add prerelease label --- CHANGELOG.md | 2 +- src/PowerShellGet.psd1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ff9d21..c30eabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -### 2.9.0 +### 2.9.0-preview ### 0.0.4 * Changes diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index eb814fb..b6efa1a 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -44,6 +44,7 @@ PrivateData = @{ PSData = @{ + Prerelease = 'preview' Tags = @('PackageManagement', 'PSEdition_Desktop', 'PSEdition_Core', @@ -54,7 +55,7 @@ LicenseUri = 'https://github.com/PowerShell/PowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/PowerShellGet' ReleaseNotes = @' -### 2.9.0 +### 2.9.0-preview * Changes - This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' From 04bece857eff9ddf00c1a355f600ce9dd6811e45 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 20 Sep 2023 00:03:01 -0700 Subject: [PATCH 46/74] Update module version --- CHANGELOG.md | 4 +++- src/PowerShellGet.psd1 | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c30eabf..276fe73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog -### 2.9.0-preview +### 3.0.22-beta22 +* Changes +- This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' ### 0.0.4 * Changes diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index b6efa1a..b5c3286 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'PowerShellGet.psm1' - ModuleVersion = '2.9.0' + ModuleVersion = '3.0.22' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -44,7 +44,7 @@ PrivateData = @{ PSData = @{ - Prerelease = 'preview' + Prerelease = 'beta22' Tags = @('PackageManagement', 'PSEdition_Desktop', 'PSEdition_Core', @@ -55,7 +55,7 @@ LicenseUri = 'https://github.com/PowerShell/PowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/PowerShellGet' ReleaseNotes = @' -### 2.9.0-preview +### 3.0.22-beta22 * Changes - This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' From 4a3da84ea87a43c63f6ee89c3621d41f549c7f2a Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 4 Oct 2023 10:15:13 -0700 Subject: [PATCH 47/74] Set the internal hook for PowerShellGet telemetry (#50) --- src/PowerShellGet.psm1 | 361 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 360 insertions(+), 1 deletion(-) diff --git a/src/PowerShellGet.psm1 b/src/PowerShellGet.psm1 index d12963f..c50b024 100644 --- a/src/PowerShellGet.psm1 +++ b/src/PowerShellGet.psm1 @@ -236,6 +236,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -255,6 +262,15 @@ param( end { try { + + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -346,6 +362,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -365,8 +388,16 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } $steppablePipeline.End() - } catch { + } + catch { throw } } @@ -488,6 +519,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -507,6 +545,13 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } $steppablePipeline.End() } catch { throw @@ -684,6 +729,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Find-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -703,6 +755,13 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } $steppablePipeline.End() } catch { throw @@ -769,6 +828,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-InstalledPSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -788,6 +854,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -850,6 +924,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-InstalledPSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -869,6 +950,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -900,6 +989,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -919,6 +1015,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1034,6 +1138,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1053,6 +1164,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1162,6 +1281,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Install-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1172,6 +1298,14 @@ param( process { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.Process($_) } catch { throw @@ -1296,6 +1430,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('New-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1315,6 +1456,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1424,6 +1573,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1443,6 +1599,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1504,6 +1668,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Publish-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1523,6 +1694,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1622,6 +1801,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Register-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1641,6 +1827,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1759,6 +1953,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1778,6 +1979,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -1895,6 +2104,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Save-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -1914,6 +2130,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2007,6 +2231,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Set-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2026,6 +2257,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2068,6 +2307,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Test-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2087,6 +2333,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2165,6 +2419,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2184,6 +2445,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2257,6 +2526,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Uninstall-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2276,6 +2552,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2311,6 +2595,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Unregister-PSResourceRepository', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2330,6 +2621,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2417,6 +2716,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2436,6 +2742,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2520,6 +2834,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSResource', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2539,6 +2860,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2649,6 +2978,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSModuleManifest', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2668,6 +3004,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw @@ -2788,6 +3132,13 @@ param( $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Update-PSScriptFileInfo', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = {& $wrappedCmd @PSBoundParameters } + # Set internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $true) + } catch { + # Ignore if not available + } + $steppablePipeline = $scriptCmd.GetSteppablePipeline() $steppablePipeline.Begin($PSCmdlet) } catch { @@ -2807,6 +3158,14 @@ param( end { try { + # Reset internal hook for being invoked from Compat module + try { + [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("InvokedFromCompat", $false) + } + catch { + # Ignore if not available + } + $steppablePipeline.End() } catch { throw From 23b28382cea5be607ae92ee7b6f5bfb02848d808 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:52:00 -0700 Subject: [PATCH 48/74] Update version, changelog, release notes --- CHANGELOG.md | 4 ++++ src/PowerShellGet.psd1 | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 276fe73..4c26ede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +### 3.0.23-beta23 +* Changes +- Add internal hook for PSResourceGet telemetry + ### 3.0.22-beta22 * Changes - This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index b5c3286..ccab244 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'PowerShellGet.psm1' - ModuleVersion = '3.0.22' + ModuleVersion = '3.0.23' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -44,7 +44,7 @@ PrivateData = @{ PSData = @{ - Prerelease = 'beta22' + Prerelease = 'beta23' Tags = @('PackageManagement', 'PSEdition_Desktop', 'PSEdition_Core', @@ -55,6 +55,10 @@ LicenseUri = 'https://github.com/PowerShell/PowerShellGet/blob/master/LICENSE' ProjectUri = 'https://github.com/PowerShell/PowerShellGet' ReleaseNotes = @' +### 3.0.23-beta23 +* Changes +- Add internal hook for PSResourceGet telemetry + ### 3.0.22-beta22 * Changes - This module was renamed from 'CompatPowerShellGet' to 'PowerShellGet' From 5547d013364763f571ec2b27f13e2bd9b1fc0e58 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:47:50 -0700 Subject: [PATCH 49/74] Add SBOM --- .ci/releaseBuild.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index dd3d526..a8146c9 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -98,6 +98,14 @@ stages: **\*.psm1 useMinimatch: true + - ${{ if ne(variables.SkipSigning, 'True') }}: + - template: Sbom.yml@ComplianceRepo + parameters: + BuildDropPath: $(signOutPath) + Build_Repository_Uri: 'https://github.com/powershell/powershellget' + PackageName: 'PowerShellGet' + PackageVersion: '3.0.23-beta23' + # Register local folder as PSRepository # Then publish-module to that folder - pwsh: | From d8d8225d1c20d88cda0224384e8a143d49b6740f Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:17:51 -0700 Subject: [PATCH 50/74] update version and remove skip signing condition --- .ci/releaseBuild.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index a8146c9..cf8142e 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -98,13 +98,12 @@ stages: **\*.psm1 useMinimatch: true - - ${{ if ne(variables.SkipSigning, 'True') }}: - - template: Sbom.yml@ComplianceRepo - parameters: - BuildDropPath: $(signOutPath) - Build_Repository_Uri: 'https://github.com/powershell/powershellget' - PackageName: 'PowerShellGet' - PackageVersion: '3.0.23-beta23' + - template: Sbom.yml@ComplianceRepo + parameters: + BuildDropPath: $(signOutPath) + Build_Repository_Uri: 'https://github.com/powershell/powershellget' + PackageName: 'PowerShellGet' + PackageVersion: $moduleVersion # Register local folder as PSRepository # Then publish-module to that folder From bc9519d389403b4ada1af31a5b4a34cad10597ae Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:05:39 -0700 Subject: [PATCH 51/74] Update .ci/releaseBuild.yml Co-authored-by: Aditya Patwardhan --- .ci/releaseBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index cf8142e..08f742c 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -103,7 +103,8 @@ stages: BuildDropPath: $(signOutPath) Build_Repository_Uri: 'https://github.com/powershell/powershellget' PackageName: 'PowerShellGet' - PackageVersion: $moduleVersion + PackageVersion: '$(moduleVersion)' + # Register local folder as PSRepository # Then publish-module to that folder From 07caf749831a31e88205da3f6fcc7086bf0656c0 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:12:11 -0700 Subject: [PATCH 52/74] Update .ci/releaseBuild.yml Co-authored-by: Aditya Patwardhan --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 08f742c..d6b3ea6 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -105,7 +105,6 @@ stages: PackageName: 'PowerShellGet' PackageVersion: '$(moduleVersion)' - # Register local folder as PSRepository # Then publish-module to that folder - pwsh: | From 7558f456b4ea9c956feffc870ad83f6f6b0f6117 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:46:44 -0700 Subject: [PATCH 53/74] Update yaml to use PSResourceGet --- .ci/releaseBuild.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index d6b3ea6..5db9c73 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -105,8 +105,14 @@ stages: PackageName: 'PowerShellGet' PackageVersion: '$(moduleVersion)' + - pwsh: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module "Microsoft.PowerShell.PSResourceGet" -Repository PSGallery + Import-Module "Microsoft.PowerShell.PSResourceGet" + displayName: Install and import Microsoft.PowerShell.PSResourceGet + # Register local folder as PSRepository - # Then publish-module to that folder + # Then publish module to that folder - pwsh: | $localRepo = "$(Build.SourcesDirectory)/local" New-Item -Path $localRepo -ItemType Directory -Force @@ -114,8 +120,8 @@ stages: Write-Host "local repo is: " + $vstsCommandString Write-Host "##$vstsCommandString" - Register-PSRepository -Name local -SourceLocation $localRepo - Publish-Module -Path $(signOutPath) -Repository local + Register-PSResourceRepository -Name local -URI $localRepo + Publish-PSResource -Path $(signOutPath) -Repository local displayName: Publish module to local repository # finally publish the parts of the build which will be used in the next stages From d421244b1fbe23dcce8d6fa9c3b923cd7a10f599 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:02:57 -0700 Subject: [PATCH 54/74] Remove unneeded import --- .ci/releaseBuild.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/releaseBuild.yml b/.ci/releaseBuild.yml index 5db9c73..b61f697 100644 --- a/.ci/releaseBuild.yml +++ b/.ci/releaseBuild.yml @@ -108,7 +108,6 @@ stages: - pwsh: | Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module "Microsoft.PowerShell.PSResourceGet" -Repository PSGallery - Import-Module "Microsoft.PowerShell.PSResourceGet" displayName: Install and import Microsoft.PowerShell.PSResourceGet # Register local folder as PSRepository From fe34ca3eb6e1db2b78d2aae0465cd2165a3d50b6 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 29 Jan 2024 14:54:39 -0800 Subject: [PATCH 55/74] Add owners.txt file for compliance (#61) --- owners.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 owners.txt diff --git a/owners.txt b/owners.txt new file mode 100644 index 0000000..3e3f725 --- /dev/null +++ b/owners.txt @@ -0,0 +1,16 @@ +; this is an example owners.txt file which can be added at any level in the repo to indicate owners of a subtree +; this file is used by ownership enforcer to determine reviewers to add to a pull request +; you can add comments using ; as prefix +; introduce each owner in a separate line with his/her alias (not email address) +; prefixing an alias with * means that the owner will not be automatically added as a reviewer to pull requests to reduce noise, but can still be manually added and can sign off if necessary +; to learn more you can read https://microsoft.sharepoint.com/teams/WAG/EngSys/EngPipeline/cdp/SitePages/Configure%20checkin%20gates.aspx +; if you do not wish to use this feature then you can delete this file +; example (pretend the following lines are not commented): +; +; developer1 +; developer2 +; *developer3 +annavied +americks +adityap +*slee \ No newline at end of file From dfcf224178e52063763700a41ee3f82431ab4b1f Mon Sep 17 00:00:00 2001 From: OneBranch Resources Date: Fri, 15 Mar 2024 17:30:33 +0000 Subject: [PATCH 56/74] Adding OneBranch pipeline YAML config file for PowerShellGet-Official --- .pipelines/PowerShellGet-Official.yml | 170 ++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 .pipelines/PowerShellGet-Official.yml diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml new file mode 100644 index 0000000..4fe744b --- /dev/null +++ b/.pipelines/PowerShellGet-Official.yml @@ -0,0 +1,170 @@ +################################################################################# +# OneBranch Pipelines # +# This pipeline was created by EasyStart from a sample located at: # +# https://aka.ms/obpipelines/easystart/samples # +# Documentation: https://aka.ms/obpipelines # +# Yaml Schema: https://aka.ms/obpipelines/yaml/schema # +# Retail Tasks: https://aka.ms/obpipelines/tasks # +# Support: https://aka.ms/onebranchsup # +################################################################################# + +trigger: none # https://aka.ms/obpipelines/triggers + +parameters: # parameters are shown up in ADO UI in a build queue time +- name: 'debug' + displayName: 'Enable debug output' + type: boolean + default: false + +variables: + CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning + system.debug: ${{ parameters.debug }} + + BuildSolution: $(Build.SourcesDirectory)\dirs.proj + BuildConfiguration: Release + + WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers + +resources: + repositories: + - repository: templates + type: git + name: OneBranch.Pipelines/GovernedTemplates + ref: refs/heads/main + +extends: + template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates + parameters: + cloudvault: # https://aka.ms/obpipelines/cloudvault + enabled: false + globalSdl: # https://aka.ms/obpipelines/sdl + asyncSdl: + enabled: true + tsaOptionsFile: .config/tsaoptions.json + # tsa: + # enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode. + # credscan: + # suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json + policheck: + break: true # always break the build on policheck issues. You can disable it by setting to 'false' + # suppression: + # suppressionFile: $(Build.SourcesDirectory)\.gdn\global.gdnsuppress + + stages: + - stage: build + jobs: + - job: main + pool: + type: windows # read more about custom job pool types at https://aka.ms/obpipelines/yaml/jobs + + variables: # More settings at https://aka.ms/obpipelines/yaml/jobs + ob_outputDirectory: '$(Build.SourcesDirectory)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts + # https://aka.ms/obpipelines/sdl + ob_sdl_binskim_break: true # always break the build on binskim issues, even if TSA enabled. You can disable it by setting to 'false' + ob_sdl_roslyn_break: true + ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: # conditionally enable symbolsPublishing for main branch only + ob_symbolsPublishing_enabled: true # https://aka.ms/obpipelines/symbols + # ob_sdl_suppression_suppressionFile: $(Build.SourcesDirectory)\.gdn\job.gdnsuppress + + steps: + - task: UseDotNet@2 + continueOnError: true + inputs: + packageType: 'sdk' + useGlobalJson: true + performMultiLevelLookup: true + + - task: onebranch.pipeline.version@1 # generates automatic version. For other versioning options check https://aka.ms/obpipelines/versioning + displayName: 'Setup BuildNumber' + inputs: + system: 'RevisionCounter' + major: '1' + minor: '0' + exclude_commit: true + + - task: DotNetCoreCLI@2 + displayName: 'DotNetCore restore' + inputs: + command: 'custom' + projects: $(BuildSolution) + custom: 'restore' + + # roslynanalyzers task wraps around dotnet build to enable static analysis + - task: RoslynAnalyzers@3 + displayName: 'DotNetCore build with RoslynAnalyzers' + inputs: + userProvideBuildInfo: 'msBuildInfo' + msBuildCommandline: 'dotnet.exe build $(BuildSolution) --no-restore --configuration $(BuildConfiguration)' + + - task: DotNetCoreCLI@2 + displayName: 'DotNetCore test' + inputs: + command: 'test' + projects: $(BuildSolution) + arguments: '--no-build --no-restore --configuration $(BuildConfiguration) --logger trx --blame --collect "Code coverage" --results-directory $(Build.SourcesDirectory)\TestResults\' + publishTestResults: false + + - task: PublishTestResults@2 + displayName: 'Publish test results' + inputs: + testResultsFormat: VSTest + testResultsFiles: '$(Build.SourcesDirectory)\TestResults\**\*.trx' + failTaskOnFailedTests: true + + - task: DotNetCoreCLI@2 + displayName: 'DotNetCore publish' + inputs: + command: 'publish' + publishWebProjects: false + projects: $(BuildSolution) + arguments: '--no-build --no-restore --configuration $(BuildConfiguration) --output $(Build.SourcesDirectory)\out' + zipAfterPublish: false + + - task: onebranch.pipeline.signing@1 + displayName: 'Sign output' + inputs: + command: 'sign' + signing_environment: 'azure-ado' + files_to_sign: '**/*.exe;**/*.dll;**/*.ps1;**/*.psm1' + search_root: '$(Build.SourcesDirectory)\out' +# uncomment this section and edit parameters to enable VSTest instead of dotnet tests. When you enable this you dont need publish test results and codecoverage steps + # - task: VSTest@3 + # inputs: + # testSelector: 'testAssemblies' + # testAssemblyVer2: | + # **\*test*.dll + # !**\*TestAdapter.dll + # !**\obj\** + # searchFolder: '$(Build.SourcesDirectory)\out' ## or use '$(Agent.BuildDirectory)' + ##testFiltercriteria: 'TestCategory=UnitTests' ## update + #resultsFolder: '$(Build.SourcesDirectory)\out\logs\TestResults' + #runInParallel: true ## this setting helps to speed up test case execution but if youhave depdencies between tests you change or remove this but having it enabled is always recommended + #codeCoverageEnabled: true + #testRunTitle: 'release_x64' ## Update this for a custom readable way of taggin your test run when you query in ADO test runs view + #platform: 'x64' ## you can modify this as needed + #configuration: 'release' + #publishRunAttachments: false + #failOnMinTestsNotRun: true + #rerunFailedTests: true + #rerunFailedThreshold: '70' +# https://aka.ms/obpipelines/cloudtest +# uncomment this section and edit parameters to enable CloudTest + # - stage: cloudtest + # dependsOn: build_stage + # jobs: + # - job: cloudtestjob + # pool: + # type: cloudtestagentless + # continueOnError: true + # steps: + # - task: CloudTestServerBuildTask@1 + # displayName: 'CloudTest' + # inputs: + # connectedServiceName: 'CloudTest-prod' + # cloudTestTenant: 'onebranchtest' + # testMapLocation: '[BuildRoot]\ClassLibrary.UnitTest\TestMapCdp.xml' + # pipelineArtifactName: 'drop_build_main' + # pipelineArtifactBuildUrl: '$(System.TaskDefinitionsUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)' + # parserProperties: 'worker:VsTestVersion=V150;CodeCoverageType=Dynamic;worker:TestVar=$(RUN_PIPELINE_VARIABLE)' + # cacheEnabled: false + # scheduleBuildRequesterAlias: 'azbldrun' \ No newline at end of file From 86afb9e45c3bdb349a81ef5eb7c8864a45a464ae Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:26:18 -0700 Subject: [PATCH 57/74] Add tsaoptions, update pipeline --- .config/tsaoptions.json | 10 + .pipelines/PowerShellGet-Official.yml | 358 ++++++++++++++++---------- 2 files changed, 232 insertions(+), 136 deletions(-) create mode 100644 .config/tsaoptions.json diff --git a/.config/tsaoptions.json b/.config/tsaoptions.json new file mode 100644 index 0000000..f73a19d --- /dev/null +++ b/.config/tsaoptions.json @@ -0,0 +1,10 @@ +{ + "instanceUrl": "https://msazure.visualstudio.com", + "projectName": "One", + "areaPath": "One\\MGMT\\Compute\\Powershell\\Powershell\\PowerShell Core", + "notificationAliases": [ + "adityap@microsoft.com", + "americks@microsoft.com", + "annavied@microsoft.com" + ] +} \ No newline at end of file diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 4fe744b..833e52b 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -7,9 +7,13 @@ # Retail Tasks: https://aka.ms/obpipelines/tasks # # Support: https://aka.ms/onebranchsup # ################################################################################# - +name: PowerShellGet-Release-$(Build.BuildId) trigger: none # https://aka.ms/obpipelines/triggers - +pr: + branches: + include: + - main + - release* parameters: # parameters are shown up in ADO UI in a build queue time - name: 'debug' displayName: 'Enable debug output' @@ -17,154 +21,236 @@ parameters: # parameters are shown up in ADO UI in a build queue time default: false variables: - CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning - system.debug: ${{ parameters.debug }} - - BuildSolution: $(Build.SourcesDirectory)\dirs.proj - BuildConfiguration: Release - - WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers + - name: DOTNET_CLI_TELEMETRY_OPTOUT + value: 1 + - name: POWERSHELL_TELEMETRY_OPTOUT + value: 1 + - name: WindowsContainerImage + value: onebranch.azurecr.io/windows/ltsc2022/vse2022:latest # Docker image which is used to build the project https://aka.ms/obpipelines/containers resources: repositories: - - repository: templates + - repository: onebranchTemplates type: git name: OneBranch.Pipelines/GovernedTemplates ref: refs/heads/main extends: - template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates + template: v2/OneBranch.Official.CrossPlat.yml@onebranchTemplates # https://aka.ms/obpipelines/templates parameters: - cloudvault: # https://aka.ms/obpipelines/cloudvault - enabled: false - globalSdl: # https://aka.ms/obpipelines/sdl - asyncSdl: + featureFlags: + WindowsHostVersion: '1ESWindows2022' + customTags: 'ES365AIMigrationTooling' + globalSdl: + disableLegacyManifest: true + sbom: enabled: true - tsaOptionsFile: .config/tsaoptions.json - # tsa: - # enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode. - # credscan: - # suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json - policheck: - break: true # always break the build on policheck issues. You can disable it by setting to 'false' - # suppression: - # suppressionFile: $(Build.SourcesDirectory)\.gdn\global.gdnsuppress + packageName: Microsoft.PowerShell.PowerShellGet + codeql: + compiled: + enabled: true + asyncSdl: # https://aka.ms/obpipelines/asyncsdl + enabled: true + forStages: [Build] + credscan: + enabled: true + scanFolder: $(Build.SourcesDirectory)\PowerShellGet + binskim: + enabled: true + apiscan: + enabled: false stages: - - stage: build + - stage: stagebuild + displayName: Build and Package PowerShellGet jobs: - - job: main + - job: jobbuild + displayName: Build PowerShellGet Files + variables: # More settings at https://aka.ms/obpipelines/yaml/jobs + - name: ob_outputDirectory + value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT' + - name: repoRoot + value: $(Build.SourcesDirectory)\PowerShellGet + - name: ob_sdl_tsa_configFile + value: $(Build.SourcesDirectory)\PowerShellGet\.config\tsaoptions.json + - name: signSrcPath + value: $(repoRoot)/out + - name: ob_sdl_sbom_enabled + value: true + - name: ob_signing_setup_enabled + value: true + #CodeQL tasks added manually to workaround signing failures + - name: ob_sdl_codeql_compiled_enabled + value: false + pool: + type: windows + steps: + - checkout: self + env: + ob_restore_phase: true # Set ob_restore_phase to run this step before '🔒 Setup Signing' step. + + - pwsh: | + if (-not (Test-Path $(repoRoot)/.config/tsaoptions.json)) { + Get-ChildItem $(Build.SourcesDirectory) -recurse -ErrorAction SilentlyContinue + throw "tsaoptions.json does not exist under $(repoRoot)/.config" + } + displayName: Test if tsaoptions.json exists + env: + ob_restore_phase: true # Set ob_restore_phase to run this step before '🔒 Setup Signing' step. + + - pwsh: | + Get-ChildItem env: + displayName: Capture Environment + env: + ob_restore_phase: true # Set ob_restore_phase to run this step before '🔒 Setup Signing' step. + + - task: onebranch.pipeline.signing@1 + displayName: Sign 1st party files + inputs: + command: 'sign' + signing_profile: external_distribution + files_to_sign: '**\*.psd1;**\*.psm1;**\*.ps1xml' + search_root: $(signSrcPath) + + - task: CopyFiles@2 + displayName: "Copy signed files to ob_outputDirectory - '$(ob_outputDirectory)'" + inputs: + SourceFolder: "$(signSrcPath)" + Contents: '**' + TargetFolder: $(ob_outputDirectory) + + - pwsh: | + Write-Host "Displaying contents of signSrcPath:" + Get-ChildItem $(signSrcPath) -Recurse + Write-Host "Displaying contents of ob_outputDirectory:" + Get-ChildItem $(ob_outputDirectory) -Recurse + displayName: Get contents of dirs with signed files + + - job: nupkg + dependsOn: jobbuild + displayName: Package PowerShellGet + variables: + - name: ob_outputDirectory + value: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT' + - name: repoRoot + value: $(Build.SourcesDirectory)\PowerShellGet + - name: ob_sdl_tsa_configFile + value: $(Build.SourcesDirectory)\PowerShellGet\.config\tsaoptions.json + # Disable because SBOM was already built in the previous job + - name: ob_sdl_sbom_enabled + value: false + - name: signOutPath + value: $(repoRoot)/signed + - name: ob_signing_setup_enabled + value: true + # This job is not compiling code, so disable codeQL + - name: ob_sdl_codeql_compiled_enabled + value: false + pool: - type: windows # read more about custom job pool types at https://aka.ms/obpipelines/yaml/jobs + type: windows + steps: + - checkout: self + + - pwsh: | + if (-not (Test-Path $(repoRoot)/.config/tsaoptions.json)) { + Get-ChildItem $(Build.SourcesDirectory) -recurse -ErrorAction SilentlyContinue + throw "tsaoptions.json does not exist under $(repoRoot)/.config" + } + displayName: Test if tsaoptions.json exists + + - task: DownloadPipelineArtifact@2 + displayName: 'Download build files' + inputs: + targetPath: $(signOutPath) + artifact: drop_stagebuild_jobbuild + + - pwsh: | + Set-Location "$(signOutPath)" + Write-Host "Contents of signOutPath:" + Get-ChildItem $(signOutPath) -Recurse + displayName: Capture artifacts directory structure + + - pwsh: | + $module = 'Microsoft.PowerShell.PSResourceGet' + Write-Verbose "installing $module..." -verbose + $ProgressPreference = 'SilentlyContinue' + Install-Module $module -AllowClobber -Force + displayName: Install PSResourceGet 0.9.0 or above for build.psm1 + + - pwsh: | + Set-Location "$(signOutPath)\PowerShellGet" + New-Item -ItemType Directory -Path "$(signOutPath)\PublishedNupkg" -Force + Register-PSResourceRepository -Name 'localRepo' -Uri "$(signOutPath)\PublishedNupkg" + Publish-PSResource -Path "$(signOutPath)\PowerShellGet" -Repository 'localRepo' -Verbose + displayName: Create nupkg for publishing + + - task: onebranch.pipeline.signing@1 + displayName: Sign nupkg + inputs: + command: 'sign' + signing_profile: external_distribution + files_to_sign: '**\*.nupkg' + search_root: "$(signOutPath)\PublishedNupkg" + + - pwsh: | + Set-Location "$(signOutPath)\PublishedNupkg" + Write-Host "Contents of signOutPath:" + Get-ChildItem "$(signOutPath)" -Recurse + displayName: Find Nupkg + + - task: CopyFiles@2 + displayName: "Copy nupkg to ob_outputDirectory - '$(ob_outputDirectory)'" + inputs: + Contents: $(signOutPath)\PublishedNupkg\PowerShellGet.*.nupkg + TargetFolder: $(ob_outputDirectory) - variables: # More settings at https://aka.ms/obpipelines/yaml/jobs - ob_outputDirectory: '$(Build.SourcesDirectory)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts - # https://aka.ms/obpipelines/sdl - ob_sdl_binskim_break: true # always break the build on binskim issues, even if TSA enabled. You can disable it by setting to 'false' - ob_sdl_roslyn_break: true - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: # conditionally enable symbolsPublishing for main branch only - ob_symbolsPublishing_enabled: true # https://aka.ms/obpipelines/symbols - # ob_sdl_suppression_suppressionFile: $(Build.SourcesDirectory)\.gdn\job.gdnsuppress + - pwsh: | + Write-Host "Contents of ob_outputDirectory:" + Get-ChildItem "$(ob_outputDirectory)" -Recurse + displayName: Find Signed Nupkg + - stage: release + displayName: Release PowerShellGet + dependsOn: stagebuild + variables: + version: $[ stageDependencies.build.main.outputs['package.version'] ] + drop: $(Pipeline.Workspace)/drop_build_main + jobs: + - job: validation + displayName: Manual validation + pool: + type: agentless + timeoutInMinutes: 1440 + steps: + - task: ManualValidation@0 + displayName: Wait 24 hours for validation + inputs: + instructions: Please validate the release + timeoutInMinutes: 1440 + - job: PSGalleryPublish + displayName: Publish to PSGallery + dependsOn: validation + pool: + type: windows + variables: + ob_outputDirectory: '$(Build.ArtifactStagingDirectory)/ONEBRANCH_ARTIFACT' steps: - - task: UseDotNet@2 - continueOnError: true - inputs: - packageType: 'sdk' - useGlobalJson: true - performMultiLevelLookup: true - - - task: onebranch.pipeline.version@1 # generates automatic version. For other versioning options check https://aka.ms/obpipelines/versioning - displayName: 'Setup BuildNumber' - inputs: - system: 'RevisionCounter' - major: '1' - minor: '0' - exclude_commit: true - - - task: DotNetCoreCLI@2 - displayName: 'DotNetCore restore' - inputs: - command: 'custom' - projects: $(BuildSolution) - custom: 'restore' - - # roslynanalyzers task wraps around dotnet build to enable static analysis - - task: RoslynAnalyzers@3 - displayName: 'DotNetCore build with RoslynAnalyzers' - inputs: - userProvideBuildInfo: 'msBuildInfo' - msBuildCommandline: 'dotnet.exe build $(BuildSolution) --no-restore --configuration $(BuildConfiguration)' - - - task: DotNetCoreCLI@2 - displayName: 'DotNetCore test' - inputs: - command: 'test' - projects: $(BuildSolution) - arguments: '--no-build --no-restore --configuration $(BuildConfiguration) --logger trx --blame --collect "Code coverage" --results-directory $(Build.SourcesDirectory)\TestResults\' - publishTestResults: false - - - task: PublishTestResults@2 - displayName: 'Publish test results' - inputs: - testResultsFormat: VSTest - testResultsFiles: '$(Build.SourcesDirectory)\TestResults\**\*.trx' - failTaskOnFailedTests: true - - - task: DotNetCoreCLI@2 - displayName: 'DotNetCore publish' - inputs: - command: 'publish' - publishWebProjects: false - projects: $(BuildSolution) - arguments: '--no-build --no-restore --configuration $(BuildConfiguration) --output $(Build.SourcesDirectory)\out' - zipAfterPublish: false - - - task: onebranch.pipeline.signing@1 - displayName: 'Sign output' - inputs: - command: 'sign' - signing_environment: 'azure-ado' - files_to_sign: '**/*.exe;**/*.dll;**/*.ps1;**/*.psm1' - search_root: '$(Build.SourcesDirectory)\out' -# uncomment this section and edit parameters to enable VSTest instead of dotnet tests. When you enable this you dont need publish test results and codecoverage steps - # - task: VSTest@3 - # inputs: - # testSelector: 'testAssemblies' - # testAssemblyVer2: | - # **\*test*.dll - # !**\*TestAdapter.dll - # !**\obj\** - # searchFolder: '$(Build.SourcesDirectory)\out' ## or use '$(Agent.BuildDirectory)' - ##testFiltercriteria: 'TestCategory=UnitTests' ## update - #resultsFolder: '$(Build.SourcesDirectory)\out\logs\TestResults' - #runInParallel: true ## this setting helps to speed up test case execution but if youhave depdencies between tests you change or remove this but having it enabled is always recommended - #codeCoverageEnabled: true - #testRunTitle: 'release_x64' ## Update this for a custom readable way of taggin your test run when you query in ADO test runs view - #platform: 'x64' ## you can modify this as needed - #configuration: 'release' - #publishRunAttachments: false - #failOnMinTestsNotRun: true - #rerunFailedTests: true - #rerunFailedThreshold: '70' -# https://aka.ms/obpipelines/cloudtest -# uncomment this section and edit parameters to enable CloudTest - # - stage: cloudtest - # dependsOn: build_stage - # jobs: - # - job: cloudtestjob - # pool: - # type: cloudtestagentless - # continueOnError: true - # steps: - # - task: CloudTestServerBuildTask@1 - # displayName: 'CloudTest' - # inputs: - # connectedServiceName: 'CloudTest-prod' - # cloudTestTenant: 'onebranchtest' - # testMapLocation: '[BuildRoot]\ClassLibrary.UnitTest\TestMapCdp.xml' - # pipelineArtifactName: 'drop_build_main' - # pipelineArtifactBuildUrl: '$(System.TaskDefinitionsUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)' - # parserProperties: 'worker:VsTestVersion=V150;CodeCoverageType=Dynamic;worker:TestVar=$(RUN_PIPELINE_VARIABLE)' - # cacheEnabled: false - # scheduleBuildRequesterAlias: 'azbldrun' \ No newline at end of file + - download: current + displayName: Download artifact + + - pwsh: | + Get-ChildItem $(Pipeline.Workspace) -Recurse + displayName: Capture environment + + - pwsh: | + Get-ChildItem "$(Pipeline.Workspace)/drop_stagebuild_nupkg" -Recurse + displayName: Find signed Nupkg + + - task: NuGetCommand@2 + displayName: Push PowerShellGet module artifacts to PSGallery feed + inputs: + command: push + packagesToPush: '$(Pipeline.Workspace)\drop_stagebuild_nupkg\PowerShellGet\signed\PublishedNupkg\PowerShellGet.*.nupkg' + nuGetFeedType: external + publishFeedCredentials: PSGet-PSGalleryPush From 635826b177a4c34c245175e084b1b27e8b82abd9 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:48:23 -0700 Subject: [PATCH 58/74] Add CredScanSuppressions --- .config/CredScanSuppressions.csk | 9 +++++++++ .config/CredScanSuppressions.json | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 .config/CredScanSuppressions.csk create mode 100644 .config/CredScanSuppressions.json diff --git a/.config/CredScanSuppressions.csk b/.config/CredScanSuppressions.csk new file mode 100644 index 0000000..ca746bf --- /dev/null +++ b/.config/CredScanSuppressions.csk @@ -0,0 +1,9 @@ +{ + "tool": "Credential Scanner", + "suppressions": [ + { + "file": "Test/PublishPSResource.Tests.ps1", + "_justification": "Auto generated fake key" + } + ] + } \ No newline at end of file diff --git a/.config/CredScanSuppressions.json b/.config/CredScanSuppressions.json new file mode 100644 index 0000000..ca746bf --- /dev/null +++ b/.config/CredScanSuppressions.json @@ -0,0 +1,9 @@ +{ + "tool": "Credential Scanner", + "suppressions": [ + { + "file": "Test/PublishPSResource.Tests.ps1", + "_justification": "Auto generated fake key" + } + ] + } \ No newline at end of file From 396ebe2cac2df37a5df73e038bc43670d76a1e11 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:49:25 -0700 Subject: [PATCH 59/74] Add global.json file --- global.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 0000000..2715bb6 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "6.0.418" + } +} \ No newline at end of file From 4dcc7818b2e10181e6e1ca7cef7d29f15102c66d Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:08:39 -0700 Subject: [PATCH 60/74] Update signSrcPath --- .pipelines/PowerShellGet-Official.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 833e52b..0165af7 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -74,7 +74,7 @@ extends: - name: ob_sdl_tsa_configFile value: $(Build.SourcesDirectory)\PowerShellGet\.config\tsaoptions.json - name: signSrcPath - value: $(repoRoot)/out + value: $(repoRoot) - name: ob_sdl_sbom_enabled value: true - name: ob_signing_setup_enabled @@ -112,6 +112,11 @@ extends: files_to_sign: '**\*.psd1;**\*.psm1;**\*.ps1xml' search_root: $(signSrcPath) + - pwsh: | + Write-Host "Displaying contents of signSrcPath:" + Get-ChildItem $(signSrcPath) -Recurse + displayName: Get contents of signSrcPath + - task: CopyFiles@2 displayName: "Copy signed files to ob_outputDirectory - '$(ob_outputDirectory)'" inputs: From 9ffe30e37f23743b9a8d8ea2670201325644e388 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:15:43 -0700 Subject: [PATCH 61/74] Update signSrcPath --- .pipelines/PowerShellGet-Official.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 0165af7..5f2bdd7 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -74,7 +74,7 @@ extends: - name: ob_sdl_tsa_configFile value: $(Build.SourcesDirectory)\PowerShellGet\.config\tsaoptions.json - name: signSrcPath - value: $(repoRoot) + value: $(repoRoot)/out - name: ob_sdl_sbom_enabled value: true - name: ob_signing_setup_enabled @@ -104,6 +104,16 @@ extends: env: ob_restore_phase: true # Set ob_restore_phase to run this step before '🔒 Setup Signing' step. + - pwsh: | + Write-Host "Displaying contents of repoRoot:" + Get-ChildItem $(repoRoot) -Recurse + displayName: Get contents of repoRoot + + - pwsh: | + Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath)/PowerShellGet.psd1 -Force + Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath)/PowerShellGet.psm1 -Force + displayName: Copy files to be signed to signSrcPath + - task: onebranch.pipeline.signing@1 displayName: Sign 1st party files inputs: From 9f4533d523bb8bb8ee0b0a86b34c7c6a4d6d23be Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:23:54 -0700 Subject: [PATCH 62/74] Update copy task --- .pipelines/PowerShellGet-Official.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 5f2bdd7..a983e2b 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -110,8 +110,8 @@ extends: displayName: Get contents of repoRoot - pwsh: | - Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath)/PowerShellGet.psd1 -Force - Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath)/PowerShellGet.psm1 -Force + Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath) -Force + Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath) -Force displayName: Copy files to be signed to signSrcPath - task: onebranch.pipeline.signing@1 From fcf8fb9c8243a1516ae4a3d0229f65c93e6cfc7e Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:51:29 -0700 Subject: [PATCH 63/74] Add logging to copy files task --- .pipelines/PowerShellGet-Official.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index a983e2b..2b88ea6 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -110,8 +110,11 @@ extends: displayName: Get contents of repoRoot - pwsh: | - Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath) -Force - Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath) -Force + Get-ChildItem $(repoRoot)/src/PowerShellGet.psd1 + Get-ChildItem $(repoRoot)/src/PowerShellGet.psm1 + + Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath) -Verbose + Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath) -Verbose displayName: Copy files to be signed to signSrcPath - task: onebranch.pipeline.signing@1 From ec99f579d4a44ac520047b2215de9d6dfa3368cb Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:52:37 -0700 Subject: [PATCH 64/74] Update copy task to include full file name --- .pipelines/PowerShellGet-Official.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 2b88ea6..c78167a 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -113,8 +113,8 @@ extends: Get-ChildItem $(repoRoot)/src/PowerShellGet.psd1 Get-ChildItem $(repoRoot)/src/PowerShellGet.psm1 - Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath) -Verbose - Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath) -Verbose + Copy-Item $(repoRoot)/src/PowerShellGet.psd1 $(signSrcPath)/PowerShellGet.psd1 -Verbose + Copy-Item $(repoRoot)/src/PowerShellGet.psm1 $(signSrcPath)/PowerShellGet.psm1 -Verbose displayName: Copy files to be signed to signSrcPath - task: onebranch.pipeline.signing@1 From 77735a1b4ffb652ade6d603d9ebf5eba8de736c1 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:50:49 -0700 Subject: [PATCH 65/74] make dir --- .pipelines/PowerShellGet-Official.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index c78167a..41bf01e 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -108,6 +108,10 @@ extends: Write-Host "Displaying contents of repoRoot:" Get-ChildItem $(repoRoot) -Recurse displayName: Get contents of repoRoot + + - pwsh: | + New-Item -ItemType Directory -Path $(signSrcPath) -Force + displayName: Make signSrcPath directory - pwsh: | Get-ChildItem $(repoRoot)/src/PowerShellGet.psd1 From 34a6a7a395a9bba38927d3d7c53a2bf78457d018 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:31:33 -0700 Subject: [PATCH 66/74] Update path variables --- .pipelines/PowerShellGet-Official.yml | 32 +++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 41bf01e..85dfcbb 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -74,7 +74,7 @@ extends: - name: ob_sdl_tsa_configFile value: $(Build.SourcesDirectory)\PowerShellGet\.config\tsaoptions.json - name: signSrcPath - value: $(repoRoot)/out + value: $(repoRoot)/out/PowerShellGet - name: ob_sdl_sbom_enabled value: true - name: ob_signing_setup_enabled @@ -163,6 +163,10 @@ extends: value: false - name: signOutPath value: $(repoRoot)/signed + - name: signedModuleRoot + value: $(signOutPath)/PowerShellGet + - name: signedNupkgPath + value: $(signOutPath)/PublishedNupkg - name: ob_signing_setup_enabled value: true # This job is not compiling code, so disable codeQL @@ -184,13 +188,13 @@ extends: - task: DownloadPipelineArtifact@2 displayName: 'Download build files' inputs: - targetPath: $(signOutPath) + targetPath: $(signedModuleRoot) artifact: drop_stagebuild_jobbuild - pwsh: | - Set-Location "$(signOutPath)" - Write-Host "Contents of signOutPath:" - Get-ChildItem $(signOutPath) -Recurse + Set-Location "$(signedModuleRoot)" + Write-Host "Contents of signedModuleRoot:" + Get-ChildItem $(signedModuleRoot) -Recurse displayName: Capture artifacts directory structure - pwsh: | @@ -201,10 +205,10 @@ extends: displayName: Install PSResourceGet 0.9.0 or above for build.psm1 - pwsh: | - Set-Location "$(signOutPath)\PowerShellGet" - New-Item -ItemType Directory -Path "$(signOutPath)\PublishedNupkg" -Force - Register-PSResourceRepository -Name 'localRepo' -Uri "$(signOutPath)\PublishedNupkg" - Publish-PSResource -Path "$(signOutPath)\PowerShellGet" -Repository 'localRepo' -Verbose + Set-Location "$(signOutPath)" + New-Item -ItemType Directory -Path "$(signedNupkgPath)" -Force + Register-PSResourceRepository -Name 'localRepo' -Uri "$(signedNupkgPath)" + Publish-PSResource -Path "$(signedModuleRoot)" -Repository 'localRepo' -Verbose displayName: Create nupkg for publishing - task: onebranch.pipeline.signing@1 @@ -213,18 +217,18 @@ extends: command: 'sign' signing_profile: external_distribution files_to_sign: '**\*.nupkg' - search_root: "$(signOutPath)\PublishedNupkg" + search_root: "$(signedNupkgPath)" - pwsh: | - Set-Location "$(signOutPath)\PublishedNupkg" - Write-Host "Contents of signOutPath:" - Get-ChildItem "$(signOutPath)" -Recurse + Set-Location "$(signedNupkgPath)" + Write-Host "Contents of signedNupkgPath:" + Get-ChildItem "$(signedNupkgPath)" -Recurse displayName: Find Nupkg - task: CopyFiles@2 displayName: "Copy nupkg to ob_outputDirectory - '$(ob_outputDirectory)'" inputs: - Contents: $(signOutPath)\PublishedNupkg\PowerShellGet.*.nupkg + Contents: $(signedNupkgPath)\PowerShellGet.*.nupkg TargetFolder: $(ob_outputDirectory) - pwsh: | From fec72d52427d55b871328ef17103d37af827d4a6 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:09:32 -0700 Subject: [PATCH 67/74] Update version --- src/PowerShellGet.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index ccab244..4f89495 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'PowerShellGet.psm1' - ModuleVersion = '3.0.23' + ModuleVersion = '3.0.222' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' From 7d2855cf63558b07c01f0936327af95c81b1dc83 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:04:27 -0700 Subject: [PATCH 68/74] Update .config/CredScanSuppressions.json Co-authored-by: Anam Navied --- .config/CredScanSuppressions.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.config/CredScanSuppressions.json b/.config/CredScanSuppressions.json index ca746bf..e6a6cfb 100644 --- a/.config/CredScanSuppressions.json +++ b/.config/CredScanSuppressions.json @@ -6,4 +6,5 @@ "_justification": "Auto generated fake key" } ] - } \ No newline at end of file + } + \ No newline at end of file From 01d8d778a11a8cd38c48a88a7d2b9a31dc27396a Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:04:35 -0700 Subject: [PATCH 69/74] Update .config/tsaoptions.json Co-authored-by: Anam Navied --- .config/tsaoptions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/tsaoptions.json b/.config/tsaoptions.json index f73a19d..692eaec 100644 --- a/.config/tsaoptions.json +++ b/.config/tsaoptions.json @@ -7,4 +7,4 @@ "americks@microsoft.com", "annavied@microsoft.com" ] -} \ No newline at end of file +} From 1881345a95f30b805d400f6deea00f8ed497e1fa Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:04:47 -0700 Subject: [PATCH 70/74] Update global.json Co-authored-by: Anam Navied --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 2715bb6..1cec616 100644 --- a/global.json +++ b/global.json @@ -2,4 +2,4 @@ "sdk": { "version": "6.0.418" } -} \ No newline at end of file +} From 651bb2044babe832b7753ee01df77d5fc1e82d54 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:05:02 -0700 Subject: [PATCH 71/74] Update .pipelines/PowerShellGet-Official.yml Co-authored-by: Aditya Patwardhan --- .pipelines/PowerShellGet-Official.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/PowerShellGet-Official.yml b/.pipelines/PowerShellGet-Official.yml index 85dfcbb..2d13f29 100644 --- a/.pipelines/PowerShellGet-Official.yml +++ b/.pipelines/PowerShellGet-Official.yml @@ -51,7 +51,7 @@ extends: enabled: true asyncSdl: # https://aka.ms/obpipelines/asyncsdl enabled: true - forStages: [Build] + forStages: [stagebuild] credscan: enabled: true scanFolder: $(Build.SourcesDirectory)\PowerShellGet From ad5c39c4df1c85d761154fbb77772e7f69960053 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:06:34 -0700 Subject: [PATCH 72/74] Add code review suggestions --- .config/CredScanSuppressions.csk | 9 --------- src/PowerShellGet.psd1 | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .config/CredScanSuppressions.csk diff --git a/.config/CredScanSuppressions.csk b/.config/CredScanSuppressions.csk deleted file mode 100644 index ca746bf..0000000 --- a/.config/CredScanSuppressions.csk +++ /dev/null @@ -1,9 +0,0 @@ -{ - "tool": "Credential Scanner", - "suppressions": [ - { - "file": "Test/PublishPSResource.Tests.ps1", - "_justification": "Auto generated fake key" - } - ] - } \ No newline at end of file diff --git a/src/PowerShellGet.psd1 b/src/PowerShellGet.psd1 index 4f89495..ccab244 100644 --- a/src/PowerShellGet.psd1 +++ b/src/PowerShellGet.psd1 @@ -8,7 +8,7 @@ @{ RootModule = 'PowerShellGet.psm1' - ModuleVersion = '3.0.222' + ModuleVersion = '3.0.23' GUID = '68ec3ec1-55bf-42f8-9add-d224e5c76548' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' From bc6fbf73a6c4a2386f3bbeefbaf3b0d63bda9242 Mon Sep 17 00:00:00 2001 From: alerickson <25858831+alerickson@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:33:54 -0700 Subject: [PATCH 73/74] Delete global.json --- global.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 global.json diff --git a/global.json b/global.json deleted file mode 100644 index 1cec616..0000000 --- a/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sdk": { - "version": "6.0.418" - } -} From a2dac8e74603f7c9eec4a54c5e23459531751b0d Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:42:31 -0700 Subject: [PATCH 74/74] Update Code of Conduct and Security Policy (#72) Updates the readme, code of conduct and security policy per OSPO request. --- CODE_OF_CONDUCT.md | 14 ++++++++------ README.md | 10 ++++++++++ SECURITY.md | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 SECURITY.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 638de68..8312fc6 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,8 +1,10 @@ -# Code of Conduct +# Microsoft Open Source Code of Conduct -This project has adopted the [Microsoft Open Source Code of Conduct][conduct-code]. -For more information see the [Code of Conduct FAQ][conduct-FAQ] or contact [opencode@microsoft.com][conduct-email] with any additional questions or comments. +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -[conduct-code]: https://opensource.microsoft.com/codeofconduct/ -[conduct-FAQ]: https://opensource.microsoft.com/codeofconduct/faq/ -[conduct-email]: mailto:opencode@microsoft.com \ No newline at end of file +Resources: + +- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) +- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns +- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support) diff --git a/README.md b/README.md index 68198a6..e973a52 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,13 @@ cd path/to/PowerShellGet ```powershell Import-Module src/PowerShellGet -Force ``` + +Code of Conduct +=============== + +Please see our [Code of Conduct](CODE_OF_CONDUCT.md) before participating in this project. + +Security Policy +=============== + +For any security issues, please see our [Security Policy](SECURITY.md). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..f941d30 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,41 @@ + + +## Security + +Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin) and [PowerShell](https://github.com/PowerShell). + +If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). + +If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + + * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) + * Full paths of source file(s) related to the manifestation of the issue + * The location of the affected source code (tag/branch/commit or direct URL) + * Any special configuration required to reproduce the issue + * Step-by-step instructions to reproduce the issue + * Proof-of-concept or exploit code (if possible) + * Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. + +## Preferred Languages + +We prefer all communications to be in English. + +## Policy + +Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). + +