Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI
on:
push:
branches: [ master ]
branches: [master]
paths:
- "PSDepend/**"
- "Tests/**"
Expand All @@ -18,15 +18,15 @@ on:
workflow_dispatch:

jobs:
test:
test_pwsh:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macOS-latest ]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v4
- name: Bootstrap
Expand All @@ -42,9 +42,30 @@ jobs:
name: testResults-${{ matrix.os }}
path: ./Tests/out/testResults.xml

test_ps51:
name: Test (Windows PowerShell 5.1)
runs-on: windows-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Bootstrap
shell: powershell
run: ./build.ps1 -Bootstrap -Task Init
- name: Test
shell: powershell
run: ./build.ps1 -Task Test
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: testResults-ps51
path: ./Tests/out/testResults.xml
publish-test-results:
name: Publish Test Results
needs: test
needs:
- test_pwsh
- test_ps51
runs-on: ubuntu-latest
permissions:
checks: write
Expand Down
2 changes: 1 addition & 1 deletion PSDepend/PSDependScripts/Noop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ param (

Write-Verbose "Starting noop run with $($Dependency.count) sources"

[pscustomobject]@{
[PSCustomObject]@{
PSBoundParameters = $PSBoundParameters
Dependency= $Dependency
DependencyParameters = $Dependency.Parameters
Expand Down
143 changes: 63 additions & 80 deletions PSDepend/PSDependScripts/PSGalleryModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,44 +114,48 @@ param(
)

# Extract data from Dependency
$DependencyName = $Dependency.DependencyName
$Name = $Dependency.Name
if(-not $Name)
{
$Name = $DependencyName
}
$DependencyName = $Dependency.DependencyName
$Name = $Dependency.Name
if(-not $Name) {
$Name = $DependencyName
}

$Version = $Dependency.Version
if(-not $Version)
{
$Version = 'latest'
}
$Version = $Dependency.Version
if(-not $Version) {
$Version = 'latest'
}

# We use target as a proxy for Scope
if(-not $Dependency.Target)
{
$Scope = 'AllUsers'
}
else
{
$Scope = $Dependency.Target
}
# We use target as a proxy for Scope
if(-not $Dependency.Target) {
$Scope = 'AllUsers'
} else {
$Scope = $Dependency.Target
}

$Credential = $Dependency.Credential
$Credential = $Dependency.Credential

if('AllUsers', 'CurrentUser' -notcontains $Scope)
{
$command = 'save'
}
else
{
$command = 'install'
if('AllUsers', 'CurrentUser' -notcontains $Scope) {
$command = 'save'
} else {
$command = 'install'
}

$nugetProvider = @(Get-PackageProvider -ErrorAction SilentlyContinue) |
Where-Object { $_.Name -eq 'NuGet' } |
Select-Object -First 1

if(-not $nugetProvider) {
Write-Debug 'NuGet provider not found. Attempting to install NuGet provider.'
# Bootstrap NuGet provider for Windows PowerShell 5.1 and PowerShell 7+.
$installPackageProviderSplat = @{
Name = 'NuGet'
ForceBootstrap = $true
Force = $true
Scope = 'CurrentUser'
ErrorAction = 'SilentlyContinue'
}

if(-not (Get-PackageProvider -Name Nuget))
{
# Grab nuget bits.
$null = Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
$null = Install-PackageProvider @installPackageProviderSplat
}

Write-Verbose -Message "Getting dependency [$name] from PowerShell repository [$Repository]"
Expand All @@ -160,10 +164,10 @@ Write-Verbose -Message "Getting dependency [$name] from PowerShell repository [$
# but allow to rely on all PS repos registered.
if($Repository) {
$validRepo = Get-PSRepository -Name $Repository -Verbose:$false -ErrorAction SilentlyContinue
if (-not $validRepo) {
Write-Error "[$Repository] has not been setup as a valid PowerShell repository."
return
}
if (-not $validRepo) {
Write-Error "[$Repository] has not been setup as a valid PowerShell repository."
return
}
}

$params = @{
Expand All @@ -174,47 +178,40 @@ $params = @{
Force = $True
}

if($PSBoundParameters.ContainsKey('AllowPrerelease')){
if($PSBoundParameters.ContainsKey('AllowPrerelease')) {
$params.Add('AllowPrerelease', $AllowPrerelease)
}

if($PSBoundParameters.ContainsKey('AcceptLicense')){
if($PSBoundParameters.ContainsKey('AcceptLicense')) {
$params.Add('AcceptLicense', $AcceptLicense)
}

if($Repository) {
$params.Add('Repository',$Repository)
}

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

if($Credential)
{
$Params.add('Credential', $Credential)
if($Credential) {
$Params.add('Credential', $Credential)
}

# This code works for both install and save scenarios.
if($command -eq 'Save')
{
if($command -eq 'Save') {
$ModuleName = Join-Path $Scope $Name
$Params.Remove('AllowClobber')
$Params.Remove('SkipPublisherCheck')
}
elseif ($Command -eq 'Install')
{
} elseif ($Command -eq 'Install') {
$ModuleName = $Name
}

# Only use "SkipPublisherCheck" (and other) parameter if "Install-Module" supports it
$availableParameters = (Get-Command "Install-Module").Parameters
$tempParams = $Params.Clone()
foreach($thisParameter in $Params.Keys)
{
if(-Not ($availableParameters.ContainsKey($thisParameter)))
{
foreach($thisParameter in $Params.Keys) {
if(-not ($availableParameters.ContainsKey($thisParameter))) {
Write-Verbose -Message "Removing parameter [$thisParameter] from [Install-Module] as it is not available"
$tempParams.Remove($thisParameter)
}
Expand All @@ -226,33 +223,28 @@ Add-ToPsModulePathIfRequired -Dependency $Dependency -Action $PSDependAction
$Existing = $null
$Existing = Get-Module -ListAvailable -Name $ModuleName -ErrorAction SilentlyContinue

if($Existing)
{
if($Existing) {
Write-Verbose "Found existing module [$Name]"
# Thanks to Brandon Padgett!
$ExistingVersion = $Existing | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
$FindModuleParams = @{Name = $Name}
$FindModuleParams = @{Name = $Name }
if($Repository) {
$FindModuleParams.Add('Repository', $Repository)
}
if($Credential)
{
if($Credential) {
$FindModuleParams.Add('Credential', $Credential)
}
if($AllowPrerelease)
{
if($AllowPrerelease) {
$FindModuleParams.Add('AllowPrerelease', $AllowPrerelease)
}

# 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')
{
if($PSDependAction -contains 'Test') {
return $true
}
return $null
Expand All @@ -267,20 +259,17 @@ if($Existing)
[System.Management.Automation.SemanticVersion]::TryParse($GalleryVersion, [ref]$parsedTempSemanticVersion)
) {
$GalleryVersion -le $parsedSemanticVersion
}
elseif ([System.Version]::TryParse($ExistingVersion, [ref]$parsedVersion)) {
} elseif ([System.Version]::TryParse($ExistingVersion, [ref]$parsedVersion)) {
$GalleryVersion -le $parsedVersion
}

# latest, and we have latest
if( $Version -and ($Version -eq 'latest' -or $Version -eq '') -and $isGalleryVersionLessEquals)
{
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
Import-PSDependModule -Name $ModuleName -Action $PSDependAction -Version $ExistingVersion

if($PSDependAction -contains 'Test')
{
if($PSDependAction -contains 'Test') {
return $True
}
return $null
Expand All @@ -289,24 +278,18 @@ if($Existing)
}

#No dependency found, return false if we're testing alone...
if( $PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1)
{
if( $PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
return $False
}

if($PSDependAction -contains 'Install')
{
if('AllUsers', 'CurrentUser' -contains $Scope)
{
if($PSDependAction -contains 'Install') {
if('AllUsers', 'CurrentUser' -contains $Scope) {
Write-Verbose "Installing [$Name] with scope [$Scope]"
Install-Module @params -Scope $Scope
}
else
{
} else {
Write-Verbose "Saving [$Name] with path [$Scope]"
Write-Verbose "Creating directory path to [$Scope]"
if(-not (Test-Path $Scope -ErrorAction SilentlyContinue))
{
if(-not (Test-Path $Scope -ErrorAction SilentlyContinue)) {
$Null = New-Item -ItemType Directory -Path $Scope -Force -ErrorAction SilentlyContinue
}
Save-Module @params -Path $Scope
Expand Down
2 changes: 1 addition & 1 deletion PSDepend/Private/Get-ProjectDetail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Get-ProjectDetail {
$RelativePath = '\',
$Name
)
[pscustomobject]@{
[PSCustomObject]@{
Name = $Name
Path = Resolve-Path (Join-Path $Path $RelativePath)
}
Expand Down
4 changes: 2 additions & 2 deletions PSDepend/Private/SemanticVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,6 @@ namespace System.Management.Automation
}
'@

if ($PSVersionTable.PSVersion.Major -lt 6) {
Add-Type -TypeDefinition $code
if ($PSVersionTable.PSVersion.Major -lt 6 -and -not ('System.Management.Automation.SemanticVersion' -as [type])) {
Add-Type -TypeDefinition $code
}
10 changes: 5 additions & 5 deletions PSDepend/Public/Get-Dependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function Get-Dependency {
$Dependency -match '::' -and
($Dependency -split '::').count -eq 2
) {
[pscustomobject]@{
[PSCustomObject]@{
PSTypeName = 'PSDepend.Dependency'
DependencyFile = $DependencyFile
DependencyName = ($Dependency -split '::')[1]
Expand All @@ -260,7 +260,7 @@ function Get-Dependency {
$Dependency -notmatch '/' -and
-not $DependencyType -or
$DependencyType -eq 'PSGalleryModule') {
[pscustomobject]@{
[PSCustomObject]@{
PSTypeName = 'PSDepend.Dependency'
DependencyFile = $DependencyFile
DependencyName = $Dependency
Expand All @@ -286,7 +286,7 @@ function Get-Dependency {
$Dependency.split('/').count -eq 2 -and
-not $DependencyType -or
$DependencyType -eq 'GitHub') {
[pscustomobject]@{
[PSCustomObject]@{
PSTypeName = 'PSDepend.Dependency'
DependencyFile = $DependencyFile
DependencyName = $Dependency
Expand All @@ -310,7 +310,7 @@ function Get-Dependency {
$Dependency -match '/' -and
-not $DependencyType -or
$DependencyType -eq 'Git' ) {
[pscustomobject]@{
[PSCustomObject]@{
PSTypeName = 'PSDepend.Dependency'
DependencyFile = $DependencyFile
DependencyName = $Dependency
Expand Down Expand Up @@ -362,7 +362,7 @@ function Get-Dependency {
}

$CredentialName = Get-GlobalOption -Name Credential -Prefer $DependencyHash.Credential
[pscustomobject]@{
[PSCustomObject]@{
PSTypeName = 'PSDepend.Dependency'
DependencyFile = $DependencyFile
DependencyName = $Dependency
Expand Down
2 changes: 1 addition & 1 deletion PSDepend/Public/Get-PSDependType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Function Get-PSDependType {
else
{
$Support = @($DependencyDefinitions.$Type.Supports)
[pscustomobject]@{
[PSCustomObject]@{
DependencyType = $Type
Supports = $Support
Supported = Test-PlatformSupport -Type $Type -Support $Support
Expand Down
Loading
Loading