PowerShell / PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
https://www.PowerShellGallery.com
MIT License
431 stars 138 forks source link

PowerShellGet needs to check compatibility before installing a script or module #528

Open KirkMunro opened 5 years ago

KirkMunro commented 5 years ago

For reference, see the discussion on PowerShell/PowerShell#10318.

That PR ensures that the workflow keyword results in a parse error. If you build that PR and run it, and try to run the PowerShellGet tests, you get an error when one of the tests tries to install Fabrikam-ServerScript from www.poshtestgallery.com. The error occurs because that script has a workflow defined within it, and that no longer parses, so the installation fails. The error occurs when PowerShellGet tries to get the script info, which requires parsing the script, which won't work in PowerShell 7.

The simple solution to this is for PowerShellGet to check if a script/module has workflow in it before it tries to install it, and prevent that installation from happening with an appropriate error message in PowerShell 6+. Users can still save the script (this does not do any parsing checks), but they won't be able to install such a script, and they'll know why because the error message will tell them the script includes a PowerShell workflow, which is not supported on PowerShell 6 or later.

Steps to reproduce

# Note you need to register www.poshtestgallery.com as a repo and save
# the repo's name in $repoName before you run this command on
# PowerShell 6 or later.
Install-Script Fabrikam-ServerScript -Repository $repoName

Expected behavior

An error message indicating that the script cannot be installed because it contains PowerShell workflow, which is not available in PowerShell 6 or later.

Actual behavior

On PowerShell 6, the script installs.

On PowerShell 7 with the PR code: an error is generated because the script does not parse.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.0.0-preview.2
PSEdition                      Core
GitCommitId                    7.0.0-preview.2-63-g00949ab3522c66bc2efdcb62779d64c7546a5830
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> Get-Module -ListAvailable PowerShellGet,PackageManagement
    Directory: C:\Users\kirka\OneDrive\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.4.3                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.2                   PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.4                   PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     1.2.3                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     1.1.7.2               PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.1.4                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     2.0.3                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     2.0.0                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}

    Directory: C:\users\kirka\source\repos\powershell\src\powershell-win-core\bin\debug\netcoreapp3.0\win7-x64\publish\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.4.3                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.2                   PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
> Get-PackageProvider -ListAvailable
Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            2.2.0.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, Acce…
PowerShellGet            2.1.4.0
PowerShellGet            2.0.3.0
PowerShellGet            2.0.0.0
SydneyhSmith commented 5 years ago

@KirkMunro thanks for working on this PR and opening the issue in this repo, we will track this request here...thanks!