-
Notifications
You must be signed in to change notification settings - Fork 10
/
Build.ps1
110 lines (102 loc) · 2.97 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
107
108
109
110
#Requires -Version 5
[CmdletBinding(DefaultParameterSetName = 'Build')]
param (
[parameter(Position = 0, ParameterSetName = 'Build')]
[switch]$BuildModule,
[parameter(Position = 2, ParameterSetName = 'Build')]
[switch]$UploadPSGallery,
[parameter(Position = 3, ParameterSetName = 'Build')]
[switch]$InstallAndTestModule,
[parameter(Position = 4, ParameterSetName = 'Build')]
[version]$NewVersion,
[parameter(Position = 5, ParameterSetName = 'Build')]
[string]$ReleaseNotes,
[parameter(Position = 6, ParameterSetName = 'CBH')]
[switch]$InsertCBH
)
function PrerequisitesLoaded {
# Install required modules if missing
try {
if ((get-module InvokeBuild -ListAvailable) -eq $null) {
Write-Output "Attempting to install the InvokeBuild module..."
$null = Install-Module InvokeBuild -Scope:CurrentUser
}
if (get-module InvokeBuild -ListAvailable) {
Write-Output -NoNewLine "Importing InvokeBuild module"
Import-Module InvokeBuild -Force
Write-Output '...Loaded!'
return $true
}
else {
return $false
}
}
catch {
return $false
}
}
function CleanUp {
try {
Write-Output ''
Write-Output 'Attempting to clean up the session (loaded modules and such)...'
Invoke-Build -Task BuildSessionCleanup
Remove-Module InvokeBuild
}
catch {}
}
if (-not (PrerequisitesLoaded)) {
throw 'Unable to load InvokeBuild!'
}
switch ($psCmdlet.ParameterSetName) {
'CBH' {
if ($InsertCBH) {
try {
Invoke-Build -Task InsertMissingCBH
}
catch {
throw
}
}
CleanUp
}
'Build' {
if ($NewVersion -ne $null) {
try {
Invoke-Build -Task UpdateVersion -NewVersion $NewVersion -ReleaseNotes $ReleaseNotes
}
catch {
throw $_
}
}
# If no parameters were specified or the build action was manually specified then kick off a standard build
if (($psboundparameters.count -eq 0) -or ($BuildModule)) {
try {
Invoke-Build
}
catch {
Write-Output 'Build Failed with the following error:'
Write-Output $_
}
}
# Install and test the module?
if ($InstallAndTestModule) {
try {
Invoke-Build -Task InstallAndTestModule
}
catch {
Write-Output 'Install and test of module failed:'
Write-Output $_
}
}
# Upload to gallery?
if ($UploadPSGallery) {
try {
Invoke-Build -Task PublishPSGallery
}
catch {
throw 'Unable to upload project to the PowerShell Gallery!'
}
}
CleanUp
}
}