Skip to content

Commit 37c38e9

Browse files
committed
Change a few assumptions
1 parent 4771795 commit 37c38e9

File tree

7 files changed

+63
-27
lines changed

7 files changed

+63
-27
lines changed

.markdownlint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"default": true,
3+
"MD007": {
4+
"indent": 4
5+
},
6+
"MD013": {
7+
"line_length": 120,
8+
"code_block_line_length": 120
9+
}
10+
}

DotNetPublish.Task.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Add-BuildTask DotNetPublish @{
88
}
99
Outputs = {
1010
Split-Path $dotnetProjects -Leaf |
11-
Join-Path -Path { "$PublishRoot${/}$_" } -ChildPath { "$_.dll" }
11+
Join-Path -Path { "$DotNetPublishRoot${/}$_" } -ChildPath { "$_.dll" }
1212
}
1313
Jobs = "DotNetBuild", {
1414
$local:options = @{} + $script:dotnetOptions
1515

16-
# The PublishRoot is the pub folder within the OutputRoot (used for dotnet publish output)
17-
$script:PublishRoot = New-Item (Join-Path $script:OutputRoot publish) -ItemType Root -Force -ErrorAction SilentlyContinue | Convert-Path
16+
$script:DotNetPublishRoot = New-Item $script:DotNetPublishRoot -ItemType Root -Force -ErrorAction SilentlyContinue | Convert-Path
1817

1918
# We never do self-contained builds
2019
if ($options.ContainsKey("-runtime") -or $options.ContainsKey("-ucr")) {
@@ -28,8 +27,8 @@ Add-BuildTask DotNetPublish @{
2827
}
2928

3029
Set-Location $project
31-
Write-Build Gray "dotnet publish --output $PublishRoot${/}$Name --no-build --configuration $configuration -p $($options["p"])"
32-
dotnet publish --output "$PublishRoot${/}$Name" --no-build --configuration $configuration
30+
Write-Build Gray "dotnet publish --output $DotNetPublishRoot${/}$Name --no-build --configuration $configuration -p $($options["p"])"
31+
dotnet publish --output "$DotNetPublishRoot${/}$Name" --no-build --configuration $configuration
3332
}
3433
}
3534
}

