Skip to content
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

Refactor build script and default to preview #1911

Merged
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
34 changes: 29 additions & 5 deletions .vsts-ci/azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
trigger:
- master
- legacy/1.x
name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)

variables:
# Don't download unneeded packages
# Don't download unneeded packages
- name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE
value: 'true'
# Don't send telemetry
# Improve performance by not sending telemetry
- name: DOTNET_CLI_TELEMETRY_OPTOUT
value: 'true'

trigger:
batch: true
branches:
include:
- master
- legacy/1.x
paths:
exclude:
- /.dependabot/*
- /.poshchan/*
- /.github/**/*
- /.vscode/**/*
- /.vsts-ci/misc-analysis.yml
- /tools/**/*
- .editorconfig
- .gitattributes
- .gitignore
- /docs/**/*
- /CHANGELOG.md
- /CONTRIBUTING.md
- /README.md
- /LICENSE
- /CODE_OF_CONDUCT.md

jobs:
- job: Windows
pool:
Expand Down
3 changes: 3 additions & 0 deletions .vsts-ci/templates/ci-general.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
steps:
# Setup
- pwsh: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))"
displayName: Set Build Name for Non-PR
condition: ne(variables['Build.Reason'], 'PullRequest')
- pwsh: |
git clone https://github.com/PowerShell/PowerShellEditorServices.git ../PowerShellEditorServices
Install-Module InvokeBuild -Scope CurrentUser -Force
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "powershell",
"displayName": "PowerShell",
"version": "2.0.2",
"name": "powershell-preview",
"displayName": "PowerShell Preview",
"version": "2.0.0-preview.3",
"preview": true,
"publisher": "ms-vscode",
"description": "Develop PowerShell scripts in Visual Studio Code!",
"description": "(Preview) Develop PowerShell scripts in Visual Studio Code!",
"engines": {
"vscode": "^1.31.0"
},
Expand Down
2 changes: 1 addition & 1 deletion tools/releaseBuild/Image/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ else {
}
}
push-location C:/vscode-powershell
Invoke-Build GetExtensionData,Clean,Build,Test,CheckPreview,Package
Invoke-Build Release
Copy-Item -Verbose -Recurse "C:/vscode-powershell/PowerShell-insiders.vsix" "${target}/PowerShell-insiders.vsix"
Copy-Item -Verbose -Recurse "C:/vscode-powershell/scripts/Install-VSCode.ps1" "${target}/Install-VSCode.ps1"
115 changes: 70 additions & 45 deletions vscode-powershell.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,13 @@ param(

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

task GetExtensionData -Before Package {

$script:PackageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
$updateVersion = $false
$script:ExtensionVersion = `
if ($env:VSTS_BUILD) {
$updateVersion = $true
$env:VSTS_BUILD_VERSION
}
else {
$script:PackageJson.version
}

if ($updateVersion) {
exec { & npm version $script:ExtensionVersion --no-git-tag-version --allow-same-version }
$script:PackageJson.version = $script:ExtensionVersion
}
# Grab package.json data which is used throughout the build.
$script:PackageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
Write-Host "`n### Extension Version: $($script:PackageJson.version) Extension Name: $($script:PackageJson.name)`n" -ForegroundColor Green

$script:ExtensionName = $script:PackageJson.name
Write-Host "`n### Extension Version: $script:ExtensionVersion Extension Name: $script:ExtensionName`n" -ForegroundColor Green
}
#region Utility tasks

task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices, Package {
task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices, TestEditorServices, Package {

$script:psesRepoPath = `
if ($EditorServicesRepoPath) {
Expand All @@ -43,7 +27,7 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices,

if (!(Test-Path $script:psesRepoPath)) {
# Clear the path so that it won't be used
Write-Host "`n### WARNING: The PowerShellEditorServices repo cannot be found at path $script:psesRepoPath`n" -ForegroundColor Yellow
Write-Warning "`nThe PowerShellEditorServices repo cannot be found at path $script:psesRepoPath`n"
$script:psesRepoPath = $null
}
else {
Expand All @@ -52,7 +36,18 @@ task ResolveEditorServicesPath -Before CleanEditorServices, BuildEditorServices,
}
}

task Restore RestoreNodeModules -Before Build -If { -not (Test-Path "$PSScriptRoot/node_modules") }
task UploadArtifacts {
if ($env:TF_BUILD) {
# SYSTEM_PHASENAME is the Job name.
Copy-Item -Path PowerShell-insiders.vsix `
-Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$($script:PackageJson.name)-$($script:PackageJson.version)-$env:SYSTEM_PHASENAME.vsix"
}
}

#endregion
#region Restore tasks

task Restore RestoreNodeModules -If { -not (Test-Path "$PSScriptRoot/node_modules") }

task RestoreNodeModules {

Expand All @@ -64,6 +59,9 @@ task RestoreNodeModules {
exec { & npm install $logLevelParam }
}

#endregion
#region Clean tasks

task Clean {
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
Remove-Item .\modules\* -Exclude "README.md" -Recurse -Force -ErrorAction Ignore
Expand All @@ -80,7 +78,10 @@ task CleanEditorServices {

task CleanAll CleanEditorServices, Clean

task Build {
#endregion
#region Build tasks

task Build Restore, {
Write-Host "`n### Building vscode-powershell" -ForegroundColor Green
exec { & npm run compile }
}
Expand All @@ -95,20 +96,34 @@ task BuildEditorServices {

task BuildAll BuildEditorServices, Build

#endregion
#region Test tasks

task Test Build, {
if (!$global:IsLinux) {
Write-Host "`n### Running extension tests" -ForegroundColor Green
exec { & npm run test }
}
else {
Write-Host "`n### Skipping extension tests on Linux platform" -ForegroundColor Yellow
Write-Warning "Skipping extension tests on Linux platform because vscode does not support it."
}
}

task CheckPreview -If { $script:ExtensionName -like "*Preview*" } `
UpdateReadme, UpdatePackageJson
task TestEditorServices {
if ($script:psesBuildScriptPath) {
Write-Host "`n### Testing PowerShellEditorServices`n" -ForegroundColor Green
Invoke-Build Test $script:psesBuildScriptPath
}
}

task TestAll TestEditorServices, Test

task UpdateReadme {
#endregion

#region Package tasks

task UpdateReadme -If { $script:PackageJson.version -like "*preview*" } {
# Add the preview text
$newReadmeTop = '# PowerShell Language Support for Visual Studio Code

> ## 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.
Expand All @@ -119,20 +134,34 @@ task UpdateReadme {
$readmeContent = Get-Content -Path $readmePath
if (!($readmeContent -match "This is the PREVIEW version of the PowerShell extension")) {
$readmeContent[0] = $newReadmeTop
$readmeContent > $readmePath
$readmeContent | Set-Content $readmePath -Encoding utf8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we're putting a BOM in right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm not sure what the default is for this... but I could put utf8NoBOM. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bergmeister!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is UTF8NoBOM in PSCore, but to make it work in Windows PowerShell too I think we have to fall back to .NET

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we might not need this to work in Windows PowerShell

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to WriteAllLines .NET API to support Windows PowerShell

Copy link
Contributor

@bergmeister bergmeister Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can we not drop WindowsPowerShell for building purposes only? Developers are not users and I added a pwsh switch to the Azure DevOps task last year and it seems we are not using AppVeyor any more.
I was thinking of changing this line here to use use pwsh instead lately btw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably want to move to pwsh only for building, but I suspect currently we just pick a PowerShell and stick with it. So what @TylerLeonhardt's got is safest for now.

}
}

task UpdatePackageJson {
$script:PackageJson.name = "powershell-preview"
$script:PackageJson.displayName = "PowerShell Preview"
$script:PackageJson.description = "(Preview) Develop PowerShell scripts in Visual Studio Code!"
$script:PackageJson.preview = $true
$script:ExtensionName = $script:PackageJson.name
Set-Content -Path $PSScriptRoot/package.json ($script:PackageJson | ConvertTo-Json -Depth 100)
if ($script:PackageJson.version -like "*preview*") {
$script:PackageJson.name = "powershell-preview"
$script:PackageJson.displayName = "PowerShell Preview"
$script:PackageJson.description = "(Preview) Develop PowerShell scripts in Visual Studio Code!"
$script:PackageJson.preview = $true
} else {
$script:PackageJson.name = "powershell"
$script:PackageJson.displayName = "PowerShell"
$script:PackageJson.description = "Develop PowerShell scripts in Visual Studio Code!"
$script:PackageJson.preview = $false
}

$revision = if ($env:BUILD_BUILDID) { $env:BUILD_BUILDID } else { 9999 }
$script:PackageJson.version = "$(Get-Date -Format 'yyyy.M').$revision"

$Utf8NoBomEncoding = [System.Text.UTF8Encoding]::new($false)
[System.IO.File]::WriteAllLines(
(Resolve-Path "$PSScriptRoot/package.json").Path,
($script:PackageJson | ConvertTo-Json -Depth 100),
$Utf8NoBomEncoding)
}

task Package {
task Package UpdateReadme, UpdatePackageJson, {

if ($script:psesBuildScriptPath) {
Write-Host "`n### Copying PowerShellEditorServices module files" -ForegroundColor Green
Expand All @@ -149,16 +178,12 @@ task Package {
exec { & node ./node_modules/vsce/out/vsce package }

# Change the package to have a static name for automation purposes
Move-Item -Force .\$($script:ExtensionName)-$($script:ExtensionVersion).vsix .\PowerShell-insiders.vsix
Move-Item -Force .\$($script:PackageJson.name)-$($script:PackageJson.version).vsix .\PowerShell-insiders.vsix
}

task UploadArtifacts {
if ($env:TF_BUILD) {
# SYSTEM_PHASENAME is the Job name.
Copy-Item -Path PowerShell-insiders.vsix `
-Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$script:ExtensionName-$script:ExtensionVersion-$env:SYSTEM_PHASENAME.vsix"
}
}
#endregion

# The set of tasks for a release
task Release Clean, Build, Test, Package
# The default task is to run the entire CI build
task . GetExtensionData, CleanAll, BuildAll, Test, CheckPreview, Package, UploadArtifacts
task . CleanAll, BuildAll, Test, Package, UploadArtifacts