-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathbuild.ps1
More file actions
121 lines (109 loc) · 3.92 KB
/
Copy pathbuild.ps1
File metadata and controls
121 lines (109 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter',
'Command',
Justification = 'false positive'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter',
'Parameter',
Justification = 'false positive'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter',
'CommandAst',
Justification = 'false positive'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter',
'FakeBoundParams',
Justification = 'false positive'
)]
[CmdletBinding(DefaultParameterSetName = 'task')]
param(
[parameter(ParameterSetName = 'task', Position = 0)]
[ArgumentCompleter( {
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
try {
Get-PSakeScriptTasks -BuildFile './psakeFile.ps1' -ErrorAction 'Stop' |
Where-Object { $_.Name -like "$WordToComplete*" } |
Select-Object -ExpandProperty 'Name'
} catch {
@()
}
})]
[string[]]$Task = 'default',
[switch]$Bootstrap,
[parameter(ParameterSetName = 'Help')]
[switch]$Help
)
$ErrorActionPreference = 'Stop'
$psakeFile = './psakeFile.ps1'
if ($Bootstrap) {
# Patch TLS protocols for older Windows versions
[System.Net.ServicePointManager]::SecurityProtocol = (
[System.Net.ServicePointManager]::SecurityProtocol -bor
[System.Net.SecurityProtocolType]::Tls12 -bor
[System.Net.SecurityProtocolType]::Tls13
)
Get-PackageProvider -Name 'Nuget' -ForceBootstrap | Out-Null
Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted'
# Pin PowerShellGet to v2
$powerShellGetModule = Get-Module -Name 'PowerShellGet' -ListAvailable |
Where-Object { $_.Version.Major -eq 2 } |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1
$powerShellGetModuleParameters = @{
Name = 'PowerShellGet'
MinimumVersion = '2.0.0'
MaximumVersion = '2.99.99'
Force = $true
}
if (-not $powerShellGetModule) {
Install-Module @powerShellGetModuleParameters -Scope 'CurrentUser' -AllowClobber
}
Import-Module @powerShellGetModuleParameters
# Install PSDepend if missing
if (-not (Get-Module -Name 'PSDepend' -ListAvailable)) {
Install-Module -Name 'PSDepend' -Repository 'PSGallery' -Scope 'CurrentUser' -Force
}
# Try-import-first pattern
$psDependParameters = @{
Path = $PSScriptRoot
Recurse = $False
WarningAction = 'SilentlyContinue'
Import = $True
Force = $True
ErrorAction = 'Stop'
}
$psDependTestParameters = $psDependParameters.Clone()
$null = $psDependTestParameters.Remove('Import')
$psDependTestParameters['Test'] = $true
$psDependTestParameters['Quiet'] = $true
if (-not (Invoke-PSDepend @psDependTestParameters)) {
$psDependInstallParameters = $psDependParameters.Clone()
$null = $psDependInstallParameters.Remove('Import')
Invoke-PSDepend @psDependInstallParameters -Install
}
Invoke-PSDepend @psDependParameters
} else {
if (-not (Get-Module -Name 'PSDepend' -ListAvailable)) {
throw 'Missing dependencies. Please run with the "-Bootstrap" flag to install dependencies.'
}
Invoke-PSDepend -Path $PSScriptRoot -Recurse $False -WarningAction 'SilentlyContinue' -Import -Force
}
if ($PSCmdlet.ParameterSetName -eq 'Help') {
Get-PSakeScriptTasks -BuildFile $psakeFile |
Format-Table -Property Name, Description, Alias, DependsOn
} else {
Set-BuildEnvironment -Force
$invokepsakeSplat = @{
BuildFile = $psakeFile
TaskList = $Task
NoLogo = $true
}
if ($Env:GITHUB_ACTIONS) {
$invokepsakeSplat['OutputFormat'] = 'GitHubActions'
}
Invoke-Psake @invokepsakeSplat
exit ([int](-not $psake.build_success))
}