Skip to content

Commit

Permalink
[repo] Release process tweaks & improvements 4 (#5598)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Reiley Yang <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 15cea9c commit 9d12b36
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 36 deletions.
139 changes: 139 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Prepare for a release

on:
workflow_dispatch:
inputs:
tag-prefix:
type: choice
options:
- core-
- coreunstable-
description: 'Release tag prefix'
required: true
version:
type: string
description: 'Release version'
required: true

pull_request:
types:
- closed

issue_comment:
types:
- created

permissions:
contents: write
pull-requests: write

jobs:
prepare-release-pr:
if: github.event_name == 'workflow_dispatch'

runs-on: windows-latest

steps:
- name: check out code
uses: actions/checkout@v4

- name: Create GitHub Pull Request to prepare release
shell: pwsh
run: |
Import-Module .\build\scripts\prepare-release.psm1
CreatePullRequestToUpdateChangelogsAndPublicApis `
-minVerTagPrefix '${{ inputs.tag-prefix }}' `
-version '${{ inputs.version }}' `
-targetBranch '${{ github.ref_name }}'
env:
GH_TOKEN: ${{ github.token }}

lock-pr-and-post-notice-to-create-release-tag:
if: |
github.event_name == 'pull_request'
&& github.event.action == 'closed'
&& github.event.pull_request.user.login == 'github-actions[bot]'
&& github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.title, '[repo] Prepare release ')
runs-on: windows-latest

steps:
- name: check out code
uses: actions/checkout@v4

- name: Lock GitHub Pull Request to prepare release
shell: pwsh
run: |
Import-Module .\build\scripts\prepare-release.psm1
LockPullRequestAndPostNoticeToCreateReleaseTag `
-pullRequestNumber '${{ github.event.pull_request.number }}'
env:
GH_TOKEN: ${{ github.token }}

create-release-tag-unlock-pr-post-notice:
if: |
github.event_name == 'issue_comment'
&& github.event.issue.pull_request
&& github.event.issue.locked == true
&& contains(github.event.comment.body, '/CreateReleaseTag')
&& startsWith(github.event.issue.title, '[repo] Prepare release ')
&& github.event.issue.pull_request.merged_at
runs-on: windows-latest

outputs:
tag: ${{ steps.create-tag.outputs.tag }}

steps:
- name: check out code
uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit which fails the git tag operation below
fetch-depth: 0

- name: Create release tag
id: create-tag
shell: pwsh
run: |
Import-Module .\build\scripts\prepare-release.psm1
$tag = ''
CreateReleaseTag `
-pullRequestNumber '${{ github.event.issue.number }}' `
-actionRunId '${{ github.run_id }}' `
-tag ([ref]$tag)
echo "tag=$tag" >> $env:GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}

invoke-package-workflow:
needs: create-release-tag-unlock-pr-post-notice
uses: ./.github/workflows/publish-packages-1.0.yml
with:
tag: ${{ needs.create-release-tag-unlock-pr-post-notice.outputs.tag }}

post-packages-ready-notice:
needs:
- create-release-tag-unlock-pr-post-notice
- invoke-package-workflow
runs-on: windows-latest
steps:
- name: check out code
uses: actions/checkout@v4

- name: Post notice when packages are ready
shell: pwsh
run: |
Import-Module .\build\scripts\prepare-release.psm1
PostPackagesReadyNotice `
-pullRequestNumber '${{ github.event.issue.number }}' `
-tag '${{ needs.create-release-tag-unlock-pr-post-notice.outputs.tag }}' `
-packagesUrl '${{ needs.invoke-package-workflow.outputs.artifact-url }}'
env:
GH_TOKEN: ${{ github.token }}
47 changes: 32 additions & 15 deletions .github/workflows/publish-packages-1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ on:
- 'core-*'
- 'coreunstable-*'
- 'Instrumentation.*-'
workflow_call:
inputs:
tag:
required: true
type: string
outputs:
artifact-id:
value: ${{ jobs.build-pack-publish.outputs.artifact-id }}
artifact-url:
value: ${{ jobs.build-pack-publish.outputs.artifact-url }}
schedule:
- cron: '0 0 * * *' # once in a day at 00:00

Expand All @@ -25,14 +35,18 @@ jobs:
build-pack-publish:
runs-on: windows-latest

outputs:
artifact-id: ${{ steps.upload-artifacts.outputs.artifact-id }}
artifact-url: ${{ steps.upload-artifacts.outputs.artifact-url }}

steps:
- uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit. MinVer needs to find
# the version tag which is typically NOT on the first commit so we
# retrieve them all.
fetch-depth: 0
ref: ${{ github.ref || 'main' }}
ref: ${{ inputs.tag || github.ref || 'main' }}

- name: Setup dotnet
uses: actions/setup-dotnet@v4
Expand All @@ -44,12 +58,13 @@ jobs:
run: dotnet build OpenTelemetry.proj --configuration Release --no-restore -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} -p:RunningDotNetPack=true

- name: dotnet pack
run: dotnet pack OpenTelemetry.proj --configuration Release --no-restore --no-build -p:PackTag=${{ github.ref_type == 'tag' && github.ref_name || '' }}
run: dotnet pack OpenTelemetry.proj --configuration Release --no-restore --no-build -p:PackTag=${{ github.ref_type == 'tag' && github.ref_name || inputs.tag || '' }}

- name: Publish Artifacts
id: upload-artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}-packages
name: ${{ inputs.tag || github.ref_name }}-packages
path: '**/bin/**/*.*nupkg'

