Skip to content

Commit f8d0911

Browse files
authored
Invoke-Build Task Improvements (#50)
* Invoke-Build Task Fixes Fix: Incorporate new StageFiles features Fix: Prereqs as If conditionals Fix: Dependencies variable doesn't work because Invoke-Build tasks compile dependencies ahead of time. Throw an error instead with proper override guidance * Better build dependency comparison
1 parent d8810ac commit f8d0911

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

PowerShellBuild/IB.tasks.ps1

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Remove-Variable -Name PSBPreference -Scope Script -Force -ErrorAction Ignore
22
Set-Variable -Name PSBPreference -Option ReadOnly -Scope Script -Value (. ([IO.Path]::Combine($PSScriptRoot, 'build.properties.ps1')))
3+
$__DefaultBuildDependencies = $PSBPreference.Build.Dependencies
34

45
# Synopsis: Initialize build environment variables
56
task Init {
@@ -14,12 +15,14 @@ task Clean Init, {
1415
# Synopsis: Builds module based on source directory
1516
task StageFiles Clean, {
1617
$buildParams = @{
17-
Path = $PSBPreference.General.SrcRootDir
18-
ModuleName = $PSBPreference.General.ModuleName
19-
DestinationPath = $PSBPreference.Build.ModuleOutDir
20-
Exclude = $PSBPreference.Build.Exclude
21-
Compile = $PSBPreference.Build.CompileModule
22-
Culture = $PSBPreference.Help.DefaultLocale
18+
Path = $PSBPreference.General.SrcRootDir
19+
ModuleName = $PSBPreference.General.ModuleName
20+
DestinationPath = $PSBPreference.Build.ModuleOutDir
21+
Exclude = $PSBPreference.Build.Exclude
22+
Compile = $PSBPreference.Build.CompileModule
23+
CompileDirectories = $PSBPreference.Build.CompileDirectories
24+
CopyDirectories = $PSBPreference.Build.CopyDirectories
25+
Culture = $PSBPreference.Help.DefaultLocale
2326
}
2427

2528
if ($PSBPreference.Help.ConvertReadMeToAboutHelp) {
@@ -30,6 +33,7 @@ task StageFiles Clean, {
3033
}
3134
}
3235

36+
# only add these configuration values to the build parameters if they have been been set
3337
'CompileHeader', 'CompileFooter', 'CompileScriptHeader', 'CompileScriptFooter' | ForEach-Object {
3438
if ($PSBPreference.Build.Keys -contains $_) {
3539
$buildParams.$_ = $PSBPreference.Build.$_
@@ -39,8 +43,7 @@ task StageFiles Clean, {
3943
Build-PSBuildModule @buildParams
4044
}
4145

42-
# Synopsis: Builds module and generate help documentation
43-
Task Build $($PSBPreference.Build.Dependencies -join ", ")
46+
4447

4548
$analyzePreReqs = {
4649
$result = $true
@@ -56,7 +59,7 @@ $analyzePreReqs = {
5659
}
5760

5861
# Synopsis: Execute PSScriptAnalyzer tests
59-
task Analyze Build, {
62+
task Analyze -If (. $analyzePreReqs) Build,{
6063
$analyzeParams = @{
6164
Path = $PSBPreference.Build.ModuleOutDir
6265
SeverityThreshold = $PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel
@@ -83,25 +86,24 @@ $pesterPreReqs = {
8386
}
8487

8588
# Synopsis: Execute Pester tests
86-
task Pester Build -If $pesterPreReqs, {
89+
task Pester -If (. $pesterPreReqs) Build,{
8790
$pesterParams = @{
88-
Path = $PSBPreference.Test.RootDir
89-
ModuleName = $PSBPreference.General.ModuleName
90-
OutputPath = $PSBPreference.Test.OutputFile
91-
OutputFormat = $PSBPreference.Test.OutputFormat
92-
CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
93-
CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
94-
CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
91+
Path = $PSBPreference.Test.RootDir
92+
ModuleName = $PSBPreference.General.ModuleName
93+
ModuleManifest = Join-Path $PSBPreference.Build.ModuleOutDir "$($PSBPreference.General.ModuleName).psd1"
94+
OutputPath = $PSBPreference.Test.OutputFile
95+
OutputFormat = $PSBPreference.Test.OutputFormat
96+
CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
97+
CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
98+
CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
99+
CodeCoverageOutputFile = $PSBPreference.Test.CodeCoverage.OutputFile
100+
CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFormat
101+
ImportModule = $PSBPreference.Test.ImportModule
95102
}
96103
Test-PSBuildPester @pesterParams
97104
}
98105

99-
# Synopsis: Execute Pester and ScriptAnalyzer tests
100-
task Test Pester, Analyze, {
101-
}
102106

103-
# Synopsis: Builds help documentation
104-
task BuildHelp GenerateMarkdown, GenerateMAML, {}
105107

106108
$genMarkdownPreReqs = {
107109
$result = $true
@@ -113,7 +115,7 @@ $genMarkdownPreReqs = {
113115
}
114116

115117
# Synopsis: Generates PlatyPS markdown files from module help
116-
task GenerateMarkdown StageFiles, {
118+
task GenerateMarkdown -if ($genMarkdownPreReqs) StageFiles,{
117119
$buildMDParams = @{
118120
ModulePath = $PSBPreference.Build.ModuleOutDir
119121
ModuleName = $PSBPreference.General.ModuleName
@@ -133,7 +135,7 @@ $genHelpFilesPreReqs = {
133135
}
134136

135137
# Synopsis: Generates MAML-based help from PlatyPS markdown files
136-
task GenerateMAML GenerateMarkdown, {
138+
task GenerateMAML -if (. $genHelpFilesPreReqs) GenerateMarkdown, {
137139
Build-PSBuildMAMLHelp -Path $PSBPreference.Docs.RootDir -DestinationPath $PSBPreference.Build.ModuleOutDir
138140
}
139141

@@ -147,7 +149,7 @@ $genUpdatableHelpPreReqs = {
147149
}
148150

149151
# Synopsis: Create updatable help .cab file based on PlatyPS markdown help
150-
task GenerateUpdatableHelp BuildHelp, {
152+
task GenerateUpdatableHelp -if (. $genUpdatableHelpPreReqs) BuildHelp, {
151153
Build-PSBuildUpdatableHelp -DocsPath $PSBPreference.Docs.RootDir -OutputPath $PSBPreference.Help.UpdatableHelpOutDir
152154
}
153155

@@ -171,3 +173,22 @@ Task Publish Test, {
171173

172174
Publish-PSBuildModule @publishParams
173175
}
176+
177+
178+
#region Summary Tasks
179+
180+
# Synopsis: Builds help documentation
181+
task BuildHelp GenerateMarkdown,GenerateMAML
182+
183+
Task Build {
184+
if ([String]$PSBPreference.Build.Dependencies -ne [String]$__DefaultBuildDependencies) {
185+
throw [NotSupportedException]'You cannot use $PSBPreference.Build.Dependencies with Invoke-Build. Please instead redefine the build task or your default task to include your dependencies. Example: Task . Dependency1,Dependency2,Build,Test or Task Build Dependency1,Dependency2,StageFiles'
186+
}
187+
},StageFiles,BuildHelp
188+
189+
# Synopsis: Execute Pester and ScriptAnalyzer tests
190+
task Test Analyze,Pester
191+
192+
task . Build,Test
193+
194+
#endregion Summary Tasks

0 commit comments

Comments
 (0)