-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
107 lines (90 loc) · 4.07 KB
/
build.ps1
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
[CmdletBinding(DefaultParameterSetName = 'Default')]
Param (
[Parameter()]
$Task = 'Default',
[Parameter(Mandatory, ParameterSetName = 'Coverage')]
[switch]$Coverage,
[Parameter(ParameterSetName = 'Coverage')]
[double]$MinimumCoverage = 70,
[Parameter()]
[switch]$Help
)
DynamicParam {
# Adapted from https://github.com/nightroman/Invoke-Build/blob/master/Invoke-Build.ArgumentCompleters.ps1
Register-ArgumentCompleter -CommandName build.ps1 -ParameterName Task -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $boundParameters)
$tasks = (Invoke-Build -Task ?? -File "$PSScriptRoot\build_tools\module.build.ps1").get_Keys()
$tasks -like "$wordToComplete*" | . {
process {
New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', $_
}
}
}
}
process {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ModuleName = (Get-Item -Path $PSScriptRoot).BaseName
# Writing out the current script parameters for troubleshooting logs
$params = @{}
foreach($h in $MyInvocation.MyCommand.Parameters.GetEnumerator()) {
if (
($PSCmdlet.ParameterSetName -in $h.Value.ParameterSets.Keys) -or
('__AllParameterSets' -in $h.Value.ParameterSets.Keys)
) {
try {
$key = $h.Key
$val = Get-Variable -Name $key -ErrorAction Stop | Select-Object -ExpandProperty Value -ErrorAction Stop
if (([String]::IsNullOrEmpty($val) -and (-not $PSBoundParameters.ContainsKey($key)))) {
throw "A blank value that wasn't supplied by the user."
}
$params[$key] = $val
} catch {}
}
}
if ($params.Keys) {
Write-Output "Build Parameters:`n$($params | Out-String)"
}
$buildFile = "$PSScriptRoot\build_tools\module.build.ps1"
$buildDependencies = Import-PowerShellDataFile -Path $PSScriptRoot\build_tools\build.Depend.psd1
$PSDependVersion = $buildDependencies.PSDepend
$InvokeBuildVersion = $buildDependencies.InvokeBuild.Version
Write-Output 'Installing/Importing Build-Dependent Modules'
if (-not (Get-Module -Name 'PSDepend' -ListAvailable | Where-Object { $PSDependVersion -in $_.Version })) {
Write-Output ' PSDepend module required: Installing...'
Install-Module -Name 'PSDepend' -Repository PSGallery -RequiredVersion $PSDependVersion -Force -Scope 'CurrentUser'
}
Import-Module -Name 'PSDepend' -RequiredVersion $PSDependVersion
if (-not (Get-Module -Name 'InvokeBuild' -ListAvailable | Where-Object { $InvokeBuildVersion -in $_.Version })) {
Write-Output ' InvokeBuild module required: Installing...'
Install-Module -Name 'InvokeBuild' -Repository PSGallery -RequiredVersion $InvokeBuildVersion -Force -Scope 'CurrentUser'
}
Import-Module -Name 'InvokeBuild' -RequiredVersion $InvokeBuildVersion
if ($Help) {
Invoke-Build -File $buildFile -Task ?
} else {
$invokePSDependParams = @{
Path = "$PSScriptRoot\build_tools\build.Depend.psd1"
Tags = 'Build'
Install = $true
Import = $true
Force = $true
WarningAction = 'SilentlyContinue'
Verbose = $VerbosePreference
}
Invoke-PSDepend @invokePSDependParams
if (-not (Get-PackageProvider -Name 'NuGet')) {
Write-Output ' Installing Nuget package provider...'
Install-PackageProvider -Name 'NuGet' -Force -Confirm:$false | Out-Null
}
Write-Output "Starting build of $ModuleName"
$InvokeBuildParams = @{
File = $buildFile
Task = $Task
ModuleName = $ModuleName
Coverage = $Coverage
MinimumCoverage = $MinimumCoverage
Verbose = $VerbosePreference
}
Invoke-Build @InvokeBuildParams
}
}