From b5a2690787b98ab5d1a73b04e41b929c7629fc29 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Apr 2021 15:47:47 -0700 Subject: [PATCH 1/4] Add `Update-Version` function to `ReleaseTools` module --- tools/ReleaseTools.psm1 | 91 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index 670db5ccb1..323207cf93 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -206,6 +206,95 @@ function Update-Changelog { Pop-Location } +<# +.SYNOPSIS + Updates version in repository. +.DESCRIPTION + Note that our Git tags and changelog prefix all versions with `v`. + + PowerShellEditorServices: version is `x.y.z-preview.d` + + - PowerShellEditorServices.psd1: + - `ModuleVersion` variable with `'x.y.z'` string, no pre-release info + - PowerShellEditorServices.Common.props: + - `VersionPrefix` field with `x.y.z` + - `VersionSuffix` field with pre-release portion excluding hyphen + + vscode-powershell: version is `yyyy.mm.x-preview` + + - 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 +#> +function Update-Version { + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [ValidateSet([RepoNames])] + [string]$RepositoryName + ) + # NOTE: This a side effect neccesary for Git operations to work. + Push-Location -Path "$PSScriptRoot/../../$RepositoryName" + + $Version = Get-Version -RepositoryName $RepositoryName + $v = "$($Version.Major).$($Version.Minor).$($Version.Patch)" + # TODO: Maybe cleanup the replacement logic. + switch ($RepositoryName) { + "vscode-powershell" { + $d = "Develop PowerShell scripts in Visual Studio Code!" + if ($Version.PreReleaseLabel) { + $name = "powershell-preview" + $displayName = "PowerShell Preview" + $preview = "true" + $description = "(Preview) $d" + } else { + $name = "powershell" + $displayName = "PowerShell" + $preview = "false" + $description = $d + } + $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 '^(? "name":\s+")(.+)(?",)$', "`${prefix}${name}`${suffix}" + $f = $f -replace '^(? "displayName":\s+")(.+)(?",)$', "`${prefix}${displayName}`${suffix}" + $f = $f -replace '^(? "version":\s+")(.+)(?",)$', "`${prefix}${v}`${suffix}" + $f = $f -replace '^(? "preview":\s+)(.+)(?,)$', "`${prefix}${preview}`${suffix}" + $f = $f -replace '^(? "description":\s+")(.+)(?",)$', "`${prefix}${description}`${suffix}" + $f | Set-Content -Path $path + git add $path + } + "PowerShellEditorServices" { + $path = "PowerShellEditorServices.Common.props" + $f = Get-Content -Path $path + $f = $f -replace '^(?\s+)(.+)(?)$', "`${prefix}${v}`${suffix}" + $f = $f -replace '^(?\s+)(.*)(?)$', "`${prefix}$($Version.PreReleaseLabel)`${suffix}" + $f | Set-Content -Path $path + git add $path + + $path = "module/PowerShellEditorServices/PowerShellEditorServices.psd1" + $f = Get-Content -Path $path + $f = $f -replace "^(?ModuleVersion = ')(.+)(?')`$", "`${prefix}${v}`${suffix}" + $f | Set-Content -Path $path + git add $path + } + } + + if ($PSCmdlet.ShouldProcess("$RepositoryName/v$Version", "git commit")) { + git commit -m "Bump version to v$Version" + } + + if ($PSCmdlet.ShouldProcess("$RepositoryName/v$Version", "git tag")) { + git tag "v$Version" + } + + Pop-Location +} + <# .SYNOPSIS Creates a new draft GitHub release from the updated changelog. @@ -237,4 +326,4 @@ function New-DraftRelease { New-GitHubRelease @ReleaseParams } -Export-ModuleMember -Function Update-Changelog, New-DraftRelease +Export-ModuleMember -Function Update-Changelog, Update-Version, New-DraftRelease From 9b7ce0eb6dc598c6dc1637a8203b2c74c13364ad Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Apr 2021 20:46:45 -0700 Subject: [PATCH 2/4] Delete old `updateExtensionVersions` script --- .../updateExtensionVersions.ps1 | 244 ------------------ 1 file changed, 244 deletions(-) delete mode 100644 tools/postReleaseScripts/updateExtensionVersions.ps1 diff --git a/tools/postReleaseScripts/updateExtensionVersions.ps1 b/tools/postReleaseScripts/updateExtensionVersions.ps1 deleted file mode 100644 index a420ee253c..0000000000 --- a/tools/postReleaseScripts/updateExtensionVersions.ps1 +++ /dev/null @@ -1,244 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -#requires -Version 6.0 - -[CmdletBinding(DefaultParameterSetName='Increment')] -param( - [Parameter(ParameterSetName='Increment')] - [ValidateSet('Major', 'Minor', 'Patch', 'Preview')] - [string] - $IncrementLevel = 'Preview', - - [Parameter(Mandatory, ParameterSetName='SetVersion')] - [semver] - $NewVersion, - - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter()] - [string] - $TargetFork = 'PowerShell', - - [Parameter()] - [string] - # Default set below, requires processing when $IncrementVersion is used - $BranchName, - - [Parameter()] - [string] - # Default set below, requires processing when $IncrementVersion is used - $PRDescription -) - -Import-Module -Force "$PSScriptRoot/../FileUpdateTools.psm1" -Import-Module -Force "$PSScriptRoot/../GitHubTools.psm1" - -function FindPackageJsonVersionSpan -{ - param( - [Parameter(Mandatory)] - [string] - $PackageJsonContent - ) - - try - { - $reader = [System.IO.StringReader]::new($PackageJsonContent) - $jsonReader = [Newtonsoft.Json.JsonTextReader]::new($reader) - - $depth = 0 - $seenVersion = $false - $versionStartOffset = -1 - $versionStartColumn = -1 - while ($jsonReader.Read()) - { - switch ($jsonReader.TokenType) - { - 'StartObject' - { - $depth++ - continue - } - - 'EndObject' - { - $depth-- - continue - } - - 'PropertyName' - { - if ($depth -ne 1) - { - continue - } - - $seenVersion = $jsonReader.Value -eq 'version' - - if (-not $seenVersion) - { - continue - } - - $currIndex = Get-StringOffsetFromSpan -String $PackageJsonContent -EndLine $jsonReader.LineNumber -Column $jsonReader.LinePosition - $versionStartOffset = $PackageJsonContent.IndexOf('"', $currIndex) + 1 - $versionStartColumn = $jsonReader.LinePosition + $versionStartOffset - $currIndex - - continue - } - - 'String' - { - if (-not $seenVersion -or $depth -ne 1) - { - continue - } - - return @{ - Start = $versionStartOffset - End = $versionStartOffset + $jsonReader.LinePosition - $versionStartColumn - } - - continue - } - } - } - } - finally - { - $reader.Dispose() - $jsonReader.Dispose() - } - - throw 'Did not find package.json version field' -} - -function FindVstsBuildVersionSpan -{ - param( - [Parameter(Mandatory)] - [string] - $DockerFileContent - ) - - $pattern = [regex]'ENV VSTS_BUILD_VERSION=(.*)' - $versionGroup = $pattern.Match($DockerFileContent).Groups[1] - - return @{ - Start = $versionGroup.Index - End = $versionGroup.Index + $versionGroup.Length - } -} - -function UpdateDockerFileVersion -{ - param( - [Parameter(Mandatory)] - [string] - $DockerFilePath, - - [Parameter(Mandatory)] - [version] - $Version - ) - - $vstsDockerFileContent = Get-Content -Raw $DockerFilePath - $vstsDockerFileVersionSpan = FindVstsBuildVersionSpan -DockerFileContent $vstsDockerFileContent - $newDockerFileContent = New-StringWithSegment -String $vstsDockerFileContent -NewSegment $Version -StartIndex $vstsDockerFileVersionSpan.Start -EndIndex $vstsDockerFileVersionSpan.End - Set-Content -Path $DockerFilePath -Value $newDockerFileContent -Encoding utf8NoBOM -NoNewline -} - -function GetMarketplaceVersionFromSemVer -{ - [OutputType([version])] - param( - [Parameter(Mandatory)] - [semver] - $SemVer - ) - - if (-not $SemVer.PreReleaseLabel) - { - return [version]($SemVer.ToString()) - } - - return [version]::new($NewVersion.Major, $NewVersion.Minor, $NewVersion.PreReleaseLabel.Substring(8)-1) -} - -# Define locations/branch name -$repoLocation = Join-Path ([System.IO.Path]::GetTempPath()) 'vscps-updateversion-temp' -$paths = @{ - packageJson = "$repoLocation/package.json" - mainTs = "$repoLocation/src/main.ts" - vstsDockerFile = "$repoLocation/tools/releaseBuild/Image/DockerFile" -} - -# Clone the repo -$cloneParams = @{ - OriginRemote = 'https://github.com/rjmholt/vscode-powershell' - Destination = $repoLocation - Clobber = $true - Remotes = @{ - upstream = 'https://github.com/PowerShell/vscode-powershell' - } -} -Copy-GitRepository @cloneParams - -# We may need the version from the package.json, so get that first -$packageJson = Get-Content -Raw $paths.packageJson -$pkgJsonVersionOffsetSpan = FindPackageJsonVersionSpan -PackageJsonContent $packageJson - -# If the option was to increment, we take the existing version and increment it -if ($IncrementLevel) -{ - $version = [semver]$packageJson.Substring($pkgJsonVersionOffsetSpan.Start, $pkgJsonVersionOffsetSpan.End - $pkgJsonVersionOffsetSpan.Start) - $NewVersion = Get-IncrementedVersion -Version $version -IncrementLevel $IncrementLevel -} - -if (-not $BranchName) -{ - $BranchName = "update-version-$NewVersion" -} - -if (-not $PRDescription) -{ - $PRDescription = "Updates version strings in vscode-PowerShell to $NewVersion.`n**Note**: This is an automated PR." -} - -# Get the marketplace/non-semver versions for various files -$marketPlaceVersion = GetMarketplaceVersionFromSemVer -SemVer $NewVersion - -# Finally create the new package.json file -$newPkgJsonContent = New-StringWithSegment -String $packageJson -NewSegment $NewVersion -StartIndex $pkgJsonVersionOffsetSpan.Start -EndIndex $pkgJsonVersionOffsetSpan.End -Set-Content -Path $paths.packageJson -Value $newPkgJsonContent -Encoding utf8NoBOM -NoNewline - -# Create the new content for the VSTS dockerfile -UpdateDockerFileVersion -DockerFilePath $paths.vstsDockerFile -Version $marketPlaceVersion - -# Commit and push the changes -$commitParams = @{ - Message = "[Ignore] Increment version to $NewVersion" - Branch = $branchName - RepositoryLocation = $repoLocation - File = @( - 'package.json' - 'src/main.ts' - 'tools/releaseBuild/Image/DockerFile' - ) -} -Submit-GitChanges @commitParams - -# Open a new PR in GitHub -$prParams = @{ - Organization = $TargetFork - Repository = 'vscode-PowerShell' - Branch = $branchName - Title = "Update version to v$NewVersion" - Description = $PRDescription - GitHubToken = $GitHubToken - FromOrg = 'rjmholt' -} -New-GitHubPR @prParams From febfb33c9b13b9552b9ebf3019c533d7c9ce0574 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Apr 2021 21:21:18 -0700 Subject: [PATCH 3/4] Ignore changelog and version bumps when updating changelog --- tools/ReleaseTools.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index 323207cf93..ed9e36cacb 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -167,6 +167,8 @@ function Update-Changelog { Where-Object { $_.merge_commit_sha -in $Commits } | Where-Object { -not $_.user.UserName.EndsWith("[bot]") } | Where-Object { -not $_.title.StartsWith("[Ignore]") } | + Where-Object { -not $_.title.StartsWith("Update CHANGELOG") } | + Where-Object { -not $_.title.StartsWith("Bump version") } | Get-Bullets -RepositoryName $RepositoryName $NewSection = switch ($RepositoryName) { From 818ad2fc558cb4aea6be81e4ff92e47f45bdcd63 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Apr 2021 21:24:37 -0700 Subject: [PATCH 4/4] Get all PRs so pending can be included in changelog Useful when prepping, but use with caution. --- tools/ReleaseTools.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index ed9e36cacb..829d783038 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -162,8 +162,8 @@ function Update-Changelog { $Release = $Repo | Get-GitHubRelease -Latest $Commits = git rev-list "$($Release.tag_name)..." - # NOTE: This is a slow API as it gets all closed PRs, and then filters. - $Bullets = $Repo | Get-GitHubPullRequest -State Closed | + # NOTE: This is a slow API as it gets all PRs, and then filters. + $Bullets = $Repo | Get-GitHubPullRequest -State All | Where-Object { $_.merge_commit_sha -in $Commits } | Where-Object { -not $_.user.UserName.EndsWith("[bot]") } | Where-Object { -not $_.title.StartsWith("[Ignore]") } |