Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Add new dependencies variables to allow end user to modify which tasks are
run.

## [0.7.2] 2025-05-21

### Added

- The `$PSBPreference` variable now supports the following PlatyPS `New-MarkdownHelp` and `Update-MarkdownHelp` boolean
options:
- The `$PSBPreference` variable now supports the following PlatyPS
`New-MarkdownHelp` and `Update-MarkdownHelp` boolean options:
- `$PSBPreference.Docs.AlphabeticParamsOrder`
- `$PSBPreference.Docs.ExcludeDontShow`
- `$PSBPreference.Docs.UseFullTypeName`
Expand Down
83 changes: 35 additions & 48 deletions PowerShellBuild/build.properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,63 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
[ordered]@{
General = @{
# Root directory for the project
ProjectRoot = $env:BHProjectPath
ProjectRoot = $env:BHProjectPath

# Root directory for the module
SrcRootDir = $env:BHPSModulePath
SrcRootDir = $env:BHPSModulePath

# The name of the module. This should match the basename of the PSD1 file
ModuleName = $env:BHProjectName
ModuleName = $env:BHProjectName

# Module version
ModuleVersion = $moduleVersion
ModuleVersion = $moduleVersion

# Module manifest path
ModuleManifestPath = $env:BHPSModuleManifest
}
Build = @{
Build = @{

# "Dependencies" moved to TaskDependencies section

# Output directory when building a module
OutDir = $outDir
OutDir = $outDir

# Module output directory
# This will be computed in 'Initialize-PSBuild' so we can allow the user to
# override the top-level 'OutDir' above and compute the full path to the module internally
ModuleOutDir = $null
ModuleOutDir = $null

# Controls whether to "compile" module into single PSM1 or not
CompileModule = $false
CompileModule = $false

# List of directories that if CompileModule is $true, will be concatenated into the PSM1
CompileDirectories = @('Enum', 'Classes', 'Private', 'Public')

# List of directories that will always be copied "as is" to output directory
CopyDirectories = @()
CopyDirectories = @()

# List of files (regular expressions) to exclude from output directory
Exclude = @()
Exclude = @()
}
Test = @{
Test = @{
# Enable/disable Pester tests
Enabled = $true
Enabled = $true

# Directory containing Pester tests
RootDir = [IO.Path]::Combine($env:BHProjectPath, 'tests')
RootDir = [IO.Path]::Combine($env:BHProjectPath, 'tests')

# Specifies an output file path to send to Invoke-Pester's -OutputFile parameter.
# This is typically used to write out test results so that they can be sent to a CI system
# This path is relative to the directory containing Pester tests
OutputFile = [IO.Path]::Combine($env:BHProjectPath, 'testResults.xml')
OutputFile = [IO.Path]::Combine($env:BHProjectPath, 'testResults.xml')

# Specifies the test output format to use when the TestOutputFile property is given
# a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter.
OutputFormat = 'NUnitXml'
OutputFormat = 'NUnitXml'

ScriptAnalysis = @{
ScriptAnalysis = @{
# Enable/disable use of PSScriptAnalyzer to perform script analysis
Enabled = $true
Enabled = $true

# When PSScriptAnalyzer is enabled, control which severity level will generate a build failure.
# Valid values are Error, Warning, Information and None. "None" will report errors but will not
Expand All @@ -73,26 +73,26 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
FailBuildOnSeverityLevel = 'Error'

# Path to the PSScriptAnalyzer settings file.
SettingsPath = [IO.Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
SettingsPath = [IO.Path]::Combine($PSScriptRoot, 'ScriptAnalyzerSettings.psd1')
}

# Import module from OutDir prior to running Pester tests.
ImportModule = $false
ImportModule = $false

CodeCoverage = @{
CodeCoverage = @{
# Enable/disable Pester code coverage reporting.
Enabled = $false
Enabled = $false

# Fail Pester code coverage test if below this threshold
Threshold = .75
Threshold = .75

# CodeCoverageFiles specifies the files to perform code coverage analysis on. This property
# acts as a direct input to the Pester -CodeCoverage parameter, so will support constructions
# like the ones found here: https://pester.dev/docs/usage/code-coverage.
Files = @()
Files = @()

# Path to write code coverage report to
OutputFile = [IO.Path]::Combine($env:BHProjectPath, 'codeCoverage.xml')
OutputFile = [IO.Path]::Combine($env:BHProjectPath, 'codeCoverage.xml')

# The code coverage output format to use
OutputFileFormat = 'JaCoCo'
Expand All @@ -102,61 +102,48 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
SkipRemainingOnFailure = 'None'

# Set verbosity of output. Options are None, Normal, Detailed and Diagnostic. Default: Detailed.
OutputVerbosity = 'Detailed'
OutputVerbosity = 'Detailed'
}
Help = @{
Help = @{
# Path to updatable help CAB
UpdatableHelpOutDir = [IO.Path]::Combine($outDir, 'UpdatableHelp')
UpdatableHelpOutDir = [IO.Path]::Combine($outDir, 'UpdatableHelp')

# Default Locale used for help generation, defaults to en-US
# Get-UICulture doesn't return a name on Linux so default to en-US
DefaultLocale = if (-not (Get-UICulture).Name) { 'en-US' } else { (Get-UICulture).Name }
DefaultLocale = if (-not (Get-UICulture).Name) { 'en-US' } else { (Get-UICulture).Name }

# Convert project readme into the module about file
ConvertReadMeToAboutHelp = $false
}
Docs = @{
Docs = @{
# Directory PlatyPS markdown documentation will be saved to
RootDir = [IO.Path]::Combine($env:BHProjectPath, 'docs')
RootDir = [IO.Path]::Combine($env:BHProjectPath, 'docs')

# Whether to overwrite existing markdown files and use comment based help as the source of truth
Overwrite = $false
Overwrite = $false

# Whether to order parameters alphabetically by name in PARAMETERS section.
# Value passed to New-MarkdownHelp and Update-MarkdownHelp.
AlphabeticParamsOrder = $false

# Exclude the parameters marked with `DontShow` in the parameter attribute from the help content.
# Value passed to New-MarkdownHelp and Update-MarkdownHelp.
ExcludeDontShow = $false
ExcludeDontShow = $false

# Indicates that the target document will use a full type name instead of a short name for parameters.
# Value passed to New-MarkdownHelp and Update-MarkdownHelp.
UseFullTypeName = $false
UseFullTypeName = $false
}
Publish = @{
# PowerShell repository name to publish modules to
PSRepository = 'PSGallery'
PSRepository = 'PSGallery'

# API key to authenticate to PowerShell repository with
PSRepositoryApiKey = $env:PSGALLERY_API_KEY
PSRepositoryApiKey = $env:PSGALLERY_API_KEY

# Credential to authenticate to PowerShell repository with
PSRepositoryCredential = $null
}
TaskDependencies = @{
Clean = @('Init')
StageFiles = @('Clean')
Build = @('StageFiles', 'BuildHelp')
Analyze = @('Build')
Pester = @('Build')
Test = @('Pester', 'Analyze')
BuildHelp = @('GenerateMarkdown', 'GenerateMAML')
GenerateMarkdown = @('StageFiles')
GenerateMAML = @('GenerateMarkdown')
GenerateUpdatableHelp = @('BuildHelp')
Publish = @('Test')
}
}

# Enable/disable generation of a catalog (.cat) file for the module.
Expand Down
82 changes: 59 additions & 23 deletions PowerShellBuild/psakeFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,55 @@ FormatTaskName {
Write-Host $taskName.ToUpper() -ForegroundColor Blue
}

#region Task Dependencies
if ($null -eq $PSBCleanDependency) {
$PSBCleanDependency = @('Init')
}
if ($null -eq $PSBStageFilesDependency) {
$PSBStageFilesDependency = @('Clean')
}
if ($null -eq $PSBBuildDependency) {
$PSBBuildDependency = @('StageFiles', 'BuildHelp')
}
if ($null -eq $PSBAnalyzeDependency) {
$PSBAnalyzeDependency = @('Build')
}
if ($null -eq $PSBPesterDependency) {
$PSBPesterDependency = @('Build')
}
if ($null -eq $PSBTestDependency) {
$PSBTestDependency = @('Pester', 'Analyze')
}
if ($null -eq $PSBBuildHelpDependency) {
$PSBBuildHelpDependency = @('GenerateMarkdown', 'GenerateMAML')
}
if ($null -eq $PSBGenerateMarkdownDependency) {
$PSBGenerateMarkdownDependency = @('StageFiles')
}
if ($null -eq $PSBGenerateMAMLDependency) {
$PSBGenerateMAMLDependency = @('GenerateMarkdown')
}
if ($null -eq $PSBGenerateUpdatableHelpDependency) {
$PSBGenerateUpdatableHelpDependency = @('BuildHelp')
}
if ($null -eq $PSBPublishDependency) {
$PSBPublishDependency = @('Test')
}
#endregion Task Dependencies

# This psake file is meant to be referenced from another
# Can't have two 'default' tasks
# Task default -depends Test

Task Init {
Initialize-PSBuild -UseBuildHelpers -BuildEnvironment $PSBPreference
} -description 'Initialize build environment variables'
} -Description 'Initialize build environment variables'

Task Clean -depends $PSBPreference.TaskDependencies.Clean {
Task Clean -Depends $PSBCleanDependency {
Clear-PSBuildOutputFolder -Path $PSBPreference.Build.ModuleOutDir
} -description 'Clears module output directory'
} -Description 'Clears module output directory'

Task StageFiles -depends $PSBPreference.TaskDependencies.StageFiles {
Task StageFiles -Depends $PSBStageFilesDependency {
$buildParams = @{
Path = $PSBPreference.General.SrcRootDir
ModuleName = $PSBPreference.General.ModuleName
Expand Down Expand Up @@ -51,9 +87,9 @@ Task StageFiles -depends $PSBPreference.TaskDependencies.StageFiles {
}

Build-PSBuildModule @buildParams
} -description 'Builds module based on source directory'
} -Description 'Builds module based on source directory'

Task Build -depends $PSBPreference.TaskDependencies.Build -description 'Builds module and generate help documentation'
Task Build -Depends $PSBBuildDependency -Description 'Builds module and generate help documentation'

$analyzePreReqs = {
$result = $true
Expand All @@ -67,14 +103,14 @@ $analyzePreReqs = {
}
$result
}
Task Analyze -depends $PSBPreference.TaskDependencies.Analyze -precondition $analyzePreReqs {
Task Analyze -Depends $PSBAnalyzeDependency -PreCondition $analyzePreReqs {
$analyzeParams = @{
Path = $PSBPreference.Build.ModuleOutDir
SeverityThreshold = $PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel
SettingsPath = $PSBPreference.Test.ScriptAnalysis.SettingsPath
}
Test-PSBuildScriptAnalysis @analyzeParams
} -description 'Execute PSScriptAnalyzer tests'
} -Description 'Execute PSScriptAnalyzer tests'

$pesterPreReqs = {
$result = $true
Expand All @@ -92,7 +128,7 @@ $pesterPreReqs = {
}
return $result
}
Task Pester -depends $PSBPreference.TaskDependencies.Pester -precondition $pesterPreReqs {
Task Pester -Depends $PSBPesterDependency -PreCondition $pesterPreReqs {
$pesterParams = @{
Path = $PSBPreference.Test.RootDir
ModuleName = $PSBPreference.General.ModuleName
Expand All @@ -109,12 +145,12 @@ Task Pester -depends $PSBPreference.TaskDependencies.Pester -precondition $peste
OutputVerbosity = $PSBPreference.Test.OutputVerbosity
}
Test-PSBuildPester @pesterParams
} -description 'Execute Pester tests'
} -Description 'Execute Pester tests'

Task Test -depends $PSBPreference.TaskDependencies.Test {
} -description 'Execute Pester and ScriptAnalyzer tests'
Task Test -Depends $PSBTestDependency {
} -Description 'Execute Pester and ScriptAnalyzer tests'

Task BuildHelp -depends $PSBPreference.TaskDependencies.BuildHelp {} -description 'Builds help documentation'
Task BuildHelp -Depends $PSBBuildHelpDependency {} -Description 'Builds help documentation'

$genMarkdownPreReqs = {
$result = $true
Expand All @@ -124,7 +160,7 @@ $genMarkdownPreReqs = {
}
$result
}
Task GenerateMarkdown -depends $PSBPreference.TaskDependencies.GenerateMarkdown -precondition $genMarkdownPreReqs {
Task GenerateMarkdown -Depends $PSBGenerateMarkdownDependency -PreCondition $genMarkdownPreReqs {
$buildMDParams = @{
ModulePath = $PSBPreference.Build.ModuleOutDir
ModuleName = $PSBPreference.General.ModuleName
Expand All @@ -136,7 +172,7 @@ Task GenerateMarkdown -depends $PSBPreference.TaskDependencies.GenerateMarkdown
UseFullTypeName = $PSBPreference.Docs.UseFullTypeName
}
Build-PSBuildMarkdown @buildMDParams
} -description 'Generates PlatyPS markdown files from module help'
} -Description 'Generates PlatyPS markdown files from module help'

$genHelpFilesPreReqs = {
$result = $true
Expand All @@ -146,9 +182,9 @@ $genHelpFilesPreReqs = {
}
$result
}
Task GenerateMAML -depends $PSBPreference.TaskDependencies.GenerateMAML -precondition $genHelpFilesPreReqs {
Task GenerateMAML -Depends $PSBGenerateMAMLDependency -PreCondition $genHelpFilesPreReqs {
Build-PSBuildMAMLHelp -Path $PSBPreference.Docs.RootDir -DestinationPath $PSBPreference.Build.ModuleOutDir
} -description 'Generates MAML-based help from PlatyPS markdown files'
} -Description 'Generates MAML-based help from PlatyPS markdown files'

$genUpdatableHelpPreReqs = {
$result = $true
Expand All @@ -158,12 +194,12 @@ $genUpdatableHelpPreReqs = {
}
$result
}
Task GenerateUpdatableHelp -depends $PSBPreference.TaskDependencies.GenerateUpdatableHelp -precondition $genUpdatableHelpPreReqs {
Task GenerateUpdatableHelp -Depends $PSBGenerateUpdatableHelpDependency -PreCondition $genUpdatableHelpPreReqs {
Build-PSBuildUpdatableHelp -DocsPath $PSBPreference.Docs.RootDir -OutputPath $PSBPreference.Help.UpdatableHelpOutDir
} -description 'Create updatable help .cab file based on PlatyPS markdown help'
} -Description 'Create updatable help .cab file based on PlatyPS markdown help'

Task Publish -depends $PSBPreference.TaskDependencies.Publish {
Assert -conditionToCheck ($PSBPreference.Publish.PSRepositoryApiKey -or $PSBPreference.Publish.PSRepositoryCredential) -failureMessage "API key or credential not defined to authenticate with [$($PSBPreference.Publish.PSRepository)] with."
Task Publish -Depends $PSBPublishDependency {
Assert -ConditionToCheck ($PSBPreference.Publish.PSRepositoryApiKey -or $PSBPreference.Publish.PSRepositoryCredential) -FailureMessage "API key or credential not defined to authenticate with [$($PSBPreference.Publish.PSRepository)] with."

$publishParams = @{
Path = $PSBPreference.Build.ModuleOutDir
Expand All @@ -180,9 +216,9 @@ Task Publish -depends $PSBPreference.TaskDependencies.Publish {
}

Publish-PSBuildModule @publishParams
} -description 'Publish module to the defined PowerShell repository'
} -Description 'Publish module to the defined PowerShell repository'

Task ? -description 'Lists the available tasks' {
Task ? -Description 'Lists the available tasks' {
'Available tasks:'
$psake.context.Peek().Tasks.Keys | Sort-Object
}
Loading
Loading