Skip to content

Commit 0127ee2

Browse files
Backport build script refactor to date-based versions legacy (#1938)
1 parent 955f9dc commit 0127ee2

File tree

5 files changed

+117
-39
lines changed

5 files changed

+117
-39
lines changed

.vsts-ci/azure-pipelines-ci.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
trigger:
2-
- master
3-
- legacy/1.x
1+
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
2+
43
variables:
5-
# Don't download unneeded packages
4+
# Don't download unneeded packages
65
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
76
value: 'true'
8-
# Don't send telemetry
7+
# Improve performance by not sending telemetry
98
- name: DOTNET_CLI_TELEMETRY_OPTOUT
109
value: 'true'
10+
11+
trigger:
12+
batch: true
13+
branches:
14+
include:
15+
- master
16+
- legacy/1.x
17+
paths:
18+
exclude:
19+
- /.dependabot/*
20+
- /.poshchan/*
21+
- /.github/**/*
22+
- /.vscode/**/*
23+
- /.vsts-ci/misc-analysis.yml
24+
- /tools/**/*
25+
- .editorconfig
26+
- .gitattributes
27+
- .gitignore
28+
- /docs/**/*
29+
- /CHANGELOG.md
30+
- /CONTRIBUTING.md
31+
- /README.md
32+
- /LICENSE
33+
- /CODE_OF_CONDUCT.md
34+
1135
jobs:
1236
- job: Windows
1337
pool:

.vsts-ci/templates/ci-general.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
steps:
22
# Setup
3+
- pwsh: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))"
4+
displayName: Set Build Name for Non-PR
5+
condition: ne(variables['Build.Reason'], 'PullRequest')
36
- pwsh: |
47
git clone https://github.com/PowerShell/PowerShellEditorServices.git ../PowerShellEditorServices
58
Install-Module InvokeBuild -Scope CurrentUser -Force

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "powershell",
33
"displayName": "PowerShell",
44
"version": "1.12.1",
5+
"preview": false,
56
"publisher": "ms-vscode",
67
"description": "Develop PowerShell scripts in Visual Studio Code!",
78
"engines": {

tools/releaseBuild/Image/build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ else {
99
}
1010
}
1111
push-location C:/vscode-powershell
12-
Invoke-Build GetExtensionVersion,Clean,Build,Test,Package
12+
Invoke-Build Release
1313
Copy-Item -Verbose -Recurse "C:/vscode-powershell/PowerShell-insiders.vsix" "${target}/PowerShell-insiders.vsix"

