@@ -139,13 +139,17 @@ function Get-FirstChangelog {
139
139
Creates and checks out `release/v<version>` if not already on it.
140
140
#>
141
141
function Update-Branch {
142
+ [CmdletBinding (SupportsShouldProcess )]
142
143
param (
143
144
[Parameter (Mandatory )]
144
145
[string ]$Version
145
146
)
146
- $branch = git branch -- show-current
147
- if ($branch -ne " release/v$Version " ) {
148
- git checkout - b " release/v$Version "
147
+ $Branch = git branch -- show-current
148
+ $NewBranch = " release/v$Version "
149
+ if ($Branch -ne $NewBranch ) {
150
+ if ($PSCmdlet.ShouldProcess ($NewBranch , " git checkout -b" )) {
151
+ git checkout - b $NewBranch
152
+ }
149
153
}
150
154
}
151
155
@@ -234,15 +238,16 @@ function Update-Changelog {
234
238
$CurrentChangelog [2 .. $CurrentChangelog.Length ]
235
239
) | Set-Content - Encoding utf8NoBOM - Path $ChangelogFile
236
240
237
- if ($PSCmdlet.ShouldProcess (" $RepositoryName /$ChangelogFile " , " git" )) {
238
- Update-Branch - Version $Version.Substring (1 ) # Has "v" prefix
241
+ Update-Branch - Version $Version.Substring (1 ) # Has "v" prefix
242
+
243
+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /$ChangelogFile " , " git commit" )) {
239
244
git add $ChangelogFile
240
245
git commit - m " Update CHANGELOG for `` $Version `` "
241
246
}
242
247
243
- Pop-Location
244
-
245
248
Update-Version - RepositoryName $RepositoryName
249
+
250
+ Pop-Location
246
251
}
247
252
248
253
<#
@@ -323,14 +328,15 @@ function Update-Version {
323
328
}
324
329
}
325
330
331
+ Update-Branch - Version $Version
332
+
326
333
if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git commit" )) {
327
- Update-Branch - Version $Version
328
334
git commit - m " Bump version to `` v$Version `` "
329
- }
330
-
331
- Pop-Location
335
+ } # TODO: Git reset to unstage
332
336
333
337
New-ReleasePR - RepositoryName $RepositoryName
338
+
339
+ Pop-Location
334
340
}
335
341
336
342
<#
@@ -340,6 +346,7 @@ function Update-Version {
340
346
Pushes the release branch to `origin` and then opens a draft PR.
341
347
#>
342
348
function New-ReleasePR {
349
+ [CmdletBinding (SupportsShouldProcess )]
343
350
param (
344
351
[Parameter (Mandatory )]
345
352
[ValidateSet ([RepoNames ])]
@@ -350,9 +357,13 @@ function New-ReleasePR {
350
357
351
358
$Version = Get-Version - RepositoryName $RepositoryName
352
359
$Branch = " release/v$Version "
360
+
353
361
Update-Branch - Version $Version
354
- Write-Output " Pushing branch `` $Branch `` ..."
355
- git push origin $Branch
362
+
363
+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /$Branch " , " git push" )) {
364
+ Write-Output " Pushing branch `` $Branch `` ..."
365
+ git push origin $Branch
366
+ }
356
367
357
368
$LabelParams = @ {
358
369
OwnerName = " PowerShell"
@@ -361,11 +372,13 @@ function New-ReleasePR {
361
372
}
362
373
363
374
$PRParams = @ {
364
- Head = $Branch
365
- Base = " master"
366
- Draft = $true
367
- Title = " Release `` v$Version `` "
368
- Body = " Automated PR for new release!"
375
+ Head = $Branch
376
+ Base = " master"
377
+ Draft = $true
378
+ Title = " Release `` v$Version `` "
379
+ Body = " Automated PR for new release!"
380
+ WhatIf = $WhatIfPreference
381
+ Confirm = $ConfirmPreference
369
382
}
370
383
371
384
$PR = Get-GitHubLabel @LabelParams | New-GitHubPullRequest @PRParams
@@ -394,19 +407,23 @@ function New-DraftRelease {
394
407
$Version = Get-Version - RepositoryName $RepositoryName
395
408
$Changelog = (Get-FirstChangelog - RepositoryName $RepositoryName ) -join " `n "
396
409
$ReleaseParams = @ {
397
- Draft = $true
398
410
# NOTE: We rely on GitHub to create the tag at that branch.
399
- Tag = " v$Version "
400
- Committish = " release/v$Version "
401
- Name = " v$Version "
402
- Body = $ChangeLog
403
- PreRelease = [bool ]$Version.PreReleaseLabel
404
- OwnerName = " PowerShell"
411
+ Tag = " v$Version "
412
+ Committish = " release/v$Version "
413
+ Name = " v$Version "
414
+ Body = $ChangeLog
415
+ Draft = $true
416
+ PreRelease = [bool ]$Version.PreReleaseLabel
417
+ OwnerName = " PowerShell"
405
418
RepositoryName = $RepositoryName
419
+ WhatIf = $WhatIfPreference
420
+ Confirm = $ConfirmPreference
406
421
}
407
422
408
423
$Release = New-GitHubRelease @ReleaseParams
409
- Write-Output " Draft release URL: $ ( $Release.html_url ) "
410
- Write-Output " Uploading assets..."
411
- $Assets | New-GitHubReleaseAsset - Release $Release.Id
424
+ if ($Release ) {
425
+ Write-Output " Draft release URL: $ ( $Release.html_url ) "
426
+ Write-Output " Uploading assets..."
427
+ $Assets | New-GitHubReleaseAsset - Release $Release.Id
428
+ }
412
429
}
0 commit comments