JustinGrote / ModuleFast

A "fast and loose" way to install modules from Powershell Gallery quickly. Meant for CICD, not production
Other
74 stars 5 forks source link

Errors as soon GUID is not used with MaximumVersion (#Requires-Spec) #43

Closed sharedstuff closed 7 months ago

sharedstuff commented 7 months ago

Hi Justin

Error: Cannot specify Guid unless min and max are the same

Any chance to get this working?

JustinGrote commented 7 months ago

@sharedstuff can you clarify? I made this test and it seems to work fine for the latest main version.

  It 'Resolves GUID with version range' {
    $scriptPath = Join-Path $testDrive 'testscript.ps1'
    "#requires -Module @{ModuleName='PreReleaseTest';Guid='3cb1a381-5d96-4b56-843e-dd97cf4c6545';ModuleVersion='0.0.1';MaximumVersion='0.0.2'}" | Out-File $scriptPath
    $plan = Install-ModuleFast @imfParams -Path $scriptPath -Plan
    $plan.Name -eq 'PrereleaseTest'
    $plan.ModuleVersion | Should -Be '0.0.1'
  }
JustinGrote commented 7 months ago

Also, just FYI as of now there is no GUID checking occurring, this is a little tricky because in Nuget v3 there is no standard field when publishing a module that will have the GUID, so the evaluation of the GUID can only happen after the module has been installed so that the module manifest can be read, so that means that a plan is unlikely to catch the issue unless we pre-download the package. I will add a warning to this effect if GUID is specified in a modulespec

sharedstuff commented 7 months ago

there shouldnt be a need to provide a MaximumVersion if i just add a guid - examples: @{ ModuleName='abc'; ModuleVersion='1' } --> works @{ ModuleName='abc'; GUID='guid'; ModuleVersion='1' } --> doesnt work @{ ModuleName='abc'; GUID='guid'; ModuleVersion='1'; MaximumVersion='1' } --> will work again - matches your example

JustinGrote commented 7 months ago

That's a PowerShell ModuleSpecification limitation I'm afraid:

> [Microsoft.PowerShell.Commands.ModuleSpecification]@{ModuleName='Test';Guid='3cb1a381-5d96-4b56-843e-dd97cf4c6545'}
InvalidArgument: Cannot convert value "System.Collections.Hashtable" to type "Microsoft.PowerShell.Commands.ModuleSpecification". Error: "The 'ModuleVersion', 'MaximumVersion' and 'RequiredVersion' members do not exist in the hashtable that describes this module. One of these three members must exist, and be assigned a version number in the format 'n.n.n.n'."
JustinGrote commented 7 months ago

@sharedstuff I've added install-time GUID checking but specifying a #requires with only a GUID will remain unsupported unless support for it is added in the PowerShell ModuleSpecification class itself. Sorry!

sharedstuff commented 7 months ago

@JustinGrote Thx the fast replies / evaluation Works for me - as you elaborated above: if it has no real use anyways / is not being checked against - all fine - im aware now 👍