@@ -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.
@@ -211,7 +230,8 @@ function Update-Changelog {
211230 Creates a new draft GitHub release from the updated changelog.
212231. DESCRIPTION
213232 Requires that the changelog has been updated first as it pulls the release
214- content and new version number from it.
233+ content and new version number from it. Note that our tags and version name
234+ are prefixed with a `v`.
215235#>
216236function New-DraftRelease {
217237 [CmdletBinding (SupportsShouldProcess )]
@@ -220,17 +240,14 @@ function New-DraftRelease {
220240 [ValidateSet ([RepoNames ])]
221241 [string ]$RepositoryName
222242 )
223- # TODO: Abstract this to return version components and reuse in `Update -Version`.
243+ $Version = Get -Version - RepositoryName $RepositoryName
224244 $Changelog = (Get-NewChangelog - RepositoryName $RepositoryName ) -join " `n "
225- $Version = if ($Changelog -match ' ## (?<version>v\S+)' ) {
226- $Matches.version
227- } else { Write-Error " Couldn't find version from changelog!" }
228245 $ReleaseParams = @ {
229246 Draft = $true
230- Tag = $Version
231- Name = $Version
247+ Tag = " v $Version "
248+ Name = " v $Version "
232249 Body = $ChangeLog
233- PreRelease = $Version -match ' -preview '
250+ PreRelease = [ bool ] $Version.PreReleaseLabel
234251 # TODO: Pass -WhatIf and -Confirm parameters correctly.
235252 }
236253 Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName |
0 commit comments