vscode-powershell.build.ps1

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,12 @@ param(
99

1010
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.0.0"}
1111

12-
task GetExtensionVersion -Before Package {
12+
# Grab package.json data which is used throughout the build.
13+
$script:PackageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
14+
Write-Host "`n### Extension Version: $($script:PackageJson.version) Extension Name: $($script:PackageJson.name)`n" -ForegroundColor Green
1315

14-
$updateVersion = $false
15-
$script:ExtensionVersion = `
16-
if ($env:VSTS_BUILD) {
17-
$updateVersion = $true
18-
$env:VSTS_BUILD_VERSION
19-
}
20-
else {
21-
exec { & npm version | ConvertFrom-Json | ForEach-Object { $_.PowerShell } }
22-
}
23-
24-
Write-Host "`n### Extension Version: $script:ExtensionVersion`n" -ForegroundColor Green
25-
26-
if ($updateVersion) {
27-
exec { & npm version $script:ExtensionVersion --no-git-tag-version --allow-same-version }
28-
}
29-
}
30-
31-
task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices {
16+
#region Utility tasks
17+
task ResolveEditorServicesPath -Before CleanEditorServices, TestEditorServices, BuildEditorServices {
3218

3319
$script:psesRepoPath = `
3420
if ($EditorServicesRepoPath) {
@@ -40,7 +26,7 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
4026

4127
if (!(Test-Path $script:psesRepoPath)) {
4228
# Clear the path so that it won't be used
43-
Write-Host "`n### WARNING: The PowerShellEditorServices repo cannot be found at path $script:psesRepoPath`n" -ForegroundColor Yellow
29+
Write-Warning "`nThe PowerShellEditorServices repo cannot be found at path $script:psesRepoPath`n"
4430
$script:psesRepoPath = $null
4531
}
4632
else {
@@ -49,7 +35,18 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices
4935
}
5036
}
5137

52-
task Restore RestoreNodeModules -Before Build -If { -not (Test-Path "$PSScriptRoot/node_modules") }
38+
task UploadArtifacts {
39+
if ($env:TF_BUILD) {
40+
# SYSTEM_PHASENAME is the Job name.
41+
Copy-Item -Path PowerShell-insiders.vsix `
42+
-Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$($script:PackageJson.name)-$($script:PackageJson.version)-$env:SYSTEM_PHASENAME.vsix"
43+
}
44+
}
45+
46+
#endregion
47+
#region Restore tasks
48+
49+
task Restore RestoreNodeModules -If { -not (Test-Path "$PSScriptRoot/node_modules") }
5350

5451
task RestoreNodeModules {
5552

@@ -61,6 +58,9 @@ task RestoreNodeModules {
6158
exec { & npm install $logLevelParam }
6259
}
6360

61+
#endregion
62+
#region Clean tasks
63+
6464
task Clean {
6565
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
6666
Remove-Item .\modules\* -Exclude "README.md" -Recurse -Force -ErrorAction Ignore
@@ -77,7 +77,10 @@ task CleanEditorServices {
7777

7878
task CleanAll CleanEditorServices, Clean
7979

80-
task Build {
80+
#endregion
81+
#region Build tasks
82+
83+
task Build Restore, {
8184
Write-Host "`n### Building vscode-powershell" -ForegroundColor Green
8285
exec { & npm run compile }
8386
}
@@ -92,17 +95,68 @@ task BuildEditorServices {
9295

9396
task BuildAll BuildEditorServices, Build
9497

98+
#endregion
99+
#region Test tasks
100+
95101
task Test Build, {
96102
if (!$global:IsLinux -and !$global:IsMacOS) {
97103
Write-Host "`n### Running extension tests" -ForegroundColor Green
98104
exec { & npm run test }
99105
}
100106
else {
101-
Write-Host "`n### Skipping extension tests on non-Windows platform" -ForegroundColor Yellow
107+
Write-Warning "Skipping extension tests on Linux and macOS platform for legacy branch."
102108
}
103109
}
104110

105-
task Package {
111+
task TestEditorServices {
112+
if ($script:psesBuildScriptPath) {
113+
Write-Host "`n### Testing PowerShellEditorServices`n" -ForegroundColor Green
114+
Invoke-Build Test $script:psesBuildScriptPath
115+
}
116+
}
117+
118+
task TestAll TestEditorServices, Test
119+
120+
#endregion
121+
#region Package tasks
122+
123+
task UpdateReadme -If { $script:PackageJson.version -like "*preview*" } {
124+
# Add the preview text
125+
$newReadmeTop = '# PowerShell Language Support for Visual Studio Code
126+
> ## ATTENTION: This is the PREVIEW version of the PowerShell extension for VSCode which contains features that are being evaluated for stable. It works with PowerShell 5.1 and up.
127+
> ### If you are looking for the stable version, please [go here](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell) or install the extension called "PowerShell" (not "PowerShell Preview")
128+
> ## NOTE: If you have both stable (aka "PowerShell") and preview (aka "PowerShell Preview") installed, you MUST [DISABLE](https://code.visualstudio.com/docs/editor/extension-gallery#_disable-an-extension) one of them for the best performance. Docs on how to disable an extension can be found [here](https://code.visualstudio.com/docs/editor/extension-gallery#_disable-an-extension)'
129+
$readmePath = (Join-Path $PSScriptRoot README.md)
130+
$readmeContent = Get-Content -Path $readmePath
131+
if (!($readmeContent -match "This is the PREVIEW version of the PowerShell extension")) {
132+
$readmeContent[0] = $newReadmeTop
133+
$readmeContent | Set-Content $readmePath -Encoding utf8
134+
}
135+
}
136+
137+
task UpdatePackageJson {
138+
if ($script:PackageJson.version -like "*preview*") {
139+
$script:PackageJson.name = "powershell-preview"
140+
$script:PackageJson.displayName = "PowerShell Preview"
141+
$script:PackageJson.description = "(Preview) Develop PowerShell scripts in Visual Studio Code!"
142+
$script:PackageJson.preview = $true
143+
} else {
144+
$script:PackageJson.name = "powershell"
145+
$script:PackageJson.displayName = "PowerShell"
146+
$script:PackageJson.description = "Develop PowerShell scripts in Visual Studio Code!"
147+
$script:PackageJson.preview = $false
148+
}
149+
150+
$revision = if ($env:BUILD_BUILDID) { $env:BUILD_BUILDID } else { 9999 }
151+
$script:PackageJson.version = "$(Get-Date -Format 'yyyy.M').$revision"
152+
153+
$Utf8NoBomEncoding = [System.Text.UTF8Encoding]::new($false)
154+
[System.IO.File]::WriteAllLines(
155+
(Resolve-Path "$PSScriptRoot/package.json").Path,
156+
($script:PackageJson | ConvertTo-Json -Depth 100),
157+
$Utf8NoBomEncoding)
158+
}
159+
task Package UpdateReadme, UpdatePackageJson, {
106160

107161
if ($script:psesBuildScriptPath) {
108162
Write-Host "`n### Copying PowerShellEditorServices module files" -ForegroundColor Green
@@ -119,16 +173,12 @@ task Package {
119173
exec { & node ./node_modules/vsce/out/vsce package }
120174

121175
# Change the package to have a static name for automation purposes
122-
Move-Item -Force .\powershell-$($script:ExtensionVersion).vsix .\PowerShell-insiders.vsix
176+
Move-Item -Force .\$($script:PackageJson.name)-$($script:PackageJson.version).vsix .\PowerShell-insiders.vsix
123177
}
124178

125-
task UploadArtifacts {
126-
if ($env:TF_BUILD) {
127-
# SYSTEM_PHASENAME is the Job name.
128-
Copy-Item -Path PowerShell-insiders.vsix `
129-
-Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/powershell-$script:ExtensionVersion-$env:SYSTEM_PHASENAME.vsix"
130-
}
131-
}
179+
#endregion
132180

181+
# The set of tasks for a release
182+
task Release Clean, Build, Test, Package
133183
# The default task is to run the entire CI build
134-
task . GetExtensionVersion, BuildAll, Test, Package, UploadArtifacts
184+
task . Clean, BuildAll, Test, Package, UploadArtifacts

0 commit comments

Comments
 (0)