33param (
44 [parameter (Position = 0 , ParameterSetName = ' Build' )]
55 [switch ]$BuildModule ,
6- [parameter (Position = 2 , ParameterSetName = ' Build' )]
7- [switch ]$UploadPSGallery ,
8- [parameter (Position = 3 , ParameterSetName = ' Build ' )]
9- [switch ]$InstallAndTestModule ,
10- [parameter (Position = 4 , ParameterSetName = ' Build ' )]
6+ [parameter (Position = 1 , ParameterSetName = ' Build' )]
7+ [switch ]$TestBuildAndInstallModule ,
8+ [parameter (Position = 2 , ParameterSetName = ' UpdateRelease ' )]
9+ [switch ]$UpdateRelease ,
10+ [parameter (Position = 3 , ParameterSetName = ' UpdateRelease ' )]
1111 [version ]$NewVersion ,
12- [parameter (Position = 5 , ParameterSetName = ' Build ' )]
12+ [parameter (Position = 4 , ParameterSetName = ' UpdateRelease ' )]
1313 [string ]$ReleaseNotes ,
14+ [parameter (Position = 5 , ParameterSetName = ' UpdateRelease' )]
15+ [switch ]$UploadPSGallery ,
1416 [parameter (Position = 6 , ParameterSetName = ' CBH' )]
15- [switch ]$AddCBH
17+ [switch ]$AddMissingCBH ,
18+ [parameter (Position = 7 , ParameterSetName = ' Tests' )]
19+ [switch ]$Test ,
20+ [parameter (Position = 8 , ParameterSetName = ' Tests' )]
21+ [switch ]$TestMetaOnly ,
22+ [parameter (Position = 9 , ParameterSetName = ' Tests' )]
23+ [switch ]$TestUnitOnly ,
24+ [parameter (Position = 10 , ParameterSetName = ' Tests' )]
25+ [switch ]$TestIntergrationOnly
1626)
1727
1828function PrerequisitesLoaded {
1929 # Install required modules if missing
2030 try {
21- if ((get-module InvokeBuild - ListAvailable) -eq $null ) {
22- Write-Output " Attempting to install the InvokeBuild module..."
23- $null = Install-Module InvokeBuild - Scope:CurrentUser
31+ if ((get-module PSDepend - ListAvailable) -eq $null ) {
32+ Write-Host " Attempting to install the PSDepend module..." - NoNewLine
33+ $null = Install-Module PSDepend - MinimumVersion 0.3 .2 - MaximumVersion 0.3 .2 - Scope:CurrentUser
34+ Write-Host ' Installed!'
2435 }
25- if (get-module InvokeBuild - ListAvailable) {
26- Write-Output - NoNewLine " Importing InvokeBuild module"
27- Import-Module InvokeBuild - Force
28- Write-Output ' ...Loaded!'
36+ if (get-module PSDepend - ListAvailable) {
37+ Write-Host " Importing PSDepend module..." - NoNewLine
38+ Import-Module PSDepend - Force
39+ Write-Host ' Loaded!'
40+
41+ Write-Host ' Installing dependencies...' - NoNewLine
42+ Invoke-PSDepend - Path $ (Join-Path $ (Get-Location ) ' Requirements.psd1' ) - Test
43+ Invoke-PSDepend - Path $ (Join-Path $ (Get-Location ) ' Requirements.psd1' ) - Force
44+ Invoke-PSDepend - Path $ (Join-Path $ (Get-Location ) ' Requirements.psd1' ) - Import - Force
45+ Write-Host ' Installed!'
2946 return $true
3047 }
3148 else {
@@ -39,8 +56,8 @@ function PrerequisitesLoaded {
3956
4057function CleanUp {
4158 try {
42- Write-Output ' '
43- Write-Output ' Attempting to clean up the session (loaded modules and such)...'
59+ Write-Host ' '
60+ Write-Host ' Attempting to clean up the session (loaded modules and such)...'
4461 Invoke-Build - Task BuildSessionCleanup
4562 Remove-Module InvokeBuild
4663 }
@@ -52,50 +69,49 @@ if (-not (PrerequisitesLoaded)) {
5269}
5370
5471switch ($psCmdlet.ParameterSetName ) {
55- ' CBH' {
56- if ($AddCBH ) {
72+ ' Build' {
73+ # If no parameters were specified or the build action was manually specified then kick off a standard build
74+ if (($psboundparameters.count -eq 0 ) -or ($BuildModule )) {
5775 try {
58- Invoke-Build - Task AddMissingCBH
76+ Invoke-Build
5977 }
6078 catch {
61- throw
79+ Write-Host ' Build Failed with the following error:'
80+ throw $_
6281 }
6382 }
6483
65- CleanUp
66- }
67- ' Build' {
68- if ($NewVersion -ne $null ) {
84+ # Test, Build Installd and test load the module
85+ if ($TestBuildAndInstallModule ) {
6986 try {
70- Invoke-Build - Task UpdateVersion - NewVersion $NewVersion - ReleaseNotes $ReleaseNotes
87+ Invoke-Build - Task TestBuildAndInstallModule
7188 }
7289 catch {
90+ Write-Host ' Test, Build Installd and test load the module of the module failed:'
7391 throw $_
7492 }
7593 }
76- # If no parameters were specified or the build action was manually specified then kick off a standard build
77- if (($psboundparameters.count -eq 0 ) -or ($BuildModule )) {
94+ }
95+ ' CBH' {
96+ if ($AddMissingCBH ) {
7897 try {
79- Invoke-Build
98+ Invoke-Build - Task AddMissingCBH
8099 }
81100 catch {
82- Write-Output ' Build Failed with the following error:'
83- Write-Output $_
101+ throw $_
84102 }
85103 }
86-
87- # Install and test the module?
88- if ($InstallAndTestModule ) {
104+ }
105+ ' UpdateRelease ' {
106+ if ($UpdateRelease -ne $null ) {
89107 try {
90- Invoke-Build - Task InstallAndTestModule
108+ Invoke-Build - Task UpdateRelease - NewVersion $NewVersion - ReleaseNotes $ReleaseNotes
91109 }
92110 catch {
93- Write-Output ' Install and test of module failed:'
94- Write-Output $_
111+ throw $_
95112 }
96113 }
97114
98- # Upload to gallery?
99115 if ($UploadPSGallery ) {
100116 try {
101117 Invoke-Build - Task PublishPSGallery
@@ -104,7 +120,41 @@ switch ($psCmdlet.ParameterSetName) {
104120 throw ' Unable to upload project to the PowerShell Gallery!'
105121 }
106122 }
107-
108- CleanUp
109123 }
110- }
124+ ' Tests' {
125+ if ($test ) {
126+ try {
127+ Invoke-Build - Task tests
128+ }
129+ catch {
130+ throw
131+ }
132+ }
133+ if ($TestMetaOnly ) {
134+ try {
135+ Invoke-Build - Task RunMetaTests
136+ }
137+ catch {
138+ throw
139+ }
140+ }
141+ if ($TestUnitOnly ) {
142+ try {
143+ Invoke-Build - Task RunUnitTests
144+ }
145+ catch {
146+ throw
147+ }
148+ }
149+ if ($TestIntergrationOnly ) {
150+ try {
151+ Invoke-Build - Task RunIntergrationTests
152+ }
153+ catch {
154+ throw
155+ }
156+ }
157+ }
158+ }
159+
160+
0 commit comments