@@ -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.
@@ -211,7 +230,8 @@ function Update-Changelog {
211
230
Creates a new draft GitHub release from the updated changelog.
212
231
. DESCRIPTION
213
232
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`.
215
235
#>
216
236
function New-DraftRelease {
217
237
[CmdletBinding (SupportsShouldProcess )]
@@ -220,17 +240,14 @@ function New-DraftRelease {
220
240
[ValidateSet ([RepoNames ])]
221
241
[string ]$RepositoryName
222
242
)
223
- # TODO: Abstract this to return version components and reuse in `Update -Version`.
243
+ $Version = Get -Version - RepositoryName $RepositoryName
224
244
$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!" }
228
245
$ReleaseParams = @ {
229
246
Draft = $true
230
- Tag = $Version
231
- Name = $Version
247
+ Tag = " v $Version "
248
+ Name = " v $Version "
232
249
Body = $ChangeLog
233
- PreRelease = $Version -match ' -preview '
250
+ PreRelease = [ bool ] $Version.PreReleaseLabel
234
251
# TODO: Pass -WhatIf and -Confirm parameters correctly.
235
252
}
236
253
Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName |
0 commit comments