@@ -134,6 +134,25 @@ function Get-NewChangelog {
134134 )
135135}
136136
137+ <#
138+ . SYNOPSIS
139+ Gets current version from changelog as [semver].
140+ #>
141+ function Get-Version {
142+ param (
143+ [Parameter (Mandatory )]
144+ [ValidateSet ([RepoNames ])]
145+ [string ]$RepositoryName
146+ )
147+ # NOTE: This is joined into a multi-line string so `-match` works.
148+ $Changelog = (Get-NewChangelog - RepositoryName $RepositoryName ) -join " `n "
149+ if ($Changelog -match ' ## v(?<version>\d+\.\d+\.\d+(-preview\.?\d*)?)' ) {
150+ return [semver ]$Matches.version
151+ } else {
152+ Write-Error " Couldn't find version from changelog!"
153+ }
154+ }
155+
137156<#
138157. SYNOPSIS
139158 Updates the CHANGELOG file with PRs merged since the last release.
@@ -302,7 +321,8 @@ function Update-Version {
302321 Creates a new draft GitHub release from the updated changelog.
303322. DESCRIPTION
304323 Requires that the changelog has been updated first as it pulls the release
305- content and new version number from it.
324+ content and new version number from it. Note that our tags and version name
325+ are prefixed with a `v`.
306326#>
307327function New-DraftRelease {
308328 [CmdletBinding (SupportsShouldProcess )]
@@ -311,17 +331,14 @@ function New-DraftRelease {
311331 [ValidateSet ([RepoNames ])]
312332 [string ]$RepositoryName
313333 )
314- # TODO: Abstract this to return version components and reuse in `Update -Version`.
334+ $Version = Get -Version - RepositoryName $RepositoryName
315335 $Changelog = (Get-NewChangelog - RepositoryName $RepositoryName ) -join " `n "
316- $Version = if ($Changelog -match ' ## (?<version>v\S+)' ) {
317- $Matches.version
318- } else { Write-Error " Couldn't find version from changelog!" }
319336 $ReleaseParams = @ {
320337 Draft = $true
321- Tag = $Version
322- Name = $Version
338+ Tag = " v $Version "
339+ Name = " v $Version "
323340 Body = $ChangeLog
324- PreRelease = $Version -match ' -preview '
341+ PreRelease = [ bool ] $Version.PreReleaseLabel
325342 # TODO: Pass -WhatIf and -Confirm parameters correctly.
326343 }
327344 Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName |
0 commit comments