PSModuleAnalyze.Task.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Add-BuildTask PSModuleAnalyze PSModuleBuild, {
22
$ScriptAnalyzer = @{
33
IncludeDefaultRules = $true
4-
Path = $PSModuleManifestPath -replace "d1$","*1"
4+
Path = Get-ChildItem $PSModuleOutputPath -Filter $PSModuleName.ps*1 -Recurse
55
Settings = if (Test-Path "$BuildRoot\ScriptAnalyzerSettings.psd1") {
66
"$BuildRoot\ScriptAnalyzerSettings.psd1"
77
} else {

PSModuleImport.Task.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Add-BuildTask PSModuleImport "PSModuleRestore", "PSModuleBuild", {
22
# Always re-import the module -- don't try to guess if it's been changed
3-
if (-not(Test-Path $PSModuleManifestPath)) {
4-
throw "Could not find ManifestPath '$PSModuleManifestPath'"
5-
} else {
3+
if ($PSModuleManifestPath = Get-ChildItem $PSModuleOutputPath -Filter "$PSModuleName.psm1" -Recurse -ErrorAction Ignore) {
64

75
if (($loaded = Get-Module -Name $PSModuleName -All -ErrorAction Ignore)) {
86
"Unloading Module '$PSModuleName' $($loaded.Version -join ', ')"
@@ -11,5 +9,7 @@ Add-BuildTask PSModuleImport "PSModuleRestore", "PSModuleBuild", {
119

1210
"Importing Module '$PSModuleName' $($Script:GitVersion.SemVer) from '$PSModuleManifestPath'"
1311
Import-Module -Name $PSModuleManifestPath -Force -PassThru:$PassThru
12+
} else {
13+
throw "Cannot find module manifest $PSModuleName in '$PSModuleOutputPath'"
1414
}
1515
}

PSModuleTest.Task.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Add-BuildTask PSModuleTest @{
4444
$TestModulePath = @($OutputRoot) + @($Env:PSMODULEPATH -split [IO.Path]::PathSeparator -ne $OutputRoot) -join [IO.Path]::PathSeparator
4545
$Env:PSMODULEPATH, $OldModulePath = $TestModulePath, $Env:PSMODULEPATH
4646
try {
47+
$PSModuleManifestPath = Get-ChildItem $PSModuleOutputPath -Filter "$PSModuleName.psm1" -Recurse -ErrorAction Ignore
4748
Write-Output (@(
4849
"Set PSModulePath:"
4950
$Env:PSMODULEPATH
@@ -57,7 +58,7 @@ Add-BuildTask PSModuleTest @{
5758

5859

5960
if ($Script:RequiredCodeCoverage -gt 0.00) {
60-
$CodeCoveragePath = [IO.Path]::ChangeExtension($PSModuleManifestPath, ".psm1")
61+
$CodeCoveragePath = $PSModuleManifestPath
6162
$CodeCoverageOutputPath = "$OutputRoot\coverage.xml"
6263
$CodeCoveragePercentTarget = $RequiredCodeCoverage
6364
}

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,41 @@
55

66
I've started using Invoke-Build to run my builds in PowerShell (due mostly to unhappiness with GitHub and Azure Pipelines).
77
This is a collection of tasks I've written that get shared by all my project builds.
8+
9+
## Usage
10+
11+
Your .build.ps1 script _must_ set variables:
12+
13+
### For PowerShell modules
14+
15+
- `$PSModuleName`
16+
- The name of the module you're building.
17+
- There **must** be a .psd1 module manifest with this name in your source.
18+
- The build will create a folder with this name in the output folder
19+
20+
If you're including building a dotnet project, it's also recommended to set
21+
22+
- `$DotNetPublishRoot`
23+
- The target folder for dotnet publish.
24+
- Defaults to `$OutputRoot/publish`
25+
- For PowerShell modules, I always override this to `$BuildRoot/lib` and add that to the `CopyDirectories` list
26+
in my ModuleBuilder `build.psd1` so that it gets copied to the output folder by ModuleBuilder.
27+
28+
### For DotNet assemblies
29+
30+
- `$dotnetProjects`
31+
- Specifies which projects to build
32+
- I recommend you put this as a parameter on your Build.ps1
33+
- Set the default to the full list of your assembly projects
34+
- Add an alias: "Projects"
35+
- `$dotnetTestProjects`
36+
- Specifies which projects are test projects
37+
- I recommend you put this as a parameter on your Build.ps1
38+
- Add an alias: "TestProjects"
39+
- `$dotnetOptions`
40+
- Specifies further options to pass to dotnet
41+
- I recommend you put this as a parameter on your Build.ps1
42+
- Add an alias: "Options"
43+
- Example values:
44+
"-verbosity" = "minimal"
45+
"-runtime" = "linux-x64"

_Initialize.ps1

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
#>
77
[CmdletBinding()]
88
param(
9-
# Initialize the dotnet variables and import the dotnet tasks
10-
[switch]$DotNet,
11-
12-
# Initialize the PowerShell module variables and import the tasks
13-
[switch]$PowerShell,
14-
159
# Skip importing tasks
1610
[switch]$NoTasks
17-
1811
)
12+
1913
$InformationPreference = "Continue"
2014
$ErrorView = 'DetailedView'
2115
$ErrorActionPreference = 'Stop'
@@ -116,8 +110,10 @@ Write-Information " BranchName: $script:BranchName"
116110
#endregion
117111

118112
#region DotNet task variables. Find the DotNet projects once.
119-
if ($DotNet) {
113+
if ($dotnetProjects) {
120114
Write-Information "Initializing DotNet build variables"
115+
# The DotNetPublishRoot is the "publish" folder within the OutputRoot (used for dotnet publish output)
116+
$script:DotNetPublishRoot ??= Join-Path $script:OutputRoot publish
121117

122118
# The projects are expected to each be in their own folder
123119
# Dotnet allows us to pass it the _folder_ that we want to build/test
@@ -155,12 +151,8 @@ if ($DotNet) {
155151
#endregion
156152

157153
#region PowerShell Module task variables. Find the PowerShell module once.
158-
if ($PowerShell) {
154+
if ($PSModuleName) {
159155
Write-Information "Initializing PSModule build variables"
160-
# Any of these variables can be set in the .build.ps1 to override our defaults:
161-
# $PSModuleName, $PSModuleSourceRoot,
162-
$script:PSModuleName ??= "*"
163-
164156
# We're looking for either a build.psd1 or the module manifest:
165157
# .\src\ModuleName.psd1
166158
# .\source\ModuleName.psd1
@@ -236,10 +228,6 @@ if ($PowerShell) {
236228
$script:PSModulePublishUri ??= $Env:PSMODULE_PUBLISH_URI
237229
$script:PSModulePublishKey ??= $Env:PSMODULE_PUBLISH_KEY
238230
Write-Information " PowerShellModulePublishUri: $PowerShellModulePublishUri"
239-
240-
# THESE variables can't be overridden, they're conventions based on $BuildRoot and $OutputRoot
241-
$Script:PSModuleManifestPath = Join-Path $PSModuleOutputPath "$PSModuleName.psd1"
242-
Write-Information " PSModuleManifestPath: $PSModuleManifestPath"
243231
}
244232
#endregion
245233

0 commit comments

Comments
 (0)