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

Adopt the pre-release extension feature #4462

Merged
merged 4 commits into from
Mar 15, 2023
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
7 changes: 4 additions & 3 deletions .vsts-ci/templates/ci-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ steps:
Install-Module InvokeBuild -Scope CurrentUser -Force
Install-Module platyPS -Scope CurrentUser -Force
Invoke-Build -Configuration Release
Write-Host "##vso[task.setvariable variable=vsixPath]$(Resolve-Path powershell-*.vsix)"
$PackageJson = Get-Content -Raw package.json | ConvertFrom-Json
Write-Host "##vso[task.setvariable variable=vsixPath]$(Resolve-Path powershell-$($PackageJson.version).vsix)"
workingDirectory: $(Build.SourcesDirectory)/vscode-powershell
pwsh: ${{ parameters.pwsh }}

Expand All @@ -81,9 +82,9 @@ steps:
inputs:
targetType: inline
script: |
$assembly = [Reflection.Assembly]::LoadFile("$(Build.SourcesDirectory)/vscode-powershell/modules/PowerShellEditorServices.VSCode/bin/Microsoft.PowerShell.EditorServices.VSCode.dll")
$assembly = [Reflection.Assembly]::LoadFile('$(Build.SourcesDirectory)/vscode-powershell/modules/PowerShellEditorServices.VSCode/bin/Microsoft.PowerShell.EditorServices.VSCode.dll')
if ($assembly.GetCustomAttributes([System.Diagnostics.DebuggableAttribute], $true).IsJITOptimizerDisabled) {
Write-Host "##vso[task.LogIssue type=error;] PowerShell Editor Services bits were not built in release configuration!"
Write-Host '##vso[task.LogIssue type=error;]PowerShell Editor Services bits were not built in release configuration!'
exit 1
}
pwsh: ${{ parameters.pwsh }}
Expand Down
3 changes: 2 additions & 1 deletion .vsts-ci/templates/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ steps:
displayName: Download signed artifacts

- pwsh: |
$PackageJson = Get-Content -Raw $(Build.SourcesDirectory)/package.json | ConvertFrom-Json
$(Build.SourcesDirectory)/tools/setupReleaseTools.ps1 -Token $(GitHubToken)
New-DraftRelease -RepositoryName vscode-powershell -Assets $(Pipeline.Workspace)/vscode-powershell/powershell-*.vsix,$(Pipeline.Workspace)/vscode-powershell/Install-VSCode.ps1
New-DraftRelease -RepositoryName vscode-powershell -Assets $(Pipeline.Workspace)/vscode-powershell/powershell-$($PackageJson.version).vsix,$(Pipeline.Workspace)/vscode-powershell/Install-VSCode.ps1
displayName: Drafting a GitHub Release
10 changes: 9 additions & 1 deletion .vsts-ci/templates/publish-markets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ steps:

- pwsh: |
npm ci --loglevel=error
npm run publish -- --packagePath $(Pipeline.Workspace)/vscode-powershell/powershell-*.vsix --pat $(VsceToken)
$PackageJson = Get-Content -Raw $(Build.SourcesDirectory)/package.json | ConvertFrom-Json
$PublishArgs = @(
if ($PackageJson.preview) { '--pre-release' }
'--packagePath'
"$(Pipeline.Workspace)/vscode-powershell/powershell-$($PackageJson.version).vsix"
'--pat'
'$(VsceToken)'
)
npm run publish -- @PublishArgs
displayName: Publishing VSIX to VS Code Marketplace

