Skip to content

Commit a611bd7

Browse files
authored
Updated automated build (#70)
* PR builds ignore some files (Still requires a review!) * Release build actions changes have no impact on a PR/CI build so don't trigger them * OneFlow script changes (also release build scripts) have no impact on PR/CI build so don't trigger them * Added support for `ShouldProcess` to `[Start|Publish]-Release.ps1` - This allows safer release process by providing a mechanism to use `-WhatIf` or `-Confirm` for scripts (especially `publish-release.ps1` that have significant impact and are difficult to undo)
1 parent aa8cb9c commit a611bd7

File tree

4 files changed

+58
-30
lines changed

4 files changed

+58
-30
lines changed

.github/workflows/pr-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
- '**.md'
1515
- '**.dic'
1616
- 'BuildVersion.xml'
17+
- 'GitHub/workflows/release-build.yml'
18+
- 'OneFlow/**.ps1'
1719

1820
pull_request:
1921
branches:
@@ -23,6 +25,8 @@ on:
2325
- '**.md'
2426
- '**.dic'
2527
- 'BuildVersion.xml'
28+
- 'GitHub/workflows/release-build.yml'
29+
- 'OneFlow/**.ps1'
2630

2731
jobs:
2832
# see: https://github.com/EnricoMi/publish-unit-test-result-action?tab=readme-ov-file#support-fork-repositories-and-dependabot-branches

.github/workflows/release-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ permissions:
44
pages: write
55
packages: write
66
actions: read
7+
78
defaults:
89
run:
910
shell: pwsh

OneFlow/Publish-Release.ps1

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ using module '../PsModules/RepoBuild/RepoBuild.psd1'
1919
.NOTE
2020
For the gory details of this process see: https://www.endoflineblog.com/implementing-oneflow-on-github-bitbucket-and-gitlab
2121
#>
22-
22+
[cmdletbinding(SupportsShouldProcess=$True, ConfirmImpact='High')]
2323
Param()
2424
$buildInfo = Initialize-BuildEnvironment
2525

26+
Write-Information "Build Version XML:"
27+
Write-Information ((Get-ParsedBuildVersionXML -BuildInfo $buildInfo).GetEnumerator() | Sort -Property Name | Out-String)
28+
2629
# merging the tag to develop branch on the official repository triggers the official build and release of the NuGet Packages
2730
$tagName = Get-BuildVersionTag $buildInfo
2831
$officialRemoteName = Get-GitRemoteName $buildInfo official
@@ -39,30 +42,42 @@ $mergeBackBranchName = "merge-back-$tagName"
3942
Write-Information 'Fetching from official repository'
4043
Invoke-External git fetch $officialRemoteName
4144

42-
Write-Information "Switching to release branch [$officialReleaseBranch]"
43-
Invoke-External git switch '-C' $releasebranch $officialReleaseBranch
45+
if($PSCmdlet.ShouldProcess($officialReleaseBranch, "git switch -C $releaseBranch"))
46+
{
47+
Write-Information "Switching to release branch [$officialReleaseBranch]"
48+
Invoke-External git switch '-C' $releaseBranch $officialReleaseBranch
49+
}
4450

45-
$confirmation = Read-Host "Are you Sure You Want To Proceed:"
46-
if ($confirmation -ne 'y')
51+
if($PSCmdlet.ShouldProcess($tagName, "create annotated tag"))
4752
{
48-
Write-Host "User canceled operation"
49-
return
53+
Write-Information 'Creating an annotated tag of this branch as the release'
54+
Invoke-External git tag $tagName '-m' "Official release: $tagName"
5055
}
5156

52-
Write-Information 'Creating tag of this branch as the release'
53-
Invoke-External git tag $tagName '-m' "Official release: $tagName"
57+
if($PSCmdlet.ShouldProcess($tagName, "git push $officialRemoteName tag"))
58+
{
59+
Write-Information 'Pushing tag to official remote [Starts automated build release process]'
60+
Invoke-External git push $officialRemoteName tag $tagName
61+
}
5462

55-
Write-Information 'Pushing tag to official remote [Starts automated build release process]'
56-
Invoke-External git push $officialRemoteName '--tags'
63+
if($PSCmdlet.ShouldProcess($releasebranch, "git checkout -b $mergeBackBranchName"))
64+
{
65+
Write-Information 'Creating local merge-back branch to merge changes associated with the release'
66+
# create a "merge-back" child branch to handle any updates/conflict resolutions when applying
67+
# the changes made in the release branch back to the develop branch.
68+
Invoke-External git checkout '-b' $mergeBackBranchName $releasebranch
69+
}
5770

58-
Write-Information 'Creating local merge-back branch to merge changes associated with the release'
59-
# create a "merge-back" child branch to handle any updates/conflict resolutions when applying
60-
# the changes made in the release branch back to the develop branch.
61-
Invoke-External git checkout '-b' $mergeBackBranchName $releasebranch
62-
Write-Information 'pushing merge-back branch to fork'
63-
Invoke-External git push $forkRemoteName $mergeBackBranchName
71+
if($PSCmdlet.ShouldProcess("$forkRemoteName $mergeBackBranchName", "git push"))
72+
{
73+
Write-Information 'pushing merge-back branch to fork'
74+
Invoke-External git push $forkRemoteName $mergeBackBranchName
75+
}
6476

65-
Write-Information 'Fast-forwarding main to tagged release'
66-
Invoke-External git switch '-C' $mainBranchName $officialMainBranch
67-
Invoke-External git merge --ff-only $tagName
68-
Invoke-External git push $officialRemoteName $mainBranchName
77+
if($PSCmdlet.ShouldProcess("$tagName", "Reset main to point to release tag"))
78+
{
79+
Write-Information 'Updating main to point to tagged release'
80+
Invoke-External git switch '-C' $mainBranchName $officialMainBranch
81+
Invoke-External git reset --hard $tagName
82+
Invoke-External git push --force $officialRemoteName $mainBranchName
83+
}

OneFlow/Start-Release.ps1

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ using module '../PsModules/RepoBuild/RepoBuild.psd1'
1212
.DESCRIPTION
1313
This function creates and publishes a Release branch
1414
#>
15-
16-
Param([string]$commit = "")
15+
[cmdletbinding(SupportsShouldProcess=$True)]
16+
Param(
17+
[string]$commit = ""
18+
)
1719
$buildInfo = Initialize-BuildEnvironment
1820

1921
$officialRemoteName = Get-GitRemoteName $buildInfo official
@@ -24,18 +26,24 @@ $branchName = "release/$(Get-BuildVersionTag $buildInfo)"
2426
Write-Information "Creating release branch in local repo"
2527
if ([string]::IsNullOrWhiteSpace($commit))
2628
{
27-
Invoke-External git checkout -b $branchName
29+
if($PSCmdlet.ShouldProcess($branchName, "git checkout -b"))
30+
{
31+
Invoke-External git checkout -b $branchName
32+
}
2833
}
2934
else
3035
{
31-
Invoke-External git checkout -b $branchName $commit
36+
if($PSCmdlet.ShouldProcess("$branchName $commit", "git checkout -b"))
37+
{
38+
Invoke-External git checkout -b $branchName $commit
39+
}
3240
}
3341

34-
# push to fork so that changes go through normal PR process
35-
Write-Information "Pushing branch to fork"
36-
Invoke-External git push $forkRemoteName -u $branchName
37-
3842
# Push to product repo so it is clear to all a release
3943
# is in process.
4044
Write-Information "Pushing branch to official repository (Push/Write permission required)"
41-
Invoke-External git push $officialRemoteName $branchName
45+
if($PSCmdlet.ShouldProcess("$officialRemoteName $branchName", "git push"))
46+
{
47+
Invoke-External git push $officialRemoteName $branchName
48+
}
49+

0 commit comments

Comments
 (0)