Skip to content

Commit f16d657

Browse files
authored
[Ignore] Improve Clean and Build tasks (#1144)
* Improve clean * Fix build version and origin in BuildInfo
1 parent d8fc936 commit f16d657

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

PowerShellEditorServices.build.ps1

+33-17
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,27 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, TestE
118118
Write-Host "`n### Using dotnet v$(& $script:dotnetExe --version) at path $script:dotnetExe`n" -ForegroundColor Green
119119
}
120120

121-
task Clean {
122-
exec { & $script:dotnetExe restore }
123-
exec { & $script:dotnetExe clean }
121+
task BinClean {
124122
Remove-Item $PSScriptRoot\.tmp -Recurse -Force -ErrorAction Ignore
125123
Remove-Item $PSScriptRoot\module\PowerShellEditorServices\bin -Recurse -Force -ErrorAction Ignore
126124
Remove-Item $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin -Recurse -Force -ErrorAction Ignore
125+
}
126+
127+
task Clean BinClean,{
128+
exec { & $script:dotnetExe restore }
129+
exec { & $script:dotnetExe clean }
127130
Get-ChildItem -Recurse $PSScriptRoot\src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
128131
Get-ChildItem $PSScriptRoot\PowerShellEditorServices*.zip | Remove-Item -Force -ErrorAction Ignore
129132
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
133+
134+
# Remove bundled component modules
135+
$moduleJsonPath = "$PSScriptRoot\modules.json"
136+
if (Test-Path $moduleJsonPath) {
137+
Get-Content -Raw $moduleJsonPath |
138+
ConvertFrom-Json |
139+
ForEach-Object { $_.PSObject.Properties.Name } |
140+
ForEach-Object { Remove-Item -Path "$PSScriptRoot/module/$_" -Recurse -Force -ErrorAction Ignore }
141+
}
130142
}
131143

132144
task GetProductVersion -Before PackageModule, UploadArtifacts {
@@ -156,30 +168,34 @@ task GetProductVersion -Before PackageModule, UploadArtifacts {
156168

157169
task CreateBuildInfo -Before Build {
158170
$buildVersion = "<development-build>"
159-
$buildOrigin = "<development>"
171+
$buildOrigin = "Development"
172+
173+
# Set build info fields on build platforms
174+
if ($env:TF_BUILD) {
175+
if ($env:BUILD_BUILDNUMBER -like "PR-*") {
176+
$buildOrigin = "PR"
177+
} elseif ($env:BUILD_DEFINITIONNAME -like "*-CI") {
178+
$buildOrigin = "CI"
179+
} else {
180+
$buildOrigin = "Release"
181+
}
160182

161-
if ($propsBody.VersionSuffix)
162-
{
163183
$propsXml = [xml](Get-Content -Raw -LiteralPath "$PSScriptRoot/PowerShellEditorServices.Common.props")
164184
$propsBody = $propsXml.Project.PropertyGroup
165185
$buildVersion = $propsBody.VersionPrefix
166-
$buildVersion += '-' + $propsBody.VersionSuffix
167-
}
168186

169-
# Set build info fields on build platforms
170-
if ($env:TF_BUILD)
171-
{
172-
$buildOrigin = "VSTS"
187+
if ($propsBody.VersionSuffix)
188+
{
189+
$buildVersion += '-' + $propsBody.VersionSuffix
190+
}
173191
}
174192

175193
# Allow override of build info fields (except date)
176-
if ($env:PSES_BUILD_VERSION)
177-
{
194+
if ($env:PSES_BUILD_VERSION) {
178195
$buildVersion = $env:PSES_BUILD_VERSION
179196
}
180197

181-
if ($env:PSES_BUILD_ORIGIN)
182-
{
198+
if ($env:PSES_BUILD_ORIGIN) {
183199
$buildOrigin = $env:PSES_BUILD_ORIGIN
184200
}
185201

@@ -208,7 +224,7 @@ task SetupHelpForTests -Before Test {
208224
}
209225
}
210226

211-
task Build {
227+
task Build BinClean,{
212228
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
213229
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Core }
214230
if (-not $script:IsUnix)

0 commit comments

Comments
 (0)