Skip to content
Merged
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
60 changes: 56 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[cmdletbinding(DefaultParameterSetName = 'Task')]

Check warning on line 1 in build.ps1

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (cmdletbinding)
param(
# Build task(s) to execute
[parameter(ParameterSetName = 'task', position = 0)]
Expand Down Expand Up @@ -49,11 +49,63 @@
Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
if ((Test-Path -Path ./requirements.psd1)) {
if (-not (Get-Module -Name PSDepend -ListAvailable)) {
Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force
$requirements = Import-PowerShellDataFile -Path ./requirements.psd1

$psDependVersion = $requirements.PSDepend.Version
$psDependPrerelease = ($psDependVersion -split '-', 2)[1]
$matchPSDepend = {
Get-Module -Name PSDepend -ListAvailable | Where-Object {
$candidateVersion = "$($_.Version)"
if ($_.PrivateData.PSData.Prerelease) { $candidateVersion += "-$($_.PrivateData.PSData.Prerelease)" }
$candidateVersion -eq $psDependVersion
} | Select-Object -First 1
}
$psDependModule = & $matchPSDepend
if (-not $psDependModule) {
$psDependInstallParams = @{ RequiredVersion = $psDependVersion }
if ($psDependPrerelease) { $psDependInstallParams.AllowPrerelease = $true }
Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force @psDependInstallParams
$psDependModule = & $matchPSDepend
}
# Import by the matched module's own manifest path, not just its numeric base version:
# -RequiredVersion drops the prerelease label, so if a differently-labeled (or stable)
# module sharing that same numeric version ever appears earlier on $env:PSModulePath,
# Import-Module could resolve to that one instead of the prerelease actually pinned.
Import-Module -Name $psDependModule.Path -Verbose:$false

# PowerShellBuild (installed below via requirements.psd1) declares `Pester >= 5.6.1` as
# its own RequiredModules dependency, with no upper bound. Install-Module always
# auto-resolves a target's RequiredModules, independently of whatever this repo's own
# `Pester` entry pins - and if our pin isn't on disk yet when PowerShellBuild gets
# installed, PowerShellGet fetches whatever's newest on PSGallery as a second, stray
# copy. PowerShellBuild's bundled Test task later calls `Import-Module Pester
# -MinimumVersion 5.0.0` (no exact pin), which always resolves to the HIGHEST matching
# version found on $env:PSModulePath - not whatever's already loaded - so that stray
# copy collides with the Pester.dll our own pinned import already loaded in-process.
# Installing (and importing) our pin first means PowerShellGet already finds it
# satisfying PowerShellBuild's constraint and never reaches for anything else.
$pesterVersion = $requirements.Pester.Version
if (-not (Get-Module -Name Pester -ListAvailable | Where-Object Version -eq [version]$pesterVersion)) {
Install-Module -Name Pester -RequiredVersion $pesterVersion -Scope CurrentUser -Force -SkipPublisherCheck
}
Import-Module -Name PSDepend -Verbose:$false
Invoke-PSDepend -Path './requirements.psd1' -Install -Import -Force -WarningAction SilentlyContinue
Import-Module -Name Pester -RequiredVersion $pesterVersion -Global -Force -Verbose:$false

# Invoke-PSDepend's own PSGalleryModule handler compares an installed module's
# $_.Version.ToString() (which drops any prerelease label) against the full
# 'X.Y.Z-prerelease' requirement string above, so it never recognizes our pin as already
# satisfied and would redundantly re-query/reinstall PSDepend from the gallery on every
# single bootstrap run. We've already installed and imported the exact pinned version
# above, so hand Invoke-PSDepend every *other* declared dependency instead of
# reprocessing this self-referential entry.
$otherDependencies = $requirements.Clone()
$otherDependencies.Remove('PSDepend')
Invoke-PSDepend -InputObject $otherDependencies -Install -Import -Force -WarningAction SilentlyContinue

# Defense in depth: prune any stray Pester version that still slipped onto disk (e.g. a
# concurrent PSDepend install) and reassert our pin at global scope.
Get-Module -Name Pester -ListAvailable | Where-Object { $_.Version -ne [version]$pesterVersion } |
ForEach-Object { Remove-Item -LiteralPath $_.ModuleBase -Recurse -Force -ErrorAction SilentlyContinue }
Import-Module -Name Pester -RequiredVersion $pesterVersion -Global -Force -Verbose:$false
} else {
Write-Warning 'No [requirements.psd1] found. Skipping build dependency installation.'
}
Expand All @@ -70,7 +122,7 @@
$psakeParams = @{
buildFile = $psakeFile
taskList = $Task
nologo = $true

Check warning on line 125 in build.ps1

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (nologo) Suggestions: (nolo, nolock, nonego, neology, onload)
properties = $Properties
parameters = $Parameters
}
Expand Down
5 changes: 4 additions & 1 deletion requirements.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@{
PSDepend = @{
Version = '0.4.1'
Version = '0.7.0-beta1'
Comment thread
HeyItsGilbert marked this conversation as resolved.
Resolved
Parameters = @{
AllowPrerelease = $true
Comment thread
HeyItsGilbert marked this conversation as resolved.
Resolved
}
}
PSDependOptions = @{
Target = 'CurrentUser'
Expand Down
Loading