Skip to content

Commit

Permalink
[repo] Post-release automation improvements (#5664)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Jun 3, 2024
1 parent c38cc27 commit 4d02fe1
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 20 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ jobs:
needs:
- automation

if: |
needs.automation.outputs.enabled
&&
(
(github.ref_type == 'tag' && startsWith(github.ref_name, 'core-') && !contains(github.ref_name, '-alpha') && !contains(github.ref_name, '-beta') && !contains(github.ref_name, '-rc'))
|| (inputs.tag && startsWith(inputs.tag, 'core-') && !contains(inputs.tag, '-alpha') && !contains(inputs.tag, '-beta') && !contains(inputs.tag, '-rc'))
)
if: needs.automation.outputs.enabled

env:
GH_TOKEN: ${{ secrets[needs.automation.outputs.token-secret-name] }}

steps:
- uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit. We need all the tags
# for this work.
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
token: ${{ secrets[needs.automation.outputs.token-secret-name] }}

- name: Create GitHub Pull Request to update stable build version in props
if: |
(github.ref_type == 'tag' && startsWith(github.ref_name, 'core-') && !contains(github.ref_name, '-alpha') && !contains(github.ref_name, '-beta') && !contains(github.ref_name, '-rc'))
|| (inputs.tag && startsWith(inputs.tag, 'core-') && !contains(inputs.tag, '-alpha') && !contains(inputs.tag, '-beta') && !contains(inputs.tag, '-rc'))
shell: pwsh
run: |
Import-Module .\build\scripts\post-release.psm1
Expand All @@ -49,3 +49,23 @@ jobs:
-targetBranch '${{ github.event.repository.default_branch }}' `
-gitUserName '${{ needs.automation.outputs.username }}' `
-gitUserEmail '${{ needs.automation.outputs.email }}'
- name: Invoke core version update workflow in opentelemetry-dotnet-contrib repository
if: vars.CONTRIB_REPO
shell: pwsh
run: |
Import-Module .\build\scripts\post-release.psm1
InvokeCoreVersionUpdateWorkflowInRemoteRepository `
-remoteGitRepository '${{ vars.CONTRIB_REPO }}' `
-tag '${{ inputs.tag || github.ref_name }}'
- name: Post notice when release is published
shell: pwsh
run: |
Import-Module .\build\scripts\post-release.psm1
TryPostReleasePublishedNoticeOnPrepareReleasePullRequest `
-gitRepository '${{ github.repository }}' `
-botUserName '${{ needs.automation.outputs.username }}' `
-tag '${{ inputs.tag || github.ref_name }}'
25 changes: 14 additions & 11 deletions build/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,21 @@
workflow creates a draft release for the tag which was pushed. Edit the
draft Release and click `Publish release`.
14. If a new stable version of the core packages was released, a draft PR should
have been automatically created by the [Build, pack, and publish to
MyGet](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/publish-packages-1.0.yml)
14. If a new stable version of the core packages was released, a PR should have
been automatically created by the [Complete
release](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/post-release.yml)
workflow to update the `OTelLatestStableVer` property in
`Directory.Packages.props` to the just released stable version. Mark that PR
`Ready for review` and then merge it once the build passes (this requires
the packages be available on NuGet).
15. If a new stable version of the core packages was released, open an issue in
the
[opentelemetry-dotnet-contrib](https://github.com/open-telemetry/opentelemetry-dotnet-contrib)
repo to notify maintainers to begin upgrading dependencies.
`Directory.Packages.props` to the just released stable version. Merge that
PR once the build passes (this requires the packages be available on NuGet).
15. The [Complete
release](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/post-release.yml)
workflow should have invoked the [Core version
update](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/actions/workflows/core-version-update.yml)
workflow on the
[opentelemetry-dotnet-contrib](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/)
repository which opens a PR to update dependencies. Verify this PR was
opened successfully.
16. Post an announcement in the [Slack
channel](https://cloud-native.slack.com/archives/C01N3BC2W7Q). Note any big
Expand Down
84 changes: 82 additions & 2 deletions build/scripts/post-release.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ function TryPostPackagesReadyNoticeOnPrepareReleasePullRequest {
$body =
@"
The packages for [$tag](https://github.com/$gitRepository/releases/tag/$tag) are now available: $packagesUrl.
Have a nice day!
"@

$pullRequestNumber = $pr.number
Expand Down Expand Up @@ -227,3 +225,85 @@ Merge once packages are available on NuGet and the build passes.
}

Export-ModuleMember -Function CreateStableVersionUpdatePullRequest

function InvokeCoreVersionUpdateWorkflowInRemoteRepository {
param(
[Parameter(Mandatory=$true)][string]$remoteGitRepository,
[Parameter(Mandatory=$true)][string]$tag,
[Parameter()][string]$targetBranch="main"
)

$match = [regex]::Match($tag, '^(.*?-)(.*)$')
if ($match.Success -eq $false)
{
throw 'Could not parse prefix or version from tag'
}

gh workflow run "core-version-update.yml" `
--repo $remoteGitRepository `
--ref $targetBranch `
--field "tag=$tag"
}

Export-ModuleMember -Function InvokeCoreVersionUpdateWorkflowInRemoteRepository

function TryPostReleasePublishedNoticeOnPrepareReleasePullRequest {
param(
[Parameter(Mandatory=$true)][string]$gitRepository,
[Parameter(Mandatory=$true)][string]$botUserName,
[Parameter(Mandatory=$true)][string]$tag
)

$tagSha = git rev-list -n 1 $tag 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
throw 'git rev-list failure'
}

$prListResponse = gh pr list --search $tagSha --state merged --json number,author,title,comments | ConvertFrom-Json

if ($prListResponse.Length -eq 0)
{
Write-Host 'No prepare release PR found for tag & commit skipping post notice'
return
}

foreach ($pr in $prListResponse)
{
if ($pr.author.login -ne $botUserName -or $pr.title -ne "[repo] Prepare release $tag")
{
continue
}

$foundComment = $false
foreach ($comment in $pr.comments)
{
if ($comment.author.login -eq $botUserName -and $comment.body.StartsWith("The packages for [$tag](https://github.com/$gitRepository/releases/tag/$tag) are now available:"))
{
$foundComment = $true
break
}
}

if ($foundComment -eq $false)
{
continue
}

$body =
@"
The release [$tag](https://github.com/$gitRepository/releases/tag/$tag) has been published and packages should be available on NuGet momentarily.
Have a nice day!
"@

$pullRequestNumber = $pr.number

gh pr comment $pullRequestNumber --body $body
return
}

Write-Host 'No prepare release PR found matched author and title with a valid comment'
}

Export-ModuleMember -Function TryPostReleasePublishedNoticeOnPrepareReleasePullRequest

0 comments on commit 4d02fe1

Please sign in to comment.