|
| 1 | +using module '../PSModules/CommonBuild/CommonBuild.psd1' |
| 2 | +using module '../PsModules/RepoBuild/RepoBuild.psd1' |
| 3 | + |
1 | 4 | <# |
2 | 5 | .SYNOPSIS |
3 | 6 | Publishes the current release as a new branch to the upstream repository |
|
16 | 19 | .NOTE |
17 | 20 | For the gory details of this process see: https://www.endoflineblog.com/implementing-oneflow-on-github-bitbucket-and-gitlab |
18 | 21 | #> |
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() |
23 | 24 | $buildInfo = Initialize-BuildEnvironment |
24 | 25 |
|
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) |
27 | 28 |
|
28 | 29 | # merging the tag to develop branch on the official repository triggers the official build and release of the NuGet Packages |
29 | 30 | $tagName = Get-BuildVersionTag $buildInfo |
| 31 | +$officialRemoteName = Get-GitRemoteName $buildInfo official |
| 32 | +$forkRemoteName = Get-GitRemoteName $buildInfo fork |
| 33 | + |
30 | 34 | $releaseBranch = "release/$tagName" |
| 35 | +$officialReleaseBranch = "$officialRemoteName/$releaseBranch" |
| 36 | + |
| 37 | +$mainBranchName = "master" |
| 38 | +$officialMainBranch = "$officialRemoteName/$mainBranchName" |
| 39 | + |
31 | 40 | $mergeBackBranchName = "merge-back-$tagName" |
32 | 41 |
|
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 | +} |
0 commit comments