- name: Publish MyGet
Expand All @@ -61,7 +76,7 @@ jobs:
nuget push **/bin/**/*.nupkg -Source https://www.myget.org/F/opentelemetry/api/v2/package
- name: Create GitHub Release draft
if: github.ref_type == 'tag'
if: github.ref_type == 'tag' || inputs.tag
shell: pwsh
run: |
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
Expand All @@ -88,7 +103,7 @@ jobs:
foreach ($line in $changelogContent)
{
if ($line -like "## ${{ github.ref_name }}" -and $started -ne $true)
if ($line -like "## $packageVersion" -and $started -ne $true)
{
$started = $true
}
Expand Down Expand Up @@ -122,24 +137,24 @@ jobs:
$content
See [CHANGELOG](https:/${{ github.repository }}/blob/${{ github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
See [CHANGELOG](https:/${{ github.repository }}/blob/${{ inputs.tag || github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
"@
}
if ($firstPackageVersion -match '-alpha' -or $firstPackageVersion -match '-beta' -or $firstPackageVersion -match '-rc')
{
gh release create ${{ github.ref_name }} `
--title ${{ github.ref_name }} `
gh release create ${{ inputs.tag || github.ref_name }} `
--title ${{ inputs.tag || github.ref_name }} `
--verify-tag `
--notes "$notes" `
--prerelease `
--draft
}
else
{
gh release create ${{ github.ref_name }} `
--title ${{ github.ref_name }} `
gh release create ${{ inputs.tag || github.ref_name }} `
--title ${{ inputs.tag || github.ref_name }} `
--verify-tag `
--notes "$notes" `
--latest `
Expand All @@ -149,20 +164,22 @@ jobs:
GH_TOKEN: ${{ github.token }}

- name: Create GitHub draft 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')
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: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch --create release/post-stable-${{ github.ref_name }}-update 2>&1 | % ToString
git switch --create release/post-stable-${{ inputs.tag || github.ref_name }}-update main 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git switch failure'
Return
}
$match = [regex]::Match('${{ github.ref_name }}', '.*?-(.*)')
$match = [regex]::Match('${{ inputs.tag || github.ref_name }}', '.*?-(.*)')
$packageVersion = $match.Groups[1].Value
(Get-Content Directory.Packages.props) `
Expand All @@ -183,7 +200,7 @@ jobs:
Return
}
git push -u origin release/post-stable-${{ github.ref_name }}-update 2>&1 | % ToString
git push -u origin release/post-stable-${{ inputs.tag || github.ref_name }}-update 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
{
Write-Error 'git push failure'
Expand All @@ -205,7 +222,7 @@ jobs:
--title "[repo] Core stable release $packageVersion updates" `
--body $body `
--base main `
--head release/post-stable-${{ github.ref_name }}-update `
--head release/post-stable-${{ inputs.tag || github.ref_name }}-update `
--label infra `
--draft
env:
Expand Down
7 changes: 6 additions & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Default state for all rules
default: true

# allow long lines for tables and code blocks
# MD013/line-length : Line length : https:/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md
MD013:
code_blocks: false
tables: false

# MD033/no-inline-html : Inline HTML : https:/DavidAnson/markdownlint/blob/v0.32.1/doc/md033.md
MD033:
# Allowed elements
allowed_elements: [ 'details', 'summary' ]
6 changes: 4 additions & 2 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E
build\docker-compose.net6.0.yml = build\docker-compose.net6.0.yml
build\docker-compose.net7.0.yml = build\docker-compose.net7.0.yml
build\docker-compose.net8.0.yml = build\docker-compose.net8.0.yml
build\finalize-publicapi.ps1 = build\finalize-publicapi.ps1
build\GlobalAttrExclusions.txt = build\GlobalAttrExclusions.txt
build\opentelemetry-icon-color.png = build\opentelemetry-icon-color.png
build\OpenTelemetry.prod.loose.ruleset = build\OpenTelemetry.prod.loose.ruleset
Expand All @@ -46,7 +45,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E
build\test-aot-compatibility.ps1 = build\test-aot-compatibility.ps1
build\test-threadSafety.ps1 = build\test-threadSafety.ps1
build\UnstableCoreLibraries.proj = build\UnstableCoreLibraries.proj
build\update-changelogs.ps1 = build\update-changelogs.ps1
build\xunit.runner.json = build\xunit.runner.json
EndProjectSection
EndProject
Expand Down Expand Up @@ -99,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\dotnet-format.yml = .github\workflows\dotnet-format.yml
.github\workflows\markdownlint.yml = .github\workflows\markdownlint.yml
.github\workflows\package-validation.yml = .github\workflows\package-validation.yml
.github\workflows\prepare-release.yml = .github\workflows\prepare-release.yml
.github\workflows\publish-packages-1.0.yml = .github\workflows\publish-packages-1.0.yml
.github\workflows\sanitycheck.yml = .github\workflows\sanitycheck.yml
.github\workflows\stale.yml = .github\workflows\stale.yml
Expand Down Expand Up @@ -341,6 +340,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{44982E0D-C8C6-42DC-9F8F-714981F27CE6}"
ProjectSection(SolutionItems) = preProject
build\scripts\add-labels.ps1 = build\scripts\add-labels.ps1
build\scripts\finalize-publicapi.ps1 = build\scripts\finalize-publicapi.ps1
build\scripts\prepare-release.psm1 = build\scripts\prepare-release.psm1
build\scripts\update-changelogs.ps1 = build\scripts\update-changelogs.ps1
EndProjectSection
EndProject
Global
Expand Down
Loading

0 comments on commit 9d12b36

Please sign in to comment.