Skip to content

Commit

Permalink
Merge pull request #111 from raandree/master and deploy!
Browse files Browse the repository at this point in the history
Adding support for pre-releases and semantic versioning (PowerShell Gallery)
  • Loading branch information
RamblingCookieMonster authored Jun 28, 2020
2 parents 5a48e16 + efe2c7b commit effcd8a
Show file tree
Hide file tree
Showing 6 changed files with 888 additions and 25 deletions.
55 changes: 44 additions & 11 deletions PSDepend/PSDependScripts/PSGalleryModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
.PARAMETER AllowClobber
Allow installation of modules that clobber existing commands. Defaults to $True
.PARAMETER AllowPrerelease
If specified, allow for prerelease. Defaults to $false
If specified along with version 'latest', a prerelease will be selected if it is the latest version
Sorting assumes you name prereleases appropriately (i.e. alpha < beta < gamma)
.PARAMETER Import
If specified, import the module in the global scope
Expand Down Expand Up @@ -70,6 +77,16 @@
# No version is specified - we assume latest in this case.
# * Perhaps you use this https://github.com/PowerShell/PSPrivateGallery, or Artifactory, ProGet, etc.
.EXAMPLE
@{
'vmware.powercli' = @{
Parameters = @{
AllowPrerelease = $True
}
}
}
# Install the latest version of PowerCLI, allowing for prerelease
#>
[cmdletbinding()]
param(
Expand All @@ -83,6 +100,8 @@ param(

[bool]$AllowClobber = $True,

[bool]$AllowPrerelease,

[switch]$Import,

[ValidateSet('Test', 'Install', 'Import')]
Expand Down Expand Up @@ -146,6 +165,7 @@ $params = @{
Name = $Name
SkipPublisherCheck = $SkipPublisherCheck
AllowClobber = $AllowClobber
AllowPrerelease = $AllowPrerelease
Verbose = $VerbosePreference
Force = $True
}
Expand All @@ -154,9 +174,9 @@ if($Repository) {
$params.Add('Repository',$Repository)
}

if( $Version -and $Version -ne 'latest')
if($Version -and $Version -ne 'latest')
{
$Params.add('RequiredVersion',$Version)
$Params.add('RequiredVersion', $Version)
}

if($Credential)
Expand Down Expand Up @@ -201,34 +221,47 @@ if($Existing)
$ExistingVersion = $Existing | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
$FindModuleParams = @{Name = $Name}
if($Repository) {
$FindModuleParams.Add('Repository',$Repository)
$FindModuleParams.Add('Repository', $Repository)
}
if($Credential)
{
$FindModuleParams.Add('Credential', $Credential)
}
if($AllowPrerelease)
{
$FindModuleParams.Add('AllowPrerelease', $AllowPrerelease)
}

$GetGalleryVersion = { Find-Module @FindModuleParams | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum }

# Version string, and equal to current
if( $Version -and $Version -ne 'latest' -and $Version -eq $ExistingVersion)
if($Version -and $Version -ne 'latest' -and $Version -eq $ExistingVersion)
{
Write-Verbose "You have the requested version [$Version] of [$Name]"
# Conditional import
Import-PSDependModule -Name $ModuleName -Action $PSDependAction -Version $ExistingVersion

if($PSDependAction -contains 'Test')
{
return $True
return $true
}
return $null
}

$GalleryVersion = Find-Module @FindModuleParams | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
[System.Version]$parsedVersion = $null
[System.Management.Automation.SemanticVersion]$parsedSemanticVersion = $null
[System.Management.Automation.SemanticVersion]$parsedTempSemanticVersion = $null
$isGalleryVersionLessEquals = if (
[System.Management.Automation.SemanticVersion]::TryParse($ExistingVersion, [ref]$parsedSemanticVersion) -and
[System.Management.Automation.SemanticVersion]::TryParse($GalleryVersion, [ref]$parsedTempSemanticVersion)
) {
$GalleryVersion -le $parsedSemanticVersion
}
elseif ([System.Version]::TryParse($ExistingVersion, [ref]$parsedVersion)) {
$GalleryVersion -le $parsedVersion
}

# latest, and we have latest
if( $Version -and
($Version -eq 'latest' -or $Version -like '') -and
[System.Version]($GalleryVersion = (& $GetGalleryVersion)) -le [System.Version]$ExistingVersion
)
if( $Version -and ($Version -eq 'latest' -or $Version -eq '') -and $isGalleryVersionLessEquals)
{
Write-Verbose "You have the latest version of [$Name], with installed version [$ExistingVersion] and PSGallery version [$GalleryVersion]"
# Conditional import
Expand Down
Loading

0 comments on commit effcd8a

Please sign in to comment.