This repository has been archived by the owner on Apr 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
159 lines (151 loc) · 4.56 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#Requires -Version 5
[CmdletBinding(DefaultParameterSetName = 'Build')]
param (
[parameter(Position = 0, ParameterSetName = 'Build')]
[switch]$BuildModule,
[parameter(Position = 1,ParameterSetName = 'Build')]
[switch]$TestBuildAndInstallModule,
[parameter(Position = 2, ParameterSetName = 'UpdateRelease')]
[switch]$UpdateRelease,
[parameter(Position = 3, ParameterSetName = 'UpdateRelease')]
[version]$NewVersion,
[parameter(Position = 4, ParameterSetName = 'UpdateRelease')]
[string]$ReleaseNotes,
[parameter(Position = 5, ParameterSetName = 'UpdateRelease')]
[switch]$UploadPSGallery,
[parameter(Position = 6, ParameterSetName = 'CBH')]
[switch]$AddMissingCBH,
[parameter(Position = 7, ParameterSetName = 'Tests')]
[switch]$Test,
[parameter(Position = 8,ParameterSetName = 'Tests')]
[switch]$TestMetaOnly,
[parameter(Position = 9,ParameterSetName = 'Tests')]
[switch]$TestUnitOnly,
[parameter(Position = 10,ParameterSetName = 'Tests')]
[switch]$TestIntergrationOnly
)
function PrerequisitesLoaded {
# Install required modules if missing
try {
if ((get-module PSDepend -ListAvailable) -eq $null) {
Write-Host "Attempting to install the PSDepend module..." -NoNewLine
$null = Install-Module PSDepend -MinimumVersion 0.3.2 -MaximumVersion 0.3.2 -Scope:CurrentUser
Write-Host 'Installed!'
}
if (get-module PSDepend -ListAvailable) {
Write-Host "Importing PSDepend module..." -NoNewLine
Import-Module PSDepend -Force
Write-Host 'Loaded!'
Write-Host 'Installing dependencies...' -NoNewLine
Invoke-PSDepend -Path $(Join-Path $(Get-Location) 'Requirements.psd1') -Test
Invoke-PSDepend -Path $(Join-Path $(Get-Location) 'Requirements.psd1') -Force
Invoke-PSDepend -Path $(Join-Path $(Get-Location) 'Requirements.psd1') -Import -Force
Write-Host 'Installed!'
return $true
}
else {
return $false
}
}
catch {
return $false
}
}
function CleanUp {
try {
Write-Host ''
Write-Host '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) {
'Build' {
# 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-Host 'Build Failed with the following error:'
throw $_
}
}
# Test, Build Installd and test load the module
if ($TestBuildAndInstallModule) {
try {
Invoke-Build -Task TestBuildAndInstallModule
}
catch {
Write-Host 'Test, Build Installd and test load the module of the module failed:'
throw $_
}
}
}
'CBH' {
if ($AddMissingCBH) {
try {
Invoke-Build -Task AddMissingCBH
}
catch {
throw $_
}
}
}
'UpdateRelease' {
if ($UpdateRelease) {
try {
Invoke-Build -Task UpdateRelease -NewVersion $NewVersion -ReleaseNotes $ReleaseNotes
}
catch {
throw $_
}
}
if ($UploadPSGallery) {
try {
Invoke-Build -Task PublishPSGallery
}
catch {
throw 'Unable to upload project to the PowerShell Gallery!'
}
}
}
'Tests' {
if ($test) {
try {
Invoke-Build -Task tests
}
catch {
throw
}
}
if ($TestMetaOnly) {
try {
Invoke-Build -Task RunMetaTests
}
catch {
throw
}
}
if ($TestUnitOnly) {
try {
Invoke-Build -Task RunUnitTests
}
catch {
throw
}
}
if ($TestIntergrationOnly) {
try {
Invoke-Build -Task RunIntergrationTests
}
catch {
throw
}
}
}
}