Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2bf2359

Browse files
Support WhatIf and Confirm better in ReleaseTools module
1 parent 7934504 commit 2bf2359

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

‎tools/ReleaseTools.psm1‎

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ function Get-FirstChangelog {
139139
Creates and checks out `release/v<version>` if not already on it.
140140
#>
141141
function 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
#>
342348
function 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-Host "Pushing branch ``$Branch``..."
365+
git push origin $Branch
366+
}
356367

357368
$LabelParams = @{
358369
OwnerName = "PowerShell"
@@ -361,15 +372,17 @@ 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
372-
Write-Output "Draft PR URL: $($PR.html_url)"
385+
Write-Host "Draft PR URL: $($PR.html_url)"
373386

374387
Pop-Location
375388
}
@@ -383,6 +396,7 @@ function New-ReleasePR {
383396
are prefixed with a `v`. Creates a Git tag if it does not already exist.
384397
#>
385398
function New-DraftRelease {
399+
[CmdletBinding(SupportsShouldProcess)]
386400
param(
387401
[Parameter(Mandatory)]
388402
[ValidateSet([RepoNames])]
@@ -394,19 +408,23 @@ function New-DraftRelease {
394408
$Version = Get-Version -RepositoryName $RepositoryName
395409
$Changelog = (Get-FirstChangelog -RepositoryName $RepositoryName) -join "`n"
396410
$ReleaseParams = @{
397-
Draft = $true
398411
# 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"
412+
Tag = "v$Version"
413+
Committish = "release/v$Version"
414+
Name = "v$Version"
415+
Body = $ChangeLog
416+
Draft = $true
417+
PreRelease = [bool]$Version.PreReleaseLabel
418+
OwnerName = "PowerShell"
405419
RepositoryName = $RepositoryName
420+
WhatIf = $WhatIfPreference
421+
Confirm = $ConfirmPreference
406422
}
407423

408424
$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
425+
if ($Release) {
426+
Write-Host "Draft release URL: $($Release.html_url)"
427+
Write-Host "Uploading assets..."
428+
$Assets | New-GitHubReleaseAsset -Release $Release.Id
429+
}
412430
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /