@@ -134,6 +134,25 @@ function Get-NewChangelog {
134
134
)
135
135
}
136
136
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
+
137
156
<#
138
157
. SYNOPSIS
139
158
Updates the CHANGELOG file with PRs merged since the last release.
@@ -302,7 +321,8 @@ function Update-Version {
302
321
Creates a new draft GitHub release from the updated changelog.
303
322
. DESCRIPTION
304
323
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`.
306
326
#>
307
327
function New-DraftRelease {
308
328
[CmdletBinding (SupportsShouldProcess )]
@@ -311,17 +331,14 @@ function New-DraftRelease {
311
331
[ValidateSet ([RepoNames ])]
312
332
[string ]$RepositoryName
313
333
)
314
- # TODO: Abstract this to return version components and reuse in `Update -Version`.
334
+ $Version = Get -Version - RepositoryName $RepositoryName
315
335
$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!" }
319
336
$ReleaseParams = @ {
320
337
Draft = $true
321
- Tag = $Version
322
- Name = $Version
338
+ Tag = " v $Version "
339
+ Name = " v $Version "
323
340
Body = $ChangeLog
324
- PreRelease = $Version -match ' -preview '
341
+ PreRelease = [ bool ] $Version.PreReleaseLabel
325
342
# TODO: Pass -WhatIf and -Confirm parameters correctly.
326
343
}
327
344
Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName |
0 commit comments