|
| 1 | +$gitHubBotUserName="github-actions[bot]" |
| 2 | +$gitHubBotEmail="41898282+github-actions[bot]@users.noreply.github.com" |
| 3 | + |
| 4 | +$repoViewResponse = gh repo view --json nameWithOwner | ConvertFrom-Json |
| 5 | + |
| 6 | +$gitRepository = $repoViewResponse.nameWithOwner |
| 7 | + |
| 8 | +function CreatePullRequestToUpdateChangelogsAndPublicApis { |
| 9 | + param( |
| 10 | + [Parameter(Mandatory=$true)][string]$component, |
| 11 | + [Parameter(Mandatory=$true)][string]$version, |
| 12 | + [Parameter()][string]$gitUserName=$gitHubBotUserName, |
| 13 | + [Parameter()][string]$gitUserEmail=$gitHubBotEmail, |
| 14 | + [Parameter()][string]$targetBranch="main" |
| 15 | + ) |
| 16 | + |
| 17 | + $projectContent = Get-Content -Path src/$component/$component.csproj |
| 18 | + |
| 19 | + $match = [regex]::Match($projectContent, '<MinVerTagPrefix>(.*)<\/MinVerTagPrefix>') |
| 20 | + if ($match.Success -eq $false) |
| 21 | + { |
| 22 | + throw 'Could not parse MinVerTagPrefix from project file' |
| 23 | + } |
| 24 | + |
| 25 | + $minVerTagPrefix = $match.Groups[1].Value |
| 26 | + $tag="${minVerTagPrefix}${version}" |
| 27 | + $branch="release/prepare-${tag}-release" |
| 28 | + |
| 29 | + git config user.name $gitUserName |
| 30 | + git config user.email $gitUserEmail |
| 31 | + |
| 32 | + git switch --create $branch 2>&1 | % ToString |
| 33 | + if ($LASTEXITCODE -gt 0) |
| 34 | + { |
| 35 | + throw 'git switch failure' |
| 36 | + } |
| 37 | + |
| 38 | + $body = |
| 39 | +@" |
| 40 | +Note: This PR was opened automatically by the [prepare release workflow](https://github.com/$gitRepository/actions/workflows/prepare-release.yml). |
| 41 | +
|
| 42 | +## Changes |
| 43 | +
|
| 44 | +* CHANGELOG files updated for projects being released. |
| 45 | +"@ |
| 46 | + |
| 47 | + # Update CHANGELOGs |
| 48 | + & ./build/scripts/update-changelogs.ps1 -minVerTagPrefix $minVerTagPrefix -version $version |
| 49 | + |
| 50 | + # Update publicApi files for stable releases |
| 51 | + if ($version -notlike "*-alpha*" -and $version -notlike "*-beta*" -and $version -notlike "*-rc*") |
| 52 | + { |
| 53 | + & ./build/scripts/finalize-publicapi.ps1 -minVerTagPrefix $minVerTagPrefix |
| 54 | + |
| 55 | + $body += "`r`n* Public API files updated for projects being released (only performed for stable releases)." |
| 56 | + } |
| 57 | + |
| 58 | + git commit -a -m "Prepare repo to release $tag." 2>&1 | % ToString |
| 59 | + if ($LASTEXITCODE -gt 0) |
| 60 | + { |
| 61 | + throw 'git commit failure' |
| 62 | + } |
| 63 | + |
| 64 | + git push -u origin $branch 2>&1 | % ToString |
| 65 | + if ($LASTEXITCODE -gt 0) |
| 66 | + { |
| 67 | + throw 'git push failure' |
| 68 | + } |
| 69 | + |
| 70 | + gh pr create ` |
| 71 | + --title "[repo] Prepare release $tag" ` |
| 72 | + --body $body ` |
| 73 | + --base $targetBranch ` |
| 74 | + --head $branch ` |
| 75 | + --label infra |
| 76 | +} |
| 77 | + |
| 78 | +Export-ModuleMember -Function CreatePullRequestToUpdateChangelogsAndPublicApis |
| 79 | + |
| 80 | +function LockPullRequestAndPostNoticeToCreateReleaseTag { |
| 81 | + param( |
| 82 | + [Parameter(Mandatory=$true)][string]$pullRequestNumber, |
| 83 | + [Parameter()][string]$gitUserName=$gitHubBotUserName, |
| 84 | + [Parameter()][string]$gitUserEmail=$gitHubBotEmail |
| 85 | + ) |
| 86 | + |
| 87 | + git config user.name $gitUserName |
| 88 | + git config user.email $gitUserEmail |
| 89 | + |
| 90 | + $prViewResponse = gh pr view $pullRequestNumber --json mergeCommit,author,title | ConvertFrom-Json |
| 91 | + |
| 92 | + if ($prViewResponse.author.is_bot -eq $false -or $prViewResponse.author.login -ne 'app/github-actions') |
| 93 | + { |
| 94 | + throw 'PR author was unexpected' |
| 95 | + } |
| 96 | + |
| 97 | + $match = [regex]::Match($prViewResponse.title, '^\[repo\] Prepare release (.*)$') |
| 98 | + if ($match.Success -eq $false) |
| 99 | + { |
| 100 | + throw 'Could not parse tag from PR title' |
| 101 | + } |
| 102 | + |
| 103 | + $tag = $match.Groups[1].Value |
| 104 | + |
| 105 | + $commit = $prViewResponse.mergeCommit.oid |
| 106 | + if ([string]::IsNullOrEmpty($commit) -eq $true) |
| 107 | + { |
| 108 | + throw 'Could not find merge commit' |
| 109 | + } |
| 110 | + |
| 111 | + $body = |
| 112 | +@" |
| 113 | +I noticed this PR was merged. |
| 114 | +
|
| 115 | +Post a comment with "/CreateReleaseTag" in the body if you would like me to create the release tag ``$tag`` for [the merge commit](https://github.com/$gitRepository/commit/$commit) and then trigger the package workflow. |
| 116 | +"@ |
| 117 | + |
| 118 | + gh pr comment $pullRequestNumber --body $body |
| 119 | + |
| 120 | + gh pr lock $pullRequestNumber |
| 121 | +} |
| 122 | + |
| 123 | +Export-ModuleMember -Function LockPullRequestAndPostNoticeToCreateReleaseTag |
| 124 | + |
| 125 | +function CreateReleaseTag { |
| 126 | + param( |
| 127 | + [Parameter(Mandatory=$true)][string]$pullRequestNumber, |
| 128 | + [Parameter(Mandatory=$true)][string]$actionRunId, |
| 129 | + [Parameter()][string]$gitUserName=$gitHubBotUserName, |
| 130 | + [Parameter()][string]$gitUserEmail=$gitHubBotEmail, |
| 131 | + [Parameter()][ref]$tag |
| 132 | + ) |
| 133 | + |
| 134 | + git config user.name $gitUserName |
| 135 | + git config user.email $gitUserEmail |
| 136 | + |
| 137 | + $prViewResponse = gh pr view $pullRequestNumber --json mergeCommit,author,title | ConvertFrom-Json |
| 138 | + |
| 139 | + if ($prViewResponse.author.is_bot -eq $false -or $prViewResponse.author.login -ne 'app/github-actions') |
| 140 | + { |
| 141 | + throw 'PR author was unexpected' |
| 142 | + } |
| 143 | + |
| 144 | + $match = [regex]::Match($prViewResponse.title, '^\[repo\] Prepare release (.*)$') |
| 145 | + if ($match.Success -eq $false) |
| 146 | + { |
| 147 | + throw 'Could not parse tag from PR title' |
| 148 | + } |
| 149 | + |
| 150 | + $tagValue = $match.Groups[1].Value |
| 151 | + |
| 152 | + $commit = $prViewResponse.mergeCommit.oid |
| 153 | + if ([string]::IsNullOrEmpty($commit) -eq $true) |
| 154 | + { |
| 155 | + throw 'Could not find merge commit' |
| 156 | + } |
| 157 | + |
| 158 | + git tag -a $tagValue -m "$tagValue" $commit 2>&1 | % ToString |
| 159 | + if ($LASTEXITCODE -gt 0) |
| 160 | + { |
| 161 | + throw 'git tag failure' |
| 162 | + } |
| 163 | + |
| 164 | + git push origin $tagValue 2>&1 | % ToString |
| 165 | + if ($LASTEXITCODE -gt 0) |
| 166 | + { |
| 167 | + throw 'git push failure' |
| 168 | + } |
| 169 | + |
| 170 | + gh pr unlock $pullRequestNumber |
| 171 | + |
| 172 | + $body = |
| 173 | +@" |
| 174 | +I just pushed the [$tagValue](https://github.com/$gitRepository/releases/tag/$tagValue) tag. |
| 175 | +
|
| 176 | +The [package workflow](https://github.com/$gitRepository/actions/runs/$actionRunId) should begin momentarily. |
| 177 | +"@ |
| 178 | + |
| 179 | + gh pr comment $pullRequestNumber --body $body |
| 180 | + |
| 181 | + $tag.value = $tagValue |
| 182 | +} |
| 183 | + |
| 184 | +Export-ModuleMember -Function CreateReleaseTag |
| 185 | + |
| 186 | +function PostPackagesReadyNotice { |
| 187 | + param( |
| 188 | + [Parameter(Mandatory=$true)][string]$pullRequestNumber, |
| 189 | + [Parameter(Mandatory=$true)][string]$tag, |
| 190 | + [Parameter(Mandatory=$true)][string]$packagesUrl |
| 191 | + ) |
| 192 | + |
| 193 | + $body = |
| 194 | +@" |
| 195 | +The packages for [$tag](https://github.com/$gitRepository/releases/tag/$tag) are now available: $packagesUrl. |
| 196 | +
|
| 197 | +Have a nice day! |
| 198 | +"@ |
| 199 | + |
| 200 | + gh pr comment $pullRequestNumber --body $body |
| 201 | +} |
| 202 | + |
| 203 | +Export-ModuleMember -Function PostPackagesReadyNotice |
0 commit comments