Skip to content

Invoke-Build Task Improvements #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions PowerShellBuild/IB.tasks.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Remove-Variable -Name PSBPreference -Scope Script -Force -ErrorAction Ignore
Set-Variable -Name PSBPreference -Option ReadOnly -Scope Script -Value (. ([IO.Path]::Combine($PSScriptRoot, 'build.properties.ps1')))
$__DefaultBuildDependencies = $PSBPreference.Build.Dependencies

# Synopsis: Initialize build environment variables
task Init {
Expand All @@ -14,12 +15,14 @@ task Clean Init, {
# Synopsis: Builds module based on source directory
task StageFiles Clean, {
$buildParams = @{
Path = $PSBPreference.General.SrcRootDir
ModuleName = $PSBPreference.General.ModuleName
DestinationPath = $PSBPreference.Build.ModuleOutDir
Exclude = $PSBPreference.Build.Exclude
Compile = $PSBPreference.Build.CompileModule
Culture = $PSBPreference.Help.DefaultLocale
Path = $PSBPreference.General.SrcRootDir
ModuleName = $PSBPreference.General.ModuleName
DestinationPath = $PSBPreference.Build.ModuleOutDir
Exclude = $PSBPreference.Build.Exclude
Compile = $PSBPreference.Build.CompileModule
CompileDirectories = $PSBPreference.Build.CompileDirectories
CopyDirectories = $PSBPreference.Build.CopyDirectories
Culture = $PSBPreference.Help.DefaultLocale
}

if ($PSBPreference.Help.ConvertReadMeToAboutHelp) {
Expand All @@ -30,6 +33,7 @@ task StageFiles Clean, {
}
}

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

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


$analyzePreReqs = {
$result = $true
Expand All @@ -56,7 +59,7 @@ $analyzePreReqs = {
}

# Synopsis: Execute PSScriptAnalyzer tests
task Analyze Build, {
task Analyze -If (. $analyzePreReqs) Build,{
$analyzeParams = @{
Path = $PSBPreference.Build.ModuleOutDir
SeverityThreshold = $PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel
Expand All @@ -83,25 +86,24 @@ $pesterPreReqs = {
}

# Synopsis: Execute Pester tests
task Pester Build -If $pesterPreReqs, {
task Pester -If (. $pesterPreReqs) Build,{
$pesterParams = @{
Path = $PSBPreference.Test.RootDir
ModuleName = $PSBPreference.General.ModuleName
OutputPath = $PSBPreference.Test.OutputFile
OutputFormat = $PSBPreference.Test.OutputFormat
CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
Path = $PSBPreference.Test.RootDir
ModuleName = $PSBPreference.General.ModuleName
ModuleManifest = Join-Path $PSBPreference.Build.ModuleOutDir "$($PSBPreference.General.ModuleName).psd1"
OutputPath = $PSBPreference.Test.OutputFile
OutputFormat = $PSBPreference.Test.OutputFormat
CodeCoverage = $PSBPreference.Test.CodeCoverage.Enabled
CodeCoverageThreshold = $PSBPreference.Test.CodeCoverage.Threshold
CodeCoverageFiles = $PSBPreference.Test.CodeCoverage.Files
CodeCoverageOutputFile = $PSBPreference.Test.CodeCoverage.OutputFile
CodeCoverageOutputFileFormat = $PSBPreference.Test.CodeCoverage.OutputFormat
ImportModule = $PSBPreference.Test.ImportModule
}
Test-PSBuildPester @pesterParams
}

# Synopsis: Execute Pester and ScriptAnalyzer tests
task Test Pester, Analyze, {
}

# Synopsis: Builds help documentation
task BuildHelp GenerateMarkdown, GenerateMAML, {}

$genMarkdownPreReqs = {
$result = $true
Expand All @@ -113,7 +115,7 @@ $genMarkdownPreReqs = {
}

# Synopsis: Generates PlatyPS markdown files from module help
task GenerateMarkdown StageFiles, {
task GenerateMarkdown -if ($genMarkdownPreReqs) StageFiles,{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devblackops minor bug here I think, this should be (. $genMarkdownPrereqs), my bad, may want to do a quick patch commit since you already merged the PR.

Copy link
Member

@devblackops devblackops Mar 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll fix and publish v0.6.1

$buildMDParams = @{
ModulePath = $PSBPreference.Build.ModuleOutDir
ModuleName = $PSBPreference.General.ModuleName
Expand All @@ -133,7 +135,7 @@ $genHelpFilesPreReqs = {
}

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

Expand All @@ -147,7 +149,7 @@ $genUpdatableHelpPreReqs = {
}

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

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

Publish-PSBuildModule @publishParams
}


#region Summary Tasks

# Synopsis: Builds help documentation
task BuildHelp GenerateMarkdown,GenerateMAML

Task Build {
if ([String]$PSBPreference.Build.Dependencies -ne [String]$__DefaultBuildDependencies) {
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'
}
},StageFiles,BuildHelp

# Synopsis: Execute Pester and ScriptAnalyzer tests
task Test Analyze,Pester

task . Build,Test

#endregion Summary Tasks