From 001966b770f86e6d323158e34b91db743dfbabc8 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Jul 2021 14:48:51 -0700 Subject: [PATCH 1/5] Fix emoji output in changelog to exactly two --- docs/development.md | 4 +--- tools/ReleaseTools.psm1 | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/development.md b/docs/development.md index 914fe5d4bf..119b7a5866 100644 --- a/docs/development.md +++ b/docs/development.md @@ -98,7 +98,7 @@ For PowerShellEditor Services, we simply follow semantic versioning, e.g. generally used directly: it's a library consumed by other projects which themselves use preview releases for beta testing. -For the VS Code PowerShell Extension, our version follows `vYYYY.MM.X`, that is: +For the VS Code PowerShell Extension, our version follows `vYYYY.M.X`, that is: current year, current month, and patch version (not day). This is not semantic versioning because of issues with how the VS Code marketplace and extension hosting API itself uses our version number. This scheme _does not_ mean we @@ -137,7 +137,5 @@ use the same code which includes dependencies). * `Update-Changelog` should verify the version is in the correct format * `Update-Changelog` could be faster by not downloading _every_ PR -* `Update-Changelog` should use exactly two emoji and in the right order * `Update-Version` could be run by `Update-Changelog` -* The build should emit an appropriately named VSIX instead of us manually renaming it * A `Publish-Binaries` function could be written to push the binaries out diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index e80789c5a1..fcb08d8686 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -37,10 +37,13 @@ function Get-Bullets { 'TylerLeonhardt' ) - $LabelEmoji = @{ + $IssueEmojis = @{ 'Issue-Enhancement' = '✨' 'Issue-Bug' = '🐛' 'Issue-Performance' = '⚡️' + } + + $AreaEmojis = @{ 'Area-Build & Release' = '👷' 'Area-Code Formatting' = '💎' 'Area-Configuration' = '🔧' @@ -81,12 +84,9 @@ function Get-Bullets { process { $PullRequests | ForEach-Object { # Map all the labels to emoji (or use a default). - # NOTE: Whitespacing here is weird. - $emoji = if ($_.labels) { - $LabelEmoji[$_.labels.LabelName] -join "" - } else { - '#️⃣ 🙏' - } + $labels = if ($_.labels) { $_.labels.LabelName } else { "" } + $issueEmoji = $IssueEmojis[$labels] + "#️⃣" | Select-Object -First 1 + $areaEmoji = $AreaEmojis[$labels] + "🙏" | Select-Object -First 1 # Get a linked issue number if it exists (or use the PR). $link = if ($_.body -match $IssueRegex) { @@ -105,7 +105,7 @@ function Get-Bullets { } # Put the bullet point together. - ("-", $emoji, "[$link]($($_.html_url))", "-", "$($_.title).", $thanks -join " ").Trim() + ("-", $issueEmoji, $areaEmoji, "[$link]($($_.html_url))", "-", "$($_.title).", $thanks -join " ").Trim() } } } @@ -250,18 +250,18 @@ function Update-Changelog { .DESCRIPTION Note that our Git tags and changelog prefix all versions with `v`. - PowerShellEditorServices: version is `x.y.z-preview.d` + PowerShellEditorServices: version is `X.Y.Z-preview` - PowerShellEditorServices.psd1: - - `ModuleVersion` variable with `'x.y.z'` string, no pre-release info + - `ModuleVersion` variable with `'X.Y.Z'` string, no pre-release info - PowerShellEditorServices.Common.props: - - `VersionPrefix` field with `x.y.z` + - `VersionPrefix` field with `X.Y.Z` - `VersionSuffix` field with pre-release portion excluding hyphen - vscode-powershell: version is `yyyy.mm.x-preview` + vscode-powershell: version is `YYYY.M.X-preview` - package.json: - - `version` field with `"x.y.z"` and no prefix or suffix + - `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 From b7e1cf0081e0bdc7c7be65b3fbc77bee834f90eb Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Jul 2021 14:50:30 -0700 Subject: [PATCH 2/5] Fix `$Assets` parameter for `New-DraftRelease` Can't pass string array directly from pipeline. --- docs/development.md | 9 +++------ tools/ReleaseTools.psm1 | 4 +++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/development.md b/docs/development.md index 119b7a5866..5e2ab37bf1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -73,13 +73,10 @@ Update-Version -RepositoryName vscode-powershell # Push branches to GitHub and ADO # Open PRs for review # Download and test assets (assert correct PSES is included) -New-DraftRelease -RepositoryName PowerShellEditorServices -New-DraftRelease -RepositoryName vscode-powershell -# Point releases to branches for automatic tagging -# Upload PowerShellEditorServices.zip (for other extensions) -# Upload VSIX and Install-VSCode.ps1 -# Publish draft releases and merge (don't squash!) branches +New-DraftRelease -RepositoryName PowerShellEditorServices -Assets "PowerShellEditorServices.zip" +New-DraftRelease -RepositoryName vscode-powershell -Assets "powershell-YYYY.M.X.vsix", "Install-VSCode.ps1" # Check telemetry for stability before releasing +# Publish draft releases and merge (don't squash!) branches vsce publish --packagePath ./PowerShell-.vsix # Update Install-VSCode.ps1 on gallery Publish-Script -Path ./Install-VSCode.ps1 -NuGetApiKey (Get-Secret "PowerShell Gallery API Key" -AsPlainText) diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index fcb08d8686..b9b8602dbb 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -344,7 +344,7 @@ function New-DraftRelease { [ValidateSet([RepoNames])] [string]$RepositoryName, - [Parameter(ValueFromPipeline)] + [Parameter()] [string[]]$Assets ) $Version = Get-Version -RepositoryName $RepositoryName @@ -362,5 +362,7 @@ function New-DraftRelease { } $Release = New-GitHubRelease @ReleaseParams + Write-Output "Draft release URL: $($Release.html_url)" + Write-Output "Uploading assets..." $Assets | New-GitHubReleaseAsset -Release $Release.Id } From 6bba3ae7487ab130a150790d4383773d3b64abc6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Jul 2021 13:21:37 -0700 Subject: [PATCH 3/5] Change release build pool --- .vsts-ci/azure-pipelines-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vsts-ci/azure-pipelines-release.yml b/.vsts-ci/azure-pipelines-release.yml index 4fe28b4646..e71f8b2555 100644 --- a/.vsts-ci/azure-pipelines-release.yml +++ b/.vsts-ci/azure-pipelines-release.yml @@ -31,8 +31,8 @@ jobs: - job: 'ReleaseBuild' displayName: 'Build release' pool: - name: 'Package ES Standard Build' - demands: DotNetFramework + name: '1ES' + demands: ImageOverride -equals MMS2019 variables: - group: ESRP steps: From 79345045a4e78f536d3d6b17136bec9f42436298 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Jul 2021 14:44:17 -0700 Subject: [PATCH 4/5] Update version and create PR automatically in `ReleaseTools` module --- docs/development.md | 5 ----- tools/ReleaseTools.psm1 | 48 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/docs/development.md b/docs/development.md index 5e2ab37bf1..25acdd7308 100644 --- a/docs/development.md +++ b/docs/development.md @@ -68,10 +68,6 @@ Import-Module ./tools/ReleaseTools.psm1 Update-Changelog -RepositoryName PowerShellEditorServices -Version Update-Changelog -RepositoryName vscode-powershell -Version # Amend changelog as necessary -Update-Version -RepositoryName PowerShellEditorServices -Update-Version -RepositoryName vscode-powershell -# Push branches to GitHub and ADO -# Open PRs for review # Download and test assets (assert correct PSES is included) New-DraftRelease -RepositoryName PowerShellEditorServices -Assets "PowerShellEditorServices.zip" New-DraftRelease -RepositoryName vscode-powershell -Assets "powershell-YYYY.M.X.vsix", "Install-VSCode.ps1" @@ -134,5 +130,4 @@ use the same code which includes dependencies). * `Update-Changelog` should verify the version is in the correct format * `Update-Changelog` could be faster by not downloading _every_ PR -* `Update-Version` could be run by `Update-Changelog` * A `Publish-Binaries` function could be written to push the binaries out diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index b9b8602dbb..a883c91206 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -202,8 +202,7 @@ function Update-Changelog { Where-Object { -not $_.user.UserName.EndsWith("[bot]") } | Where-Object { "Ignore" -notin $_.labels.LabelName } | Where-Object { -not $_.title.StartsWith("[Ignore]") } | - Where-Object { -not $_.title.StartsWith("Update CHANGELOG") } | - Where-Object { -not $_.title.StartsWith("Bump version") } | + Where-Object { -not $_.title.StartsWith("Release ``v") } | Get-Bullets -RepositoryName $RepositoryName $NewSection = switch ($RepositoryName) { @@ -242,6 +241,8 @@ function Update-Changelog { } Pop-Location + + Update-Version -RepositoryName $RepositoryName } <# @@ -328,6 +329,49 @@ function Update-Version { } Pop-Location + + New-ReleasePR -RepositoryName $RepositoryName +} + +<# +.SYNOPSIS + Creates a new draft GitHub PR from the release branch. +.DESCRIPTION + Pushes the release branch to `origin` and then opens a draft PR. +#> +function New-ReleasePR { + 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 + $Branch = "release/v$Version" + Update-Branch -Version $Version + Write-Output "Pushing branch ``$Branch``..." + git push origin $Branch + + $LabelParams = @{ + OwnerName = "PowerShell" + RepositoryName = $RepositoryName + Label = "Ignore" + } + + $PRParams = @{ + Head = $Branch + Base = "master" + Draft = $true + Title = "Release ``v$Version``" + Body = "Automated PR for new release!" + } + + $PR = Get-GitHubLabel @LabelParams | New-GitHubPullRequest @PRParams + Write-Output "Draft PR URL: $($PR.html_url)" + + Pop-Location } <# From 2bf2359881e939cdd00f2cb78e29f78060086fd6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Jul 2021 15:58:53 -0700 Subject: [PATCH 5/5] Support `WhatIf` and `Confirm` better in `ReleaseTools` module --- tools/ReleaseTools.psm1 | 76 +++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 index a883c91206..907be306e8 100644 --- a/tools/ReleaseTools.psm1 +++ b/tools/ReleaseTools.psm1 @@ -139,13 +139,17 @@ function Get-FirstChangelog { Creates and checks out `release/v` if not already on it. #> function Update-Branch { + [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$Version ) - $branch = git branch --show-current - if ($branch -ne "release/v$Version") { - git checkout -b "release/v$Version" + $Branch = git branch --show-current + $NewBranch = "release/v$Version" + if ($Branch -ne $NewBranch) { + if ($PSCmdlet.ShouldProcess($NewBranch, "git checkout -b")) { + git checkout -b $NewBranch + } } } @@ -234,15 +238,16 @@ function Update-Changelog { $CurrentChangelog[2..$CurrentChangelog.Length] ) | Set-Content -Encoding utf8NoBOM -Path $ChangelogFile - if ($PSCmdlet.ShouldProcess("$RepositoryName/$ChangelogFile", "git")) { - Update-Branch -Version $Version.Substring(1) # Has "v" prefix + Update-Branch -Version $Version.Substring(1) # Has "v" prefix + + if ($PSCmdlet.ShouldProcess("$RepositoryName/$ChangelogFile", "git commit")) { git add $ChangelogFile git commit -m "Update CHANGELOG for ``$Version``" } - Pop-Location - Update-Version -RepositoryName $RepositoryName + + Pop-Location } <# @@ -323,14 +328,15 @@ function Update-Version { } } + Update-Branch -Version $Version + if ($PSCmdlet.ShouldProcess("$RepositoryName/v$Version", "git commit")) { - Update-Branch -Version $Version git commit -m "Bump version to ``v$Version``" - } - - Pop-Location + } # TODO: Git reset to unstage New-ReleasePR -RepositoryName $RepositoryName + + Pop-Location } <# @@ -340,6 +346,7 @@ function Update-Version { Pushes the release branch to `origin` and then opens a draft PR. #> function New-ReleasePR { + [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [ValidateSet([RepoNames])] @@ -350,9 +357,13 @@ function New-ReleasePR { $Version = Get-Version -RepositoryName $RepositoryName $Branch = "release/v$Version" + Update-Branch -Version $Version - Write-Output "Pushing branch ``$Branch``..." - git push origin $Branch + + if ($PSCmdlet.ShouldProcess("$RepositoryName/$Branch", "git push")) { + Write-Host "Pushing branch ``$Branch``..." + git push origin $Branch + } $LabelParams = @{ OwnerName = "PowerShell" @@ -361,15 +372,17 @@ function New-ReleasePR { } $PRParams = @{ - Head = $Branch - Base = "master" - Draft = $true - Title = "Release ``v$Version``" - Body = "Automated PR for new release!" + Head = $Branch + Base = "master" + Draft = $true + Title = "Release ``v$Version``" + Body = "Automated PR for new release!" + WhatIf = $WhatIfPreference + Confirm = $ConfirmPreference } $PR = Get-GitHubLabel @LabelParams | New-GitHubPullRequest @PRParams - Write-Output "Draft PR URL: $($PR.html_url)" + Write-Host "Draft PR URL: $($PR.html_url)" Pop-Location } @@ -383,6 +396,7 @@ function New-ReleasePR { are prefixed with a `v`. Creates a Git tag if it does not already exist. #> function New-DraftRelease { + [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [ValidateSet([RepoNames])] @@ -394,19 +408,23 @@ function New-DraftRelease { $Version = Get-Version -RepositoryName $RepositoryName $Changelog = (Get-FirstChangelog -RepositoryName $RepositoryName) -join "`n" $ReleaseParams = @{ - Draft = $true # NOTE: We rely on GitHub to create the tag at that branch. - Tag = "v$Version" - Committish = "release/v$Version" - Name = "v$Version" - Body = $ChangeLog - PreRelease = [bool]$Version.PreReleaseLabel - OwnerName = "PowerShell" + Tag = "v$Version" + Committish = "release/v$Version" + Name = "v$Version" + Body = $ChangeLog + Draft = $true + PreRelease = [bool]$Version.PreReleaseLabel + OwnerName = "PowerShell" RepositoryName = $RepositoryName + WhatIf = $WhatIfPreference + Confirm = $ConfirmPreference } $Release = New-GitHubRelease @ReleaseParams - Write-Output "Draft release URL: $($Release.html_url)" - Write-Output "Uploading assets..." - $Assets | New-GitHubReleaseAsset -Release $Release.Id + if ($Release) { + Write-Host "Draft release URL: $($Release.html_url)" + Write-Host "Uploading assets..." + $Assets | New-GitHubReleaseAsset -Release $Release.Id + } }