Skip to content

Commit 34d68bd

Browse files
Joel BennettJaykul
authored andcommitted
Try a PSDepend-free bootstrap
1 parent a5f2785 commit 34d68bd

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

RequiredModules.psd1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@(
2+
@{ ModuleName = "Configuration"; RequiredVersion = "1.3.1"}
3+
@{ ModuleName = "Pester"; RequiredVersion = "4.4.0"}
4+
<# etc #>
5+
)

bootstrap.ps1

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
1+
using namespace Microsoft.PowerShell.Commands
12
[CmdletBinding()]
23
param(
34
#
4-
[ValidateSet("CurrentUser", "AllUsers", "LocalTools")]
5+
[ValidateSet("CurrentUser", "AllUsers")]
56
$Scope = "CurrentUser"
67
)
8+
[ModuleSpecification[]]$RequiredModules = Import-LocalizedData -BaseDirectory $PSScriptRoot -FileName RequiredModules
9+
$Policy = (Get-PSRepository PSGallery).InstallationPolicy
10+
Set-PSRepository PSGallery -InstallationPolicy Trusted
711

8-
Push-Location $PSScriptRoot -StackName bootstrap-stack
9-
10-
# # This would probably work, if the default gallery was trusted ...
11-
# Install-Module Pester -RequiredVersion 4.4.0 -Scope CurrentUser -Repository PSGallery -SkipPublisherCheck
12-
# Install-Module Configuration -RequiredVersion 1.3.1 -Scope CurrentUser -Repository PSGallery -SkipPublisherCheck
13-
if (!(Get-Module PSDepend -ListAvailable)) {
14-
$Policy = (Get-PSRepository PSGallery).InstallationPolicy
15-
try {
16-
Set-PSRepository PSGallery -InstallationPolicy Trusted
17-
18-
if ($Scope -eq "LocalTools") {
19-
$Target = Join-Path $PSScriptRoot "Tools"
20-
New-Item -Path $Target -ItemType Directory -Force
21-
22-
$Env:PSModulePath += ';' + $Target
23-
$PSDefaultParameterValues["Invoke-PSDepend:Target"] = $Target
24-
Save-Module PSDepend -Repository PSGallery -ErrorAction Stop -Path $Target
25-
} else {
26-
$PSDefaultParameterValues["Invoke-PSDepend:Target"] = $Scope
27-
Install-Module PSDepend -Repository PSGallery -ErrorAction Stop -Scope:$Scope
28-
}
29-
} finally {
30-
# Make sure we didn't change anything permanently
31-
Set-PSRepository PSGallery -InstallationPolicy:$Policy
32-
Pop-Location -StackName bootstrap-stack
33-
}
34-
}
35-
36-
try {
37-
Write-Verbose "Updating dependencies"
38-
Import-Module PSDepend -ErrorAction Stop
39-
Invoke-PSDepend -Import -Force -ErrorAction Stop -Verbose
40-
} catch {
41-
Write-Warning "Unable to restore dependencies. Please review errors:"
42-
throw
43-
}
12+
$RequiredModules | Install-Module -Scope $Scope -Repository PSGallery -SkipPublisherCheck -Verbose
13+
$RequiredModules | Import-Module

0 commit comments

Comments
 (0)