diff --git a/tools/ChangelogTools.psm1 b/tools/ChangelogTools.psm1 deleted file mode 100644 index ad07ed1ce7..0000000000 --- a/tools/ChangelogTools.psm1 +++ /dev/null @@ -1,401 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -#requires -Version 6.0 - -using module .\GitHubTools.psm1 - -class IgnoreConfiguration -{ - [string[]]$User - [string[]]$IssueLabel - [string[]]$PRLabel - [string[]]$CommitLabel -} - -class ChangeInfo -{ - [GitHubCommitInfo]$Commit - [GitHubPR]$PR - [GitHubIssue[]]$ClosedIssues - [int]$IssueNumber = -1 - [int]$PRNumber = -1 - [string]$ContributingUser - [string]$BodyText - [string]$Subject -} - -class ChangelogEntry -{ - [uri]$IssueLink - [uri]$PRLink - [string]$Category - [string[]]$Tags - [string]$BodyText - [string]$Subject - [string]$Thanks - [string]$RepositoryName - [ChangeInfo]$Change -} - -class ChangeLog -{ - ChangeLog() - { - $this.Sections = [System.Collections.Generic.Dictionary[string, ChangelogEntry]]::new() - } - - [string]$ReleaseName - [datetime]$Date - [string]$Preamble - [System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections -} - -function NormalizeSubject -{ - [OutputType([string])] - param( - [Parameter(Mandatory)] - [string] - $Subject - ) - - $Subject = $Subject.Trim() - if ([char]::IsLower($Subject[0])) { $Subject = [char]::ToUpper($Subject[0]) + $Subject.Substring(1) } - if ($Subject[$Subject.Length] -ne '.') { $Subject += '.' } - - return $Subject -} - -filter Get-ChangeInfoFromCommit -{ - [OutputType([ChangeInfo])] - param( - [Parameter(Mandatory, ValueFromPipeline, Position=0)] - [GitHubCommitInfo[]] - $Commit, - - [Parameter(Mandatory)] - [string] - $GitHubToken - ) - - foreach ($singleCommit in $Commit) - { - Write-Verbose "Getting change information for commit $($Commit.Hash)" - - $changelogItem = [ChangeInfo]@{ - Commit = $singleCommit - BodyText = $singleCommit.Body - Subject = $singleCommit.Subject - ContributingUser = $singleCommit.GitHubCommitData.author.login - } - - if ($Commit.PRNumber -ge 0) - { - $getPrParams = @{ - Organization = $singleCommit.Organization - Repository = $singleCommit.Repository - PullNumber = $singleCommit.PRNumber - GitHubToken = $GitHubToken - } - $pr = Get-GitHubPR @getPrParams - - $changelogItem.PR = $pr - $changelogItem.PRNumber = $pr.Number - - $closedIssueInfos = $pr.GetClosedIssueInfos() - if ($closedIssueInfos) - { - $changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue - $changelogItem.IssueNumber = $closedIssueInfos[0].Number - } - } - - $changelogItem - } -} - -filter New-ChangelogEntry -{ - [OutputType([ChangelogEntry])] - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangeInfo] - $Change, - - [Parameter(Mandatory)] - [System.Collections.Specialized.OrderedDictionary] - $EntryCategories, - - [Parameter(Mandatory)] - [string] - $DefaultCategory, - - [Parameter(Mandatory)] - [hashtable] - $TagLabels, - - [Parameter()] - [string[]] - $NoThanks = @() - ) - - [string[]]$tags = @() - :labelLoop foreach ($issueLabel in $Change.ClosedIssues.Labels) - { - if (-not $entryCategory) - { - foreach ($category in $EntryCategories.GetEnumerator()) - { - if ($issueLabel -in $category.Value.Issue) - { - $entryCategory = $category.Key - continue :labelLoop - } - } - } - - $tag = $TagLabels[$issueLabel] - if ($tag) - { - $tags += $tag - } - } - - if (-not $entryCategory) - { - $entryCategory = $DefaultCategory - } - - $organization = $Change.Commit.Organization - $repository = $Change.Commit.Repository - - $issueLink = if ($Change.IssueNumber -ge 0) { $Change.ClosedIssues[0].GetHtmlUri() } else { $null } - $prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$organization/$repository/pull/$($Change.PRNumber)" } else { $null } - $thanks = if ($Change.ContributingUser -notin $NoThanks) { $Change.ContributingUser } else { $null } - - $subject = $Change.Subject - if ($subject -match '(.*)\(#\d+\)$') - { - $subject = $Matches[1] - } - - Write-Verbose "Assembled changelog entry for commit $($Change.Commit.Hash)" - - return [ChangelogEntry]@{ - IssueLink = $issueLink - PRLink = $prLink - Thanks = $thanks - Category = $entryCategory - Tags = $tags - Change = $Change - RepositoryName = "$organization/$repository" - BodyText = $Change.BodyText - Subject = $subject - } -} - -function New-ChangeLogSection -{ - [OutputType([string])] - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangelogEntry[]] - $ChangelogEntry, - - [Parameter(Mandatory)] - [string] - $ReleaseName, - - [Parameter(Mandatory)] - [string[]] - $Categories, - - [Parameter(Mandatory)] - [string] - $DefaultCategory, - - [Parameter()] - [string] - $Preamble, - - [Parameter()] - [string] - $Postamble, - - [Parameter()] - [datetime] - $Date = [datetime]::Now, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [string] - $DateFormat = 'dddd, dd MM yyyy', - - [Parameter()] - [string] - $Indent = ' ' - ) - - begin - { - $entries = [ordered]@{} - - foreach ($category in $Categories) - { - $entries[$category] = [System.Collections.Generic.List[ChangelogEntry]]::new() - } - } - - process - { - foreach ($entry in $ChangelogEntry) - { - $entries[$entry.Category].Add($entry) - } - } - - end - { - $dateStr = $Date.ToString($DateFormat) - $sb = [System.Text.StringBuilder]::new().AppendLine("## $ReleaseName").AppendLine("### $dateStr") - - if ($Preamble) - { - [void]$sb.AppendLine($Preamble) - } - - [void]$sb.AppendLine() - - foreach ($category in $entries.GetEnumerator()) - { - if (-not $category.Value) - { - continue - } - - if ($category.Key -ne $DefaultCategory) - { - [void]$sb.AppendLine("$($category.Key):") - } - - foreach ($item in $category.Value) - { - # Set up the pieces needed for a changelog entry - $link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" } - $thanks = $item.Thanks - - if ($item.Change.IssueNumber -ge 0) - { - $project = $item.Change.ClosedIssues[0].Repository - $issueNumber = $item.Change.IssueNumber - } - elseif ($item.Change.PRNumber -ge 0) - { - $project = $item.Change.PR.Repository - $issueNumber = $item.Change.PRNumber - } - - # Add the list bullet - [void]$sb.Append('- ') - - # Start with the tags - if ($item.Tags) - { - [void]$sb.Append(($item.Tags -join ' ')).Append(' ') - } - - # Create a header for the change if there is an issue number - if ($issueNumber) - { - [void]$sb.AppendLine("[$project #$issueNumber]($link) -").Append($Indent) - } - - [void]$sb.Append((NormalizeSubject -Subject $item.Subject)) - if ($thanks) - { - [void]$sb.Append(" (Thanks @$thanks!)") - } - [void]$sb.AppendLine() - } - } - - if ($Postamble) - { - [void]$sb.AppendLine().AppendLine($Postamble) - } - - [void]$sb.AppendLine() - - return $sb.ToString() - } -} - -filter Skip-IgnoredChange -{ - param( - [Parameter(Mandatory, ValueFromPipeline)] - [ChangeInfo[]] - $Change, - - [Parameter()] - [string[]] - $User, - - [Parameter()] - [string] - $CommitLabel, - - [Parameter()] - [string[]] - $IssueLabel, - - [Parameter()] - [string[]] - $PRLabel - ) - - :outer foreach ($chg in $Change) - { - $msg = $chg.Subject - if ($chg.ContributingUser -in $User) - { - $u = $chg.ContributingUser - Write-Verbose "Skipping change from user '$u': '$msg'" - continue - } - - foreach ($chgCommitLabel in $chg.Commit.CommitLabels) - { - if ($chgCommitLabel -in $CommitLabel) - { - Write-Verbose "Skipping change with commit label '$chgCommitLabel': '$msg'" - continue outer - } - } - - foreach ($chgIssueLabel in $chg.ClosedIssues.Labels) - { - if ($chgIssueLabel -in $IssueLabel) - { - Write-Verbose "Skipping change with issue label '$chgIssueLabel': '$msg'" - continue outer - } - } - - foreach ($chgPRLabel in $chg.PR.Labels) - { - if ($chgPRLabel -in $PRLabel) - { - Write-Verbose "Skipping change with PR label '$chgPRLabel': '$msg'" - continue outer - } - } - - # Yield the change - $chg - } -} - -Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,New-ChangelogSection,Skip-IgnoredChange diff --git a/tools/ReleaseTools.psm1 b/tools/ReleaseTools.psm1 new file mode 100644 index 0000000000..4f2e5c7e6e --- /dev/null +++ b/tools/ReleaseTools.psm1 @@ -0,0 +1,230 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +#requires -Version 7.0 + +using module PowerShellForGitHub +using namespace System.Management.Automation + +class RepoNames: IValidateSetValuesGenerator { + # NOTE: This is super over-engineered, but it was fun. + static [string[]] $Values = "vscode-powershell", "PowerShellEditorServices" + [String[]] GetValidValues() { return [RepoNames]::Values } +} + +$ChangelogFile = "CHANGELOG.md" + +<# +.SYNOPSIS + Given a collection of PRs, generates a bulleted list. +#> +function Get-Bullets { + param( + [Parameter(Mandatory)] + [ValidateSet([RepoNames])] + [string]$RepositoryName, + + [Parameter(Mandatory, ValueFromPipeline)] + [PSCustomObject[]]$PullRequests + ) + begin { + $SkipThanks = @( + 'andschwa' + 'daxian-dbw' + 'PaulHigin' + 'rjmholt' + 'SteveL-MSFT' + 'TylerLeonhardt' + ) + + $LabelEmoji = @{ + 'Issue-Enhancement' = '✨' + 'Issue-Bug' = '🐛' + 'Issue-Performance' = '⚡️' + 'Area-Build & Release' = '👷' + 'Area-Code Formatting' = '💎' + 'Area-Configuration' = '🔧' + 'Area-Debugging' = '🔍' + 'Area-Documentation' = '📖' + 'Area-Engine' = '🚂' + 'Area-Folding' = '📚' + 'Area-Integrated Console' = '📟' + 'Area-IntelliSense' = '🧠' + 'Area-Logging' = '💭' + 'Area-Pester' = '🐢' + 'Area-Script Analysis' = '‍🕵️' + 'Area-Snippets' = '✂️' + 'Area-Startup' = '🛫' + 'Area-Symbols & References' = '🔗' + 'Area-Tasks' = '✅' + 'Area-Test' = '🚨' + 'Area-Threading' = '⏱️' + 'Area-UI' = '📺' + 'Area-Workspaces' = '📁' + } + + $CloseKeywords = @( + 'close' + 'closes' + 'closed' + 'fix' + 'fixes' + 'fixed' + 'resolve' + 'resolves' + 'resolved' + ) + + $IssueRegex = '(' + ($CloseKeywords -join '|') + ')\s+(?\D+)(?\d+)' + } + + 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 { + '#️⃣ 🙏' + } + + # Get a linked issue number if it exists (or use the PR). + $link = if ($_.body -match $IssueRegex) { + $number = $Matches.number + $repo = $Matches.repo + # Handle links to issues in both repos, in both shortcode and URLs. + $name = [RepoNames]::Values | Where-Object { $repo -match $_ } | Select-Object -First 1 + "$($name ?? $RepositoryName) #$number" + } else { + "$RepositoryName #$($_.number)" + } + + # Thank the contributor if they are not one of us. + $thanks = if ($_.user.UserName -notin $SkipThanks) { + "(Thanks @$($_.user.UserName)!)" + } + + # Put the bullet point together. + ("-", $emoji, "[$link]($($_.html_url))", "-", "$($_.title).", $thanks -join " ").Trim() + } + } +} + +<# +.SYNOPSIS + Gets the unpublished content from the changelog. +.DESCRIPTION + This is used so that we can manually touch-up the automatically updated + changelog, and then bring its contents into the extension's changelog or + the GitHub release. +#> +function Get-NewChangelog { + param( + [Parameter(Mandatory)] + [ValidateSet([RepoNames])] + [string]$RepositoryName + ) + $Repo = Get-GitHubRepository -OwnerName PowerShell -RepositoryName $RepositoryName + $Release = $Repo | Get-GitHubRelease -Latest + $Changelog = Get-Content -Path "$PSScriptRoot/../../$RepositoryName/$ChangelogFile" + $Changelog.Where( + { $_.StartsWith("##") }, "SkipUntil" + ).Where( + { $_.StartsWith("## $($Release.tag_name)") }, "Until" + ) +} + +<# +.SYNOPSIS + Updates the CHANGELOG file with PRs merged since the last release. +.DESCRIPTION + Uses the local Git repositories but does not pull, so ensure HEAD is where + you want it. Creates a new branch at release/$Version if not already + checked out. Handles any merge option for PRs, but is a little slow as it + queries all closed PRs. +#> +function Update-Changelog { + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [ValidateSet([RepoNames])] + [string]$RepositoryName, + + [Parameter(Mandatory)] + [ValidateScript({ $_.StartsWith("v") })] + [string]$Version + ) + # NOTE: This a side effect neccesary for Git operations to work. + Push-Location -Path "$PSScriptRoot/../../$RepositoryName" + + # Get the repo object, latest release, and commits since its tag. + $Repo = Get-GitHubRepository -OwnerName PowerShell -RepositoryName $RepositoryName + $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 | + Where-Object { $_.merge_commit_sha -in $Commits } | + Where-Object { -not $_.user.UserName.EndsWith("[bot]") } | + Where-Object { -not $_.title.StartsWith("[Ignore]") } | + Get-Bullets -RepositoryName $RepositoryName + + $NewSection = switch ($RepositoryName) { + "vscode-powershell" { + @( + "#### [vscode-powershell](https://github.com/PowerShell/vscode-powershell)`n" + $Bullets + "" + "#### [PowerShellEditorServices](https://github.com/PowerShell/PowerShellEditorServices)`n" + (Get-NewChangelog -RepositoryName "PowerShellEditorServices").Where({ $_.StartsWith("- ") }, "SkipUntil") + ) + } + "PowerShellEditorServices" { + @($Bullets) + } + } + + $CurrentChangelog = Get-Content -Path $ChangelogFile + + @( + $CurrentChangelog[0..1] + "## $Version" + "### $([datetime]::Now.ToString('dddd, MMMM dd, yyyy'))`n" + $NewSection + $CurrentChangelog[1..$CurrentChangelog.Length] + ) | Set-Content -Encoding utf8NoBOM -Path $ChangelogFile + + if ($PSCmdlet.ShouldProcess("$RepositoryName/$ChangelogFile", "git")) { + $branch = git branch --show-current + if ($branch -ne "release/$Version") { + git checkout -b "release/$Version" + } + git add $ChangelogFile + git commit -m "Update CHANGELOG for $Version" + } + + Pop-Location +} + +function New-DraftRelease { + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [ValidateSet([RepoNames])] + [string]$RepositoryName + ) + $Changelog = Get-NewChangelog -RepositoryName $RepositoryName + $Changelog -match '## (?v\S+)' + $Version = $Matches.version + $ReleaseParams = @{ + Draft = $true + Tag = $Version + Name = $Version + Body = $ChangeLog -join "`n" + PreRelease = $Version -match '-preview' + } + $Repo = Get-GitHubRepository -OwnerName PowerShell -RepositoryName $RepositoryName + $Repo | New-GitHubRelease @ReleaseParams +} + +Export-ModuleMember -Function Update-Changelog, New-DraftRelease diff --git a/tools/changelog/updateChangelog.ps1 b/tools/changelog/updateChangelog.ps1 deleted file mode 100644 index 1807528d28..0000000000 --- a/tools/changelog/updateChangelog.ps1 +++ /dev/null @@ -1,351 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -#requires -Version 6.0 - -using module ..\GitHubTools.psm1 -using module ..\ChangelogTools.psm1 - -<# -.EXAMPLE -.\updateChangelog.ps1 -GitHubToken $ghTok -PSExtensionSinceRef v2019.5.0 -PsesSinceRef v2.0.0-preview.4 -PSExtensionVersion 2019.9.0 -PsesVersion 2.0.0-preview.5 -PSExtensionUntilRef master -PsesUntilRef master -Verbose -#> -[CmdletBinding()] -param( - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter(Mandatory)] - [string] - $PSExtensionSinceRef, - - [Parameter(Mandatory)] - [string] - $PsesSinceRef, - - [Parameter()] - [version] - $PSExtensionVersion, # Default from package.json - - [Parameter()] - [semver] - $PsesVersion, # Default from PowerShellEditorServices.Common.props - - [Parameter()] - [string] - $PSExtensionReleaseName, # Default from $PSExtensionVersion - - [Parameter()] - [string] - $PsesReleaseName, # Default from $PsesVersion - - [Parameter()] - [string] - $PSExtensionUntilRef = 'HEAD', - - [Parameter()] - [string] - $PsesUntilRef = 'HEAD', - - [Parameter()] - [string] - $PSExtensionBaseBranch, # Default is master if HEAD, otherwise $PSExtensionSinceRef - - [Parameter()] - [string] - $PsesBaseBranch, # Default is master if HEAD, otherwise $PsesSinceRef - - [Parameter()] - [string] - $Organization = 'PowerShell', - - [Parameter()] - [string] - $TargetFork = $Organization, - - [Parameter()] - [string] - $FromFork = 'rjmholt', - - [Parameter()] - [string] - $ChangelogName = 'CHANGELOG.md', - - [Parameter()] - [string] - $PSExtensionRepositoryPath = (Resolve-Path "$PSScriptRoot/../../"), - - [Parameter()] - [string] - $PsesRepositoryPath = (Resolve-Path "$PSExtensionRepositoryPath/../PowerShellEditorServices") -) - -$PSExtensionRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PSExtensionRepositoryPath) -$PsesRepositoryPath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($PsesRepositoryPath) - -$packageJson = Get-Content -Raw "$PSExtensionRepositoryPath/package.json" | ConvertFrom-Json -$extensionName = $packageJson.name -if (-not $PSExtensionVersion) -{ - $PSExtensionVersion = $packageJson.version -} - -if (-not $PsesVersion) -{ - $psesProps = [xml](Get-Content -Raw "$PsesRepositoryPath/PowerShellEditorServices.Common.props") - $psesVersionPrefix = $psesProps.Project.PropertyData.VersionPrefix - $psesVersionSuffix = $psesProps.Project.PropertyData.VersionSuffix - - $PsesVersion = [semver]"$psesVersionPrefix-$psesVersionSuffix" -} - -if (-not $PSExtensionReleaseName) -{ - $PSExtensionReleaseName = "v$PSExtensionVersion" -} - -if (-not $PsesReleaseName) -{ - $PsesReleaseName = "v$PsesVersion" -} - -if (-not $PSExtensionBaseBranch) -{ - $PSExtensionBaseBranch = if ($PSExtensionUntilRef -eq 'HEAD') - { - 'master' - } - else - { - $PSExtensionUntilRef - } -} - -if (-not $PsesBaseBranch) -{ - $PsesBaseBranch = if ($PsesUntilRef -eq 'HEAD') - { - 'master' - } - else - { - $PsesUntilRef - } -} - -function UpdateChangelogFile -{ - param( - [Parameter(Mandatory)] - [string] - $NewSection, - - [Parameter(Mandatory)] - [string] - $Path - ) - - Write-Verbose "Writing new changelog section to '$Path'" - - $changelogLines = Get-Content -Path $Path - $newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n") - Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path -} - -#region Configuration - -Write-Verbose "Configuring settings" - -$vscodeRepoName = 'vscode-PowerShell' -$psesRepoName = 'PowerShellEditorServices' - -$dateFormat = 'dddd, MMMM dd, yyyy' - -$ignore = @{ - User = 'dependabot[bot]','dependabot-preview[bot]','github-actions[bot]' - CommitLabel = 'Ignore' -} - -$noThanks = @( - 'andschwa' - 'daxian-dbw' - 'PaulHigin' - 'rjmholt' - 'SteveL-MSFT' - 'TylerLeonhardt' -) - -$categories = [ordered]@{ - Debugging = @{ - Issue = 'Area-Debugging' - } - CodeLens = @{ - Issue = 'Area-CodeLens' - } - 'Script Analysis' = @{ - Issue = 'Area-Script Analysis' - } - Formatting = @{ - Issue = 'Area-Formatting' - } - 'Integrated Console' = @{ - Issue = 'Area-Integrated Console','Area-PSReadLine' - } - Intellisense = @{ - Issue = 'Area-Intellisense' - } - General = @{ - Issue = 'Area-General' - } -} - -$defaultCategory = 'General' - -$branchName = "changelog-$PSExtensionReleaseName" - -#endregion Configuration - -#region PSES Changelog - -$psesGetCommitParams = @{ - SinceRef = $PsesSinceRef - UntilRef = $PsesUntilRef - GitHubToken = $GitHubToken - RepositoryPath = $PsesRepositoryPath - Verbose = $VerbosePreference -} - -$clEntryParams = @{ - EntryCategories = $categories - DefaultCategory = $defaultCategory - TagLabels = @{ - 'Issue-Enhancement' = '✨' - 'Issue-Bug' = '🐛' - 'Issue-Performance' = '⚡️' - 'Area-Build & Release' = '👷' - 'Area-Code Formatting' = '💎' - 'Area-Configuration' = '🔧' - 'Area-Debugging' = '🔍' - 'Area-Documentation' = '📖' - 'Area-Engine' = '🚂' - 'Area-Folding' = '📚' - 'Area-Integrated Console' = '📟' - 'Area-IntelliSense' = '🧠' - 'Area-Logging' = '💭' - 'Area-Pester' = '🐢' - 'Area-Script Analysis' = '👮‍' - 'Area-Snippets' = '✂️' - 'Area-Startup' = '🛫' - 'Area-Symbols & References' = '🔗' - 'Area-Tasks' = '✅' - 'Area-Test' = '🚨' - 'Area-Threading' = '⏱️' - 'Area-UI' = '📺' - 'Area-Workspaces' = '📁' - } - NoThanks = $noThanks - Verbose = $VerbosePreference -} - -$clSectionParams = @{ - Categories = $categories.Keys - DefaultCategory = $defaultCategory - DateFormat = $dateFormat - Verbose = $VerbosePreference -} - -Write-Verbose "Creating PSES changelog" - -$psesChangelogSection = Get-GitCommit @psesGetCommitParams | - Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | - Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | - New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams -ReleaseName $PsesReleaseName - -Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n" - -#endregion PSES Changelog - -#region vscode-PowerShell Changelog -$psesChangelogPostamble = $psesChangelogSection -split "`n" -$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..($psesChangelogPostamble.Length-3)] -$psesChangelogPostamble = $psesChangelogPostamble -join "`n" - -$psExtGetCommitParams = @{ - SinceRef = $PSExtensionSinceRef - UntilRef = $PSExtensionUntilRef - GitHubToken = $GitHubToken - RepositoryPath = $PSExtensionRepositoryPath - Verbose = $VerbosePreference -} -$psextChangelogSection = Get-GitCommit @psExtGetCommitParams | - Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference | - Skip-IgnoredChange @ignore -Verbose:$VerbosePreference | - New-ChangelogEntry @clEntryParams | - New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble -ReleaseName $PSExtensionReleaseName - -Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n" - -#endregion vscode-PowerShell Changelog - -#region PRs - -# PSES PR -$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate" - -$cloneParams = @{ - OriginRemote = "https://github.com/$FromFork/$psesRepoName" - Destination = $cloneLocation - CheckoutBranch = $branchName - CloneBranch = $PsesBaseBranch - Clobber = $true - Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$psesRepoName" } -} -Copy-GitRepository @cloneParams -Verbose:$VerbosePreference - -UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName" - -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $PsesReleaseName" -Verbose:$VerbosePreference - -$prParams = @{ - Organization = $TargetFork - Repository = $psesRepoName - Branch = $branchName - Title = "Update CHANGELOG for $PsesReleaseName" - GitHubToken = $GitHubToken - FromOrg = $FromFork - TargetBranch = $PsesBaseBranch -} -New-GitHubPR @prParams -Verbose:$VerbosePreference - -# vscode-PowerShell PR -$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate" - -$cloneParams = @{ - OriginRemote = "https://github.com/$FromFork/$vscodeRepoName" - Destination = $cloneLocation - CheckoutBranch = $branchName - CloneBranch = $PSExtensionBaseBranch - Clobber = $true - Remotes = @{ 'upstream' = "https://github.com/$TargetFork/$vscodeRepoName" } - PullUpstream = $true -} -Copy-GitRepository @cloneParams -Verbose:$VerbosePreference - -UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName" - -Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $PSExtensionReleaseName" -Verbose:$VerbosePreference - -$prParams = @{ - Organization = $TargetFork - Repository = $vscodeRepoName - Branch = $branchName - Title = "Update $extensionName CHANGELOG for $PSExtensionReleaseName" - GitHubToken = $GitHubToken - FromOrg = $FromFork - TargetBranch = $PSExtensionBaseBranch -} -New-GitHubPR @prParams -Verbose:$VerbosePreference - -#endregion PRs diff --git a/tools/postReleaseScripts/publishGHRelease.ps1 b/tools/postReleaseScripts/publishGHRelease.ps1 deleted file mode 100644 index f75b99a8b2..0000000000 --- a/tools/postReleaseScripts/publishGHRelease.ps1 +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -#requires -Version 6.0 - -param( - [Parameter(Mandatory)] - [semver] - $Version, - - [Parameter(Mandatory)] - [string] - $GitHubToken, - - [Parameter(Mandatory)] - [ValidateSet("vscode-powershell", "PowerShellEditorServices")] - $Repository, - - [Parameter()] - [string] - $TargetFork = 'PowerShell', - - [Parameter()] - [string] - $ChangelogPath = "$PSScriptRoot/../../../$Repository/CHANGELOG.md", - - [Parameter()] - [string[]] - $AssetPath -) - -Import-Module "$PSScriptRoot/../GitHubTools.psm1" -Force - -<# -.SYNOPSIS -Get the release description from the CHANGELOG -.DESCRIPTION -Gets the latest CHANGELOG entry from the CHANGELOG for use as the GitHub release description -.PARAMETER ChangelogPath -Path to the changelog file -#> -function GetDescriptionFromChangelog -{ - param( - [Parameter(Mandatory)] - [string] - $ChangelogPath - ) - - $lines = Get-Content -Path $ChangelogPath - # First two lines are the title and newline - # Third looks like '## vX.Y.Z-releasetag' - $sb = [System.Text.StringBuilder]::new($lines[2]) - # Read through until the next '## vX.Y.Z-releasetag' H2 - for ($i = 3; -not $lines[$i].StartsWith('## '); $i++) - { - $null = $sb.Append("`n").Append($lines[$i]) - } - - return $sb.ToString() -} - -$tag = "v$Version" - -$releaseParams = @{ - Draft = $true - Organization = $TargetFork - Repository = $Repository - Tag = $tag - ReleaseName = $tag - AssetPath = $AssetPath - Prerelease = [bool]($Version.PreReleaseLabel) - Description = GetDescriptionFromChangelog -ChangelogPath $ChangelogPath - GitHubToken = $GitHubToken -} -Publish-GitHubRelease @releaseParams