Skip to content

Loosen Dependencies #72

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 6 commits into from
Mar 31, 2025
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
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"powershell.codeFormatting.preset": "OTBS"
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.alignPropertyValuePairs": true
}
20 changes: 12 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Breaking Changes
### Changed

- [**#71**](https://github.com/psake/PowerShellBuild/pull/71) Compiled modules
are now explicitly created as UTF-8 files.
- [**#67**](https://github.com/psake/PowerShellBuild/pull/67) You can now
overwrite existing markdown files using `$PSBPreference.Docs.Overwrite` and
setting it to `$true`.
- Loose dependencies by allowing them to be overwritten with $PSBPreference.
- [**#72**](https://github.com/psake/PowerShellBuild/pull/72) Loosen
dependencies by allowing them to be overwritten with
`$PSBPreference.TaskDependencies`.

## [0.6.2] 2024-10-06

Expand Down Expand Up @@ -133,13 +137,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
'Public' folder when dot sourcing functions in PSM1 (via
[@pauby](https://github.com/pauby))

### Changed

- [**#19**](https://github.com/psake/PowerShellBuild/pull/19) Allow the
`BHBuildOutput` environment variable defined by `BuildHelpers` to be set via
the `$PSBPreference.Build.ModuleOutDir` property of the build tasks (via
[@pauby](https://github.com/pauby))

### Breaking changes

- Refactor build properties into a single hashtable `$PSBPreference`
Expand All @@ -150,6 +147,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
tasks are now auto-generated from the psake tasks via a converter script (via
[@JustinGrote](https://github.com/JustinGrote))

- [**#19**](https://github.com/psake/PowerShellBuild/pull/19) Allow the
`BHBuildOutput` environment variable defined by `BuildHelpers` to be set via
the `$PSBPreference.Build.ModuleOutDir` property of the build tasks (via
[@pauby](https://github.com/pauby))

## [0.2.0] - 2018-11-15

### Added
Expand All @@ -170,3 +172,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Initial commit

<!--spell-checker:ignore IMJLA webtroter joshooaj pauby joeypiccola nightroman -->
18 changes: 16 additions & 2 deletions PowerShellBuild/build.properties.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# spell-checker:ignore PSGALLERY BHPS MAML
BuildHelpers\Set-BuildEnvironment -Force

$outDir = [IO.Path]::Combine($env:BHProjectPath, 'Output')
Expand All @@ -22,7 +23,7 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
}
Build = @{

Dependencies = @('StageFiles', 'BuildHelp')
# "Dependencies" moved to TaskDependencies section

# Output directory when building a module
OutDir = $outDir
Expand Down Expand Up @@ -98,7 +99,7 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
}
}
Help = @{
# Path to updateable help CAB
# Path to updatable help CAB
UpdatableHelpOutDir = [IO.Path]::Combine($outDir, 'UpdatableHelp')

# Default Locale used for help generation, defaults to en-US
Expand All @@ -125,6 +126,19 @@ $moduleVersion = (Import-PowerShellDataFile -Path $env:BHPSModuleManifest).Modul
# 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
46 changes: 23 additions & 23 deletions PowerShellBuild/psakeFile.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# spell-checker:ignore Reqs
# Load in build settings
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')))

properties {}
Properties {}

FormatTaskName {
param($taskName)
Expand All @@ -15,24 +15,24 @@ FormatTaskName {
# Can't have two 'default' tasks
# Task default -depends Test

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

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

task StageFiles -depends Clean {
Task StageFiles -depends $PSBPreference.TaskDependencies.StageFiles {
$buildParams = @{
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
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 @@ -53,7 +53,7 @@ task StageFiles -depends Clean {
Build-PSBuildModule @buildParams
} -description 'Builds module based on source directory'

task Build -depends $PSBPreference.Build.Dependencies -description 'Builds module and generate help documentation'
Task Build -depends $PSBPreference.TaskDependencies.Build -description 'Builds module and generate help documentation'

$analyzePreReqs = {
$result = $true
Expand All @@ -67,7 +67,7 @@ $analyzePreReqs = {
}
$result
}
task Analyze -depends Build -precondition $analyzePreReqs {
Task Analyze -depends $PSBPreference.TaskDependencies.Analyze -precondition $analyzePreReqs {
$analyzeParams = @{
Path = $PSBPreference.Build.ModuleOutDir
SeverityThreshold = $PSBPreference.Test.ScriptAnalysis.FailBuildOnSeverityLevel
Expand All @@ -92,7 +92,7 @@ $pesterPreReqs = {
}
return $result
}
task Pester -depends Build -precondition $pesterPreReqs {
Task Pester -depends $PSBPreference.TaskDependencies.Pester -precondition $pesterPreReqs {
$pesterParams = @{
Path = $PSBPreference.Test.RootDir
ModuleName = $PSBPreference.General.ModuleName
Expand All @@ -109,10 +109,10 @@ task Pester -depends Build -precondition $pesterPreReqs {
Test-PSBuildPester @pesterParams
} -description 'Execute Pester tests'

task Test -depends Pester, Analyze {
Task Test -depends $PSBPreference.TaskDependencies.Test {
} -description 'Execute Pester and ScriptAnalyzer tests'

task BuildHelp -depends GenerateMarkdown, GenerateMAML {} -description 'Builds help documentation'
Task BuildHelp -depends $PSBPreference.TaskDependencies.BuildHelp {} -description 'Builds help documentation'

$genMarkdownPreReqs = {
$result = $true
Expand All @@ -122,7 +122,7 @@ $genMarkdownPreReqs = {
}
$result
}
task GenerateMarkdown -depends StageFiles -precondition $genMarkdownPreReqs {
Task GenerateMarkdown -depends $PSBPreference.TaskDependencies.GenerateMarkdown -precondition $genMarkdownPreReqs {
$buildMDParams = @{
ModulePath = $PSBPreference.Build.ModuleOutDir
ModuleName = $PSBPreference.General.ModuleName
Expand All @@ -141,7 +141,7 @@ $genHelpFilesPreReqs = {
}
$result
}
task GenerateMAML -depends GenerateMarkdown -precondition $genHelpFilesPreReqs {
Task GenerateMAML -depends $PSBPreference.TaskDependencies.GenerateMAML -precondition $genHelpFilesPreReqs {
Build-PSBuildMAMLHelp -Path $PSBPreference.Docs.RootDir -DestinationPath $PSBPreference.Build.ModuleOutDir
} -description 'Generates MAML-based help from PlatyPS markdown files'

Expand All @@ -153,11 +153,11 @@ $genUpdatableHelpPreReqs = {
}
$result
}
task GenerateUpdatableHelp -depends BuildHelp -precondition $genUpdatableHelpPreReqs {
Task GenerateUpdatableHelp -depends $PSBPreference.TaskDependencies.GenerateUpdatableHelp -precondition $genUpdatableHelpPreReqs {
Build-PSBuildUpdatableHelp -DocsPath $PSBPreference.Docs.RootDir -OutputPath $PSBPreference.Help.UpdatableHelpOutDir
} -description 'Create updatable help .cab file based on PlatyPS markdown help'

task Publish -depends Test {
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."

$publishParams = @{
Expand All @@ -177,7 +177,7 @@ task Publish -depends Test {
Publish-PSBuildModule @publishParams
} -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
}
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PowerShellBuild

| GitHub Actions | PS Gallery | License |
|----------------|------------|---------|
| GitHub Actions | PS Gallery | License |
|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|--------------------------------------|
| [![GitHub Actions Status][github-actions-badge]][github-actions-build] [![GitHub Actions Status][github-actions-badge-publish]][github-actions-build] | [![PowerShell Gallery][psgallery-badge]][psgallery] | [![License][license-badge]][license] |

This project aims to provide common [psake](https://github.com/psake/psake) and
Expand Down Expand Up @@ -53,28 +53,28 @@ other projects.
These primary tasks are the main tasks you'll typically call as part of
PowerShell module development.

| Name | Dependencies | Description |
| --------------------- | --------------------- | ----------- |
| Init | _none_ | Initialize psake and task variables |
| Clean | init | Clean output directory |
| Build | StageFiles, BuildHelp | Clean and build module in output directory |
| Analyze | Build | Run PSScriptAnalyzer tests |
| Pester | Build | Run Pester tests |
| Test | Analyze, Pester | Run combined tests |
| Publish | Test | Publish module to defined PowerShell repository |
| Name | Dependencies | Description |
|---------|-----------------------|-------------------------------------------------|
| Init | _none_ | Initialize psake and task variables |
| Clean | init | Clean output directory |
| Build | StageFiles, BuildHelp | Clean and build module in output directory |
| Analyze | Build | Run PSScriptAnalyzer tests |
| Pester | Build | Run Pester tests |
| Test | Analyze, Pester | Run combined tests |
| Publish | Test | Publish module to defined PowerShell repository |

### Secondary Tasks

These secondary tasks are called as dependencies from the primary tasks but may
also be called directly.

| Name | Dependencies | Description |
| --------------------- | -------------------------------| ----------- |
| BuildHelp | GenerateMarkdown, GenerateMAML | Build all help files |
| Name | Dependencies | Description |
|-----------------------|--------------------------------|----------------------------------|
| BuildHelp | GenerateMarkdown, GenerateMAML | Build all help files |
| StageFiles | Clean | Build module in output directory |
| GenerateMarkdown | StageFiles | Build markdown-based help |
| GenerateMAML | GenerateMarkdown | Build MAML help |
| GenerateUpdatableHelp | BuildHelp | Build updatable help cab |
| GenerateMarkdown | StageFiles | Build markdown-based help |
| GenerateMAML | GenerateMarkdown | Build MAML help |
| GenerateUpdatableHelp | BuildHelp | Build updatable help cab |

## Task customization

Expand Down Expand Up @@ -119,10 +119,21 @@ match your environment.
| $PSBPreference.Help.DefaultLocale | `(Get-UICulture).Name` | Default locale used for help generation |
| $PSBPreference.Help.ConvertReadMeToAboutHelp | `$false` | Convert project readme into the module about file |
| $PSBPreference.Docs.RootDir | `$projectRoot/docs` | Directory PlatyPS markdown documentation will be saved to |
| $PSBPreference.Docs.Overwrite | `$false` | Overwrite the markdown files in the docs folder using the comment based help as the source of truth. |
| $PSBPreference.Docs.Overwrite | `$false` | Overwrite the markdown files in the docs folder using the comment based help as the source of truth. |
| $PSBPreference.Publish.PSRepository | `PSGallery` | PowerShell repository name to publish |
| $PSBPreference.Publish.PSRepositoryApiKey | `$env:PSGALLERY_API_KEY` | API key to authenticate to PowerShell repository with |
| $PSBPreference.Publish.PSRepositoryCredential | `$null` | Credential to authenticate to PowerShell repository with. Overrides `$psRepositoryApiKey` if defined |
| $PSBPreference.TaskDependencies.Clean | 'Init' | Tasks the 'Clean' task depends on. |
| $PSBPreference.TaskDependencies.StageFiles | 'Clean' | Tasks the 'StageFiles' task depends on. |
| $PSBPreference.TaskDependencies.Build | 'StageFiles', 'BuildHelp' | Tasks the 'Build' task depends on. |
| $PSBPreference.TaskDependencies.Analyze | 'Build' | Tasks the 'Analyze' task depends on. |
| $PSBPreference.TaskDependencies.Pester | 'Build' | Tasks the 'Pester' task depends on. |
| $PSBPreference.TaskDependencies.Test | 'Pester', 'Analyze' | Tasks the 'Test' task depends on. |
| $PSBPreference.TaskDependencies.BuildHelp | 'GenerateMarkdown', 'GenerateMAML' | Tasks the 'BuildHelp' task depends on. |
| $PSBPreference.TaskDependencies.GenerateMarkdown | 'StageFiles' | Tasks the 'GenerateMarkdown' task depends on. |
| $PSBPreference.TaskDependencies.GenerateMAML | 'GenerateMarkdown' | Tasks the 'GenerateMAML' task depends on. |
| $PSBPreference.TaskDependencies.GenerateUpdatableHelp | 'BuildHelp' | Tasks the 'GenerateUpdatableHelp' task depends on. |
| $PSBPreference.TaskDependencies.Publish | 'Test' | Tasks the 'Publish' task depends on. |

## Examples

Expand Down
Loading