Skip to content

Commit 4de756f

Browse files
committed
Unifiy build infrastructure for greater commonality across repos in org
* Fixed publication of NuGet Packages based on work in other repos * Added support for `ShouldProcesss` to the `OneFlow` scripts to allow sanity checks before making major changes.
1 parent bcdb252 commit 4de756f

File tree

3 files changed

+101
-37
lines changed

3 files changed

+101
-37
lines changed

.github/workflows/release-build.yml

Lines changed: 9 additions & 3 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
@@ -67,12 +68,17 @@ jobs:
6768
branch: gh-pages
6869

6970
- name: Publish packages to NuGet.org
70-
run: dotnet nuget push .\BuildOutput\NuGet\*.nupkg -k ${{ secrets.NUGETPUSH_ACCESS_TOKEN }} -s 'https://api.nuget.org/v3/index.json' --skip-duplicate
71+
run: |
72+
if( [string]::IsNullOrWhiteSpace('${{secrets.NUGETPUSH_ACCESS_TOKEN}}'))
73+
{
74+
throw "'NUGETPUSH_ACCESS_TOKEN' does not exist, is empty or all whitespace!"
75+
}
76+
dotnet nuget push .\BuildOutput\NuGet\*.nupkg --api-key '${{secrets.NUGETPUSH_ACCESS_TOKEN}}' --source 'https://api.nuget.org/v3/index.json' --skip-duplicate
7177
7278
- name: Create Release
7379
if: (!cancelled())
7480
uses: softprops/action-gh-release@v2
7581
with:
76-
tag_name: ${{ github.ref }}
77-
release_name: Release ${{ github.ref }}
7882
draft: true
83+
files: BuildOutput/NuGet/*.nupkg
84+

OneFlow/Publish-Release.ps1

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using module '../PSModules/CommonBuild/CommonBuild.psd1'
2+
using module '../PsModules/RepoBuild/RepoBuild.psd1'
3+
14
<#
25
.SYNOPSIS
36
Publishes the current release as a new branch to the upstream repository
@@ -16,33 +19,68 @@
1619
.NOTE
1720
For the gory details of this process see: https://www.endoflineblog.com/implementing-oneflow-on-github-bitbucket-and-gitlab
1821
#>
19-
20-
Param([switch]$TagOnly)
21-
$repoRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, ".."))
22-
. (join-path $repoRoot repo-buildutils.ps1)
22+
[cmdletbinding(SupportsShouldProcess=$True, ConfirmImpact='High')]
23+
Param()
2324
$buildInfo = Initialize-BuildEnvironment
2425

25-
# create script scoped alias for git that throws a PowerShell exception if the command fails
26-
Set-Alias git Invoke-git -scope Script -option Private
26+
Write-Information "Build Version XML:"
27+
Write-Information ((Get-ParsedBuildVersionXML -BuildInfo $buildInfo).GetEnumerator() | Sort -Property Name | Out-String)
2728

2829
# merging the tag to develop branch on the official repository triggers the official build and release of the NuGet Packages
2930
$tagName = Get-BuildVersionTag $buildInfo
31+
$officialRemoteName = Get-GitRemoteName $buildInfo official
32+
$forkRemoteName = Get-GitRemoteName $buildInfo fork
33+
3034
$releaseBranch = "release/$tagName"
35+
$officialReleaseBranch = "$officialRemoteName/$releaseBranch"
36+
37+
$mainBranchName = "master"
38+
$officialMainBranch = "$officialRemoteName/$mainBranchName"
39+
3140
$mergeBackBranchName = "merge-back-$tagName"
3241

33-
# check out and tag the release branch
34-
git checkout $releasebranch
35-
git tag $tagname -m "Official release: $tagname"
36-
git push --tags
37-
38-
# create a "merge-back" child branch to handle any updates/conflict resolutions
39-
# the tag from the parent will flow through to the final commit of the PR For
40-
# the merge. Otherwise, the tag is locked to the commit on the release branch
41-
# and any conflict resolution commits are "AFTER" the tag (and thus, not included
42-
# in the tagged commit)
43-
# This PR **MUST** be merged to origin with the --no-ff strategy
44-
git checkout -b $mergeBackBranchName $releasebranch
45-
git push $mergeBackBranchName
46-
47-
Write-Output "Created and published $mergeBackBranchName to your forked repository, you must create a PR for this change to the Official repository"
48-
Write-Output "Additionally, these changes **MUST** be merged back without squashing"
42+
Write-Information 'Fetching from official repository'
43+
Invoke-External git fetch $officialRemoteName
44+
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+
}
50+
51+
if($PSCmdlet.ShouldProcess($tagName, "create signed tag"))
52+
{
53+
Write-Information 'Creating a signed tag of this branch as the release'
54+
Invoke-External git tag -s $tagName '-m' "Official release: $tagName"
55+
56+
Write-Information 'Verifying signature on tag'
57+
Invoke-External git tag -v $tagName
58+
}
59+
60+
if($PSCmdlet.ShouldProcess($tagName, "git push $officialRemoteName tag"))
61+
{
62+
Write-Information 'Pushing tag to official remote [Starts automated build release process]'
63+
Invoke-External git push $officialRemoteName tag $tagName
64+
}
65+
66+
if($PSCmdlet.ShouldProcess($releasebranch, "git checkout -b $mergeBackBranchName"))
67+
{
68+
Write-Information 'Creating local merge-back branch to merge changes associated with the release'
69+
# create a "merge-back" child branch to handle any updates/conflict resolutions when applying
70+
# the changes made in the release branch back to the develop branch.
71+
Invoke-External git checkout '-b' $mergeBackBranchName $releasebranch
72+
}
73+
74+
if($PSCmdlet.ShouldProcess("$forkRemoteName $mergeBackBranchName", "git push"))
75+
{
76+
Write-Information 'pushing merge-back branch to fork'
77+
Invoke-External git push $forkRemoteName $mergeBackBranchName
78+
}
79+
80+
if($PSCmdlet.ShouldProcess("$tagName", "Reset main to point to release tag"))
81+
{
82+
Write-Information 'Updating main to point to tagged release'
83+
Invoke-External git switch '-C' $mainBranchName $officialMainBranch
84+
Invoke-External git reset --hard $tagName
85+
Invoke-External git push --force $officialRemoteName $mainBranchName
86+
}

OneFlow/Start-Release.ps1

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using module '../PSModules/CommonBuild/CommonBuild.psd1'
2+
using module '../PsModules/RepoBuild/RepoBuild.psd1'
3+
14
<#
25
.SYNOPSIS
36
Creates a new public release branch the current branch state as an official release tag
@@ -9,21 +12,38 @@
912
.DESCRIPTION
1013
This function creates and publishes a Release branch
1114
#>
12-
13-
Param([switch]$TagOnly, [string]$commit = "")
14-
$repoRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, ".."))
15-
. (join-path $repoRoot repo-buildutils.ps1)
15+
[cmdletbinding(SupportsShouldProcess=$True)]
16+
Param(
17+
[string]$commit = ""
18+
)
1619
$buildInfo = Initialize-BuildEnvironment
1720

18-
# Create script scoped alias for git that throws a PowerShell exception if the command fails
19-
Set-Alias git Invoke-git -scope Script -option Private
21+
$officialRemoteName = Get-GitRemoteName $buildInfo official
22+
$forkRemoteName = Get-GitRemoteName $buildInfo fork
2023

2124
# create new local branch for the release
22-
$branchName = "release/$(Get-BuildVersionTag $buildInfo -ReleaseNameOnly)"
23-
git checkout -b $branchName $commit
25+
$branchName = "release/$(Get-BuildVersionTag $buildInfo)"
26+
Write-Information "Creating release branch in local repo"
27+
if ([string]::IsNullOrWhiteSpace($commit))
28+
{
29+
if($PSCmdlet.ShouldProcess($branchName, "git checkout -b"))
30+
{
31+
Invoke-External git checkout -b $branchName
32+
}
33+
}
34+
else
35+
{
36+
if($PSCmdlet.ShouldProcess("$branchName $commit", "git checkout -b"))
37+
{
38+
Invoke-External git checkout -b $branchName $commit
39+
}
40+
}
2441

25-
# Push to origin so it is clear to all a release is in process
26-
git push origin $branchName
42+
# Push to product repo so it is clear to all a release
43+
# is in process.
44+
Write-Information "Pushing branch to official repository (Push/Write permission required)"
45+
if($PSCmdlet.ShouldProcess("$officialRemoteName $branchName", "git push"))
46+
{
47+
Invoke-External git push $officialRemoteName $branchName
48+
}
2749

28-
# push to fork so that changes go through normal PR process
29-
git push -u $branchName

0 commit comments

Comments
 (0)