# NOTE: We rarely update this script, so we can ignore errors from the gallery
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "powershell-preview",
"displayName": "PowerShell Preview",
"name": "powershell",
"displayName": "PowerShell",
"version": "2023.3.0",
"preview": true,
"publisher": "ms-vscode",
"description": "(Preview) Develop PowerShell modules, commands and scripts in Visual Studio Code!",
"description": "Develop PowerShell modules, commands and scripts in Visual Studio Code!",
"engines": {
"vscode": "^1.67.0"
},
Expand Down
16 changes: 1 addition & 15 deletions tools/ReleaseTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ function Update-Changelog {
- package.json:
- `version` field with `"X.Y.Z"` and no prefix or suffix
- `preview` field set to `true` or `false` if version is a preview
- `name` field has `-preview` appended similarly
- `displayName` field has ` Preview` appended similarly
- `description` field has `(Preview) ` prepended similarly
- `icon` field has `_Preview ` inserted similarly
- `icon` field has `_Preview ` inserted if preview
#>
function Update-Version {
[CmdletBinding(SupportsShouldProcess)]
Expand All @@ -318,34 +315,23 @@ function Update-Version {

Update-Branch -RepositoryName $RepositoryName

# TODO: Maybe cleanup the replacement logic.
Use-Repository -RepositoryName $RepositoryName -Script {
switch ($RepositoryName) {
"vscode-powershell" {
$d = "Develop PowerShell modules, commands and scripts in Visual Studio Code!"
if ($Version.PreReleaseLabel) {
$name = "powershell-preview"
$displayName = "PowerShell Preview"
$preview = "true"
$description = "(Preview) $d"
$icon = "media/PowerShell_Preview_Icon.png"
} else {
$name = "powershell"
$displayName = "PowerShell"
$preview = "false"
$description = $d
$icon = "media/PowerShell_Icon.png"
}

$path = "package.json"
$f = Get-Content -Path $path
# NOTE: The prefix regex match two spaces exactly to avoid matching
# nested objects in the file.
$f = $f -replace '^(?<prefix> "name":\s+")(.+)(?<suffix>",)$', "`${prefix}${name}`${suffix}"
$f = $f -replace '^(?<prefix> "displayName":\s+")(.+)(?<suffix>",)$', "`${prefix}${displayName}`${suffix}"
$f = $f -replace '^(?<prefix> "version":\s+")(.+)(?<suffix>",)$', "`${prefix}${v}`${suffix}"
$f = $f -replace '^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$', "`${prefix}${preview}`${suffix}"
$f = $f -replace '^(?<prefix> "description":\s+")(.+)(?<suffix>",)$', "`${prefix}${description}`${suffix}"
$f = $f -replace '^(?<prefix> "icon":\s+")(.+)(?<suffix>",)$', "`${prefix}${icon}`${suffix}"
$f | Set-Content -Path $path
git add $path
Expand Down
49 changes: 18 additions & 31 deletions vscode-powershell.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ param(

# Grab package.json data which is used throughout the build.
$script:PackageJson = Get-Content -Raw $PSScriptRoot/package.json | ConvertFrom-Json
$script:IsPreviewExtension = $script:PackageJson.name -like "*preview*" -or $script:PackageJson.displayName -like "*preview*"
Write-Host "`n### Extension: $($script:PackageJson.name)-$($script:PackageJson.version)`n" -ForegroundColor Green

function Get-EditorServicesPath {
Expand All @@ -32,9 +31,9 @@ task RestoreNodeModules -If { !(Test-Path ./node_modules) } {
# When in a CI build use the --loglevel=error parameter so that
# package install warnings don't cause PowerShell to throw up
if ($env:TF_BUILD) {
exec { & npm ci --loglevel=error }
Invoke-BuildExec { & npm ci --loglevel=error }
} else {
exec { & npm install }
Invoke-BuildExec { & npm install }
}
}

Expand All @@ -45,7 +44,7 @@ task RestoreEditorServices -If (Get-EditorServicesPath) {
# that developers always have the latest local bits.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -ne "SymbolicLink") {
Write-Host "`n### Creating symbolic link to PSES" -ForegroundColor Green
remove ./modules
Remove-BuildItem ./modules
New-Item -ItemType SymbolicLink -Path ./modules -Target "$(Split-Path (Get-EditorServicesPath))/module"
}

Expand All @@ -57,7 +56,7 @@ task RestoreEditorServices -If (Get-EditorServicesPath) {
# and only if they don't already exist.
if ((Get-Item ./modules -ErrorAction SilentlyContinue).LinkType -eq "SymbolicLink") {
Write-Host "`n### Deleting PSES symbolic link" -ForegroundColor Green
remove ./modules
Remove-BuildItem ./modules
}

if (!(Test-Path ./modules)) {
Expand All @@ -81,7 +80,7 @@ task Restore RestoreEditorServices, RestoreNodeModules

task Clean {
Write-Host "`n### Cleaning vscode-powershell`n" -ForegroundColor Green
remove ./modules, ./out, ./node_modules, *.vsix
Remove-BuildItem ./modules, ./out, ./node_modules, *.vsix
}

task CleanEditorServices -If (Get-EditorServicesPath) {
Expand All @@ -94,9 +93,9 @@ task CleanEditorServices -If (Get-EditorServicesPath) {

task Build Restore, {
Write-Host "`n### Building vscode-powershell`n" -ForegroundColor Green
assert (Test-Path ./modules/PowerShellEditorServices/bin) "Extension requires PSES"
Assert-Build (Test-Path ./modules/PowerShellEditorServices/bin) "Extension requires PSES"

exec { & npm run lint }
Invoke-BuildExec { & npm run lint }

# TODO: When supported we should use `esbuild` for the tests too. Although
# we now use `esbuild` to transpile, bundle, and minify the extension, we
Expand All @@ -105,8 +104,8 @@ task Build Restore, {
# Unfortunately `esbuild` doesn't support emitting 1:1 files (yet).
# https://github.com/evanw/esbuild/issues/944
switch ($Configuration) {
"Debug" { exec { & npm run build -- --sourcemap } }
"Release" { exec { & npm run build -- --minify } }
"Debug" { Invoke-BuildExec { & npm run build -- --sourcemap } }
"Release" { Invoke-BuildExec { & npm run build -- --minify } }
}
}

Expand All @@ -115,9 +114,9 @@ task Build Restore, {

task Test -If (!($env:TF_BUILD -and $global:IsLinux)) Build, {
Write-Host "`n### Running extension tests" -ForegroundColor Green
exec { & npm run test }
Invoke-BuildExec { & npm run test }
# Reset the state of files modified by tests
exec { git checkout package.json test/.vscode/settings.json}
Invoke-BuildExec { git checkout package.json test/.vscode/settings.json}
}

task TestEditorServices -If (Get-EditorServicesPath) {
Expand All @@ -128,26 +127,14 @@ task TestEditorServices -If (Get-EditorServicesPath) {
#endregion
#region Package tasks

task UpdateReadme -If { $script:IsPreviewExtension } {
# 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.
> ### 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")
> ## 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)'
$readmePath = (Join-Path $PSScriptRoot README.md)

$readmeContent = Get-Content -Path $readmePath
if (!($readmeContent -match "This is the PREVIEW version of the PowerShell extension")) {
$readmeContent[0] = $newReadmeTop
$readmeContent | Set-Content $readmePath -Encoding utf8
}
}

task Package UpdateReadme, Build, {
task Package Build, {
Write-Host "`n### Packaging $($script:PackageJson.name)-$($script:PackageJson.version).vsix`n" -ForegroundColor Green
assert ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
exec { & npm run package }
Assert-Build ((Get-Item ./modules).LinkType -ne "SymbolicLink") "Packaging requires a copy of PSES, not a symlink!"
if ($script:PackageJson.preview) {
Invoke-BuildExec { & npm run package -- --pre-release }
} else {
Invoke-BuildExec { & npm run package }
}
}

#endregion
Expand Down