@@ -139,13 +139,17 @@ function Get-FirstChangelog {
139139 Creates and checks out `release/v<version>` if not already on it.
140140#>
141141function Update-Branch {
142+ [CmdletBinding (SupportsShouldProcess )]
142143 param (
143144 [Parameter (Mandatory )]
144145 [string ]$Version
145146 )
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+ }
149153 }
150154}
151155
@@ -234,15 +238,16 @@ function Update-Changelog {
234238 $CurrentChangelog [2 .. $CurrentChangelog.Length ]
235239 ) | Set-Content - Encoding utf8NoBOM - Path $ChangelogFile
236240
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" )) {
239244 git add $ChangelogFile
240245 git commit - m " Update CHANGELOG for `` $Version `` "
241246 }
242247
243- Pop-Location
244-
245248 Update-Version - RepositoryName $RepositoryName
249+
250+ Pop-Location
246251}
247252
248253<#
@@ -323,14 +328,15 @@ function Update-Version {
323328 }
324329 }
325330
331+ Update-Branch - Version $Version
332+
326333 if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git commit" )) {
327- Update-Branch - Version $Version
328334 git commit - m " Bump version to `` v$Version `` "
329- }
330-
331- Pop-Location
335+ } # TODO: Git reset to unstage
332336
333337 New-ReleasePR - RepositoryName $RepositoryName
338+
339+ Pop-Location
334340}
335341
336342<#
@@ -340,6 +346,7 @@ function Update-Version {
340346 Pushes the release branch to `origin` and then opens a draft PR.
341347#>
342348function New-ReleasePR {
349+ [CmdletBinding (SupportsShouldProcess )]
343350 param (
344351 [Parameter (Mandatory )]
345352 [ValidateSet ([RepoNames ])]
@@ -350,9 +357,13 @@ function New-ReleasePR {
350357
351358 $Version = Get-Version - RepositoryName $RepositoryName
352359 $Branch = " release/v$Version "
360+
353361 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+ }
356367
357368 $LabelParams = @ {
358369 OwnerName = " PowerShell"
@@ -361,11 +372,13 @@ function New-ReleasePR {
361372 }
362373
363374 $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
369382 }
370383
371384 $PR = Get-GitHubLabel @LabelParams | New-GitHubPullRequest @PRParams
@@ -394,21 +407,25 @@ function New-DraftRelease {
394407 $Version = Get-Version - RepositoryName $RepositoryName
395408 $Changelog = (Get-FirstChangelog - RepositoryName $RepositoryName ) -join " `n "
396409 $ReleaseParams = @ {
397- Draft = $true
398410 # 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"
405418 RepositoryName = $RepositoryName
419+ WhatIf = $WhatIfPreference
420+ Confirm = $ConfirmPreference
406421 }
407422
408423 $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+ }
412429}
413430
414431<#
0 commit comments