Skip to content

Commit ad913e8

Browse files
committed
Add a better clean task and fix the ability to build DEBUG mode
1 parent 751efb3 commit ad913e8

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

Clean.Task.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Add-BuildTask Clean {
22
# This will blow away everything that's .gitignored, and fast
33
git clean -Xdf
4-
# Re "Initialize.ps1" to make sure the directories are there
5-
& "$PSScriptRoot/_Initialize.ps1" -NoTasks -InformationAction SilentlyContinue
4+
5+
# Ensure the output directories from Initialize are still there
6+
New-Item -Type Directory -Path $OutputRoot -Force | Out-Null
7+
New-Item -Type Directory -Path $TestResultsRoot -Force | Out-Null
8+
New-Item -Type Directory -Path $TempRoot -Force | Out-Null
69
}

_Initialize.ps1

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ${script:\} = ${script:/} = [IO.Path]::DirectorySeparatorChar
3838
$Script:RequiredCodeCoverage ??= 0.9
3939

4040
# Our default build configuration is Release (probably only applies to DotNet)
41-
$script:Configuration ??= "Release"
41+
$script:Configuration ??= $Env:CONFIGURATION ?? "Release"
4242
Write-Information " Configuration: $script:Configuration"
4343

4444
#endregion
@@ -78,27 +78,20 @@ if ($script:BuildSystem -eq "AzureDevops") {
7878
#>
7979

8080
# There are a few different environment/variables it could be, and then our fallback
81-
$Script:OutputRoot = $script:OutputRoot ??
82-
$Env:OUTPUT_ROOT ?? # I set this for earthly
83-
$Env:BUILD_BINARIESDIRECTORY ?? # Azure
84-
(Join-Path -Path $BuildRoot -ChildPath 'output')
81+
# Prefer the environment variable (because earthly uses these)
82+
# Otherwise, the local $script: variable (my .build.ps1 uses these)
83+
# Otherwise, the GitHub Workflow and Azure Pipeline environment variables
84+
# Finally, some calculated default value
85+
$Script:OutputRoot = $Env:OUTPUT_ROOT ?? $script:OutputRoot ?? $Env:BUILD_BINARIESDIRECTORY ?? (Join-Path -Path $BuildRoot -ChildPath 'output')
8586
New-Item -Type Directory -Path $OutputRoot -Force | Out-Null
8687
Write-Information " OutputRoot: $OutputRoot"
8788

88-
$Script:TestResultsRoot = $script:TestResultsRoot ??
89-
$Env:TEST_ROOT ?? # I set this for earthly
90-
$Env:COMMON_TESTRESULTSDIRECTORY ?? # Azure
91-
$Env:TEST_RESULTS_DIRECTORY ??
92-
(Join-Path -Path $OutputRoot -ChildPath 'tests')
89+
$Script:TestResultsRoot = $Env:TEST_ROOT ?? $script:TestResultsRoot ?? $Env:COMMON_TESTRESULTSDIRECTORY <# Azure #> ?? $Env:TEST_RESULTS_DIRECTORY <# Github #> ?? (Join-Path -Path $OutputRoot -ChildPath 'tests')
9390
New-Item -Type Directory -Path $TestResultsRoot -Force | Out-Null
9491
Write-Information " TestResultsRoot: $TestResultsRoot"
9592

9693
### IMPORTANT: Our local TempRoot does not cleaned the way the Azure one does
97-
$Script:TempRoot = $script:TempRoot ??
98-
$Env:TEMP_ROOT ?? # I set this for earthly
99-
$Env:RUNNER_TEMP ?? # Github
100-
$Env:AGENT_TEMPDIRECTORY ?? # Azure
101-
(Join-Path ($Env:TEMP ?? $Env:TMP ?? "$BuildRoot/Tmp_$(Get-Date -f yyyyMMddThhmmss)") -ChildPath 'InvokeBuild')
94+
$Script:TempRoot = $Env:TEMP_ROOT ?? $script:TempRoot ?? $Env:RUNNER_TEMP <# Github #> ?? $Env:AGENT_TEMPDIRECTORY <# Azure #> ?? (Join-Path ($Env:TEMP ?? $Env:TMP ?? "$BuildRoot/Tmp_$(Get-Date -f yyyyMMddThhmmss)") -ChildPath 'InvokeBuild')
10295
New-Item -Type Directory -Path $TempRoot -Force | Out-Null
10396
Write-Information " TempRoot: $TempRoot"
10497

@@ -168,13 +161,14 @@ if (([bool]$DotNet = $dotnetProjects -or $DotNetPublishRoot)) {
168161
#endregion
169162

170163
#region PowerShell Module task variables. Find the PowerShell module once.
164+
$script:PSModuleName ??= $Env:MODULE_NAME
171165
if ($PSModuleName) {
172166
Write-Information "Initializing PSModule build variables"
173167
# We're looking for either a build.psd1 or the module manifest:
174168
# ./src/ModuleName.psd1
175169
# ./source/ModuleName.psd1
176170
# ./ModuleName/ModuleName.psd1
177-
if ($PSModuleName -eq "*" -or !$PSModuleSourceRoot -or !$PSModuleName -or !(Test-Path $PSModuleSourceRoot -PathType Container)) {
171+
if ($PSModuleName -eq "*" -or !$PSModuleSourceRoot -or !$PSModuleName -or !(Test-Path $PSModuleSourceRoot -PathType Container)) {
178172
Write-Information " Looking for PSModule source"
179173
# look for a build.psd1 for ModuleBuilder. It should be in the root, but it might be in a subfolder
180174
if (($BuildModule = Get-ChildItem -Recurse -Filter build.psd1 -ErrorAction Ignore | Select-Object -First 1)) {
@@ -205,10 +199,10 @@ if ($PSModuleName) {
205199
} else {
206200
Write-Information " No build manifest, searching for module source"
207201
# Look for a module manifest
208-
$ModuleManifest = Get-ChildItem "src","source",$PSModuleName,"." -Filter "$PSModuleName.psd1" -File -ErrorAction Ignore |
209-
Where-Object Name -ne "build.psd1" |
210-
Select-Object -First 1 |
211-
Convert-Path
202+
$ModuleManifest = Get-ChildItem "src", "source", $PSModuleName, "." -Filter "$PSModuleName.psd1" -File -ErrorAction Ignore |
203+
Where-Object Name -ne "build.psd1" |
204+
Select-Object -First 1 |
205+
Convert-Path
212206
if (Test-Path $ModuleManifest -PathType Leaf) {
213207
Write-Information " Found PSModule source manifest: $ModuleManifest"
214208
$script:PSModuleName = [IO.Path]::GetFileNameWithoutExtension($ModuleManifest)
@@ -258,24 +252,33 @@ $script:PackageNames = $script:PackageNames ?? @(
258252
@($PSModuleName)
259253
}
260254
) + @(
261-
if (!$dotnetProjects -and !$PSModuleName){
255+
if (!$dotnetProjects -and !$PSModuleName) {
262256
"module"
263257
}
264258
) | Select-Object -Unique
265259

266260
## The first task defined is the default task. Default to build and test.
267261
if ($PSModuleName -and $dotnetProjects -or $DotNetPublishRoot) {
268-
Add-BuildTask Build DotNetRestore, PSModuleRestore, GitVersion, DotNetBuild, DotNetPublish, PSModuleBuild #, PSModuleBuildHelp
262+
Add-BuildTask Build @(
263+
if ($Clean) { "Clean" }
264+
"DotNetRestore", "PSModuleRestore", "GitVersion", "DotNetBuild", "DotNetPublish", "PSModuleBuild" #, PSModuleBuildHelp
265+
)
269266
Add-BuildTask Test Build, DotNetTest, PSModuleAnalyze, PSModuleTest
270267
Add-BuildTask Pack Test, TagSource, DotNetPack
271268
Add-BuildTask Push Pack, DotNetPush, PSModulePush
272269
} elseif ($PSModuleName) {
273-
Add-BuildTask Build PSModuleRestore, GitVersion, PSModuleBuild #, PSModuleBuildHelp
270+
Add-BuildTask Build @(
271+
if ($Clean) { "Clean" }
272+
"PSModuleRestore", "GitVersion", "PSModuleBuild" #, PSModuleBuildHelp
273+
)
274274
Add-BuildTask Test Build, PSModuleAnalyze, PSModuleTest
275275
Add-BuildTask Pack Test, TagSource
276276
Add-BuildTask Push Pack, PSModulePush
277277
} elseif ($dotnetProjects) {
278-
Add-BuildTask Build DotNetRestore, GitVersion, DotNetBuild, DotNetPublish
278+
Add-BuildTask Build @(
279+
if ($Clean) { "Clean" }
280+
"DotNetRestore", "GitVersion", "DotNetBuild", "DotNetPublish"
281+
)
279282
Add-BuildTask Test Build, DotNetTest
280283
Add-BuildTask Pack Test, TagSource
281284
Add-BuildTask Push Pack, DotNetPack, DotNetPush

0 commit comments

Comments
 (0)