Skip to content

Commit 2d2fcf9

Browse files
authored
[repo] Post-release workflow refactor (#5617)
1 parent cf8ca09 commit 2d2fcf9

File tree

3 files changed

+176
-138
lines changed

3 files changed

+176
-138
lines changed

.github/workflows/publish-packages-1.0.yml

+8-138
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ on:
1313
tags:
1414
- 'core-*'
1515
- 'coreunstable-*'
16-
- 'Instrumentation.*-'
1716
workflow_call:
1817
inputs:
1918
tag:
@@ -79,87 +78,10 @@ jobs:
7978
if: github.ref_type == 'tag' || inputs.tag
8079
shell: pwsh
8180
run: |
82-
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
83-
84-
$notes = ''
85-
$firstPackageVersion = ''
86-
87-
foreach ($package in $packages)
88-
{
89-
$match = [regex]::Match($package, '(.*)\.(\d+\.\d+\.\d+.*?)\.nupkg')
90-
$packageName = $match.Groups[1].Value
91-
$packageVersion = $match.Groups[2].Value
92-
93-
if ($firstPackageVersion -eq '')
94-
{
95-
$firstPackageVersion = $packageVersion
96-
}
97-
98-
$changelogContent = Get-Content -Path "src/$packageName/CHANGELOG.md"
99-
100-
$headingWritten = $false
101-
$started = $false
102-
$content = ""
103-
104-
foreach ($line in $changelogContent)
105-
{
106-
if ($line -like "## $packageVersion" -and $started -ne $true)
107-
{
108-
$started = $true
109-
}
110-
elseif ($line -like "Released *" -and $started -eq $true)
111-
{
112-
continue
113-
}
114-
elseif ($line -like "## *" -and $started -eq $true)
115-
{
116-
break
117-
}
118-
else
119-
{
120-
if ($started -eq $true -and ([string]::IsNullOrWhitespace($line) -eq $false -or $content.Length -gt 0))
121-
{
122-
$content += " " + $line + "`r`n"
123-
}
124-
}
125-
}
126-
127-
if ([string]::IsNullOrWhitespace($content) -eq $true)
128-
{
129-
$content = " No notable changes."
130-
}
131-
132-
$content = $content.trimend()
133-
134-
$notes +=
135-
@"
136-
* NuGet: [$packageName v$packageVersion](https://www.nuget.org/packages/$packageName/$packageVersion)
137-
138-
$content
139-
140-
See [CHANGELOG](https://github.com/${{ github.repository }}/blob/${{ inputs.tag || github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
141-
142-
"@
143-
}
144-
145-
if ($firstPackageVersion -match '-alpha' -or $firstPackageVersion -match '-beta' -or $firstPackageVersion -match '-rc')
146-
{
147-
gh release create ${{ inputs.tag || github.ref_name }} `
148-
--title ${{ inputs.tag || github.ref_name }} `
149-
--verify-tag `
150-
--notes "$notes" `
151-
--prerelease `
152-
--draft
153-
}
154-
else
155-
{
156-
gh release create ${{ inputs.tag || github.ref_name }} `
157-
--title ${{ inputs.tag || github.ref_name }} `
158-
--verify-tag `
159-
--notes "$notes" `
160-
--latest `
161-
--draft
162-
}
81+
Import-Module .\build\scripts\post-release.psm1
82+
83+
CreateDraftRelease `
84+
-tag '${{ inputs.tag || github.ref_name }}'
16385
env:
16486
GH_TOKEN: ${{ github.token }}
16587

@@ -169,61 +91,9 @@ jobs:
16991
|| (inputs.tag && startsWith(inputs.tag, 'core-') && !contains(inputs.tag, '-alpha') && !contains(inputs.tag, '-beta') && !contains(inputs.tag, '-rc'))
17092
shell: pwsh
17193
run: |
172-
git config user.name "github-actions[bot]"
173-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
174-
175-
git switch --create release/post-stable-${{ inputs.tag || github.ref_name }}-update main 2>&1 | % ToString
176-
if ($LASTEXITCODE -gt 0)
177-
{
178-
Write-Error 'git switch failure'
179-
Return
180-
}
181-
182-
$match = [regex]::Match('${{ inputs.tag || github.ref_name }}', '.*?-(.*)')
183-
$packageVersion = $match.Groups[1].Value
184-
185-
(Get-Content Directory.Packages.props) `
186-
-replace '<OTelLatestStableVer>.*<\/OTelLatestStableVer>', "<OTelLatestStableVer>$packageVersion</OTelLatestStableVer>" |
187-
Set-Content Directory.Packages.props
188-
189-
git add Directory.Packages.props 2>&1 | % ToString
190-
if ($LASTEXITCODE -gt 0)
191-
{
192-
Write-Error 'git add failure'
193-
Return
194-
}
195-
196-
git commit -m "Update OTelLatestStableVer in Directory.Packages.props to $packageVersion." 2>&1 | % ToString
197-
if ($LASTEXITCODE -gt 0)
198-
{
199-
Write-Error 'git commit failure'
200-
Return
201-
}
202-
203-
git push -u origin release/post-stable-${{ inputs.tag || github.ref_name }}-update 2>&1 | % ToString
204-
if ($LASTEXITCODE -gt 0)
205-
{
206-
Write-Error 'git push failure'
207-
Return
208-
}
209-
210-
$body =
211-
@"
212-
Note: This PR was opened automatically by the [package workflow](https://github.com/${{ github.repository }}/actions/workflows/publish-packages-1.0.yml).
213-
214-
Merge once packages are available on NuGet and the build passes.
215-
216-
## Changes
217-
218-
* Sets `OTelLatestStableVer` in `Directory.Packages.props` to `$packageVersion`.
219-
"@
220-
221-
gh pr create `
222-
--title "[repo] Core stable release $packageVersion updates" `
223-
--body $body `
224-
--base main `
225-
--head release/post-stable-${{ inputs.tag || github.ref_name }}-update `
226-
--label infra `
227-
--draft
94+
Import-Module .\build\scripts\post-release.psm1
95+
96+
CreateStableVersionUpdatePullRequest `
97+
-tag '${{ inputs.tag || github.ref_name }}'
22898
env:
22999
GH_TOKEN: ${{ github.token }}

OpenTelemetry.sln

+1
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{4498
338338
ProjectSection(SolutionItems) = preProject
339339
build\scripts\add-labels.ps1 = build\scripts\add-labels.ps1
340340
build\scripts\finalize-publicapi.ps1 = build\scripts\finalize-publicapi.ps1
341+
build\scripts\post-release.psm1 = build\scripts\post-release.psm1
341342
build\scripts\prepare-release.psm1 = build\scripts\prepare-release.psm1
342343
build\scripts\update-changelogs.ps1 = build\scripts\update-changelogs.ps1
343344
EndProjectSection

build/scripts/post-release.psm1

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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 CreateDraftRelease {
9+
param(
10+
[Parameter(Mandatory=$true)][string]$tag
11+
)
12+
13+
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
14+
15+
$notes = ''
16+
$firstPackageVersion = ''
17+
18+
foreach ($package in $packages)
19+
{
20+
$match = [regex]::Match($package, '(.*)\.(\d+\.\d+\.\d+.*?)\.nupkg')
21+
$packageName = $match.Groups[1].Value
22+
$packageVersion = $match.Groups[2].Value
23+
24+
if ($firstPackageVersion -eq '')
25+
{
26+
$firstPackageVersion = $packageVersion
27+
}
28+
29+
$changelogContent = Get-Content -Path "src/$packageName/CHANGELOG.md"
30+
31+
$headingWritten = $false
32+
$started = $false
33+
$content = ""
34+
35+
foreach ($line in $changelogContent)
36+
{
37+
if ($line -like "## $packageVersion" -and $started -ne $true)
38+
{
39+
$started = $true
40+
}
41+
elseif ($line -like "Released *" -and $started -eq $true)
42+
{
43+
continue
44+
}
45+
elseif ($line -like "## *" -and $started -eq $true)
46+
{
47+
break
48+
}
49+
else
50+
{
51+
if ($started -eq $true -and ([string]::IsNullOrWhitespace($line) -eq $false -or $content.Length -gt 0))
52+
{
53+
$content += " " + $line + "`r`n"
54+
}
55+
}
56+
}
57+
58+
if ([string]::IsNullOrWhitespace($content) -eq $true)
59+
{
60+
$content = " No notable changes."
61+
}
62+
63+
$content = $content.trimend()
64+
65+
$notes +=
66+
@"
67+
* NuGet: [$packageName v$packageVersion](https://www.nuget.org/packages/$packageName/$packageVersion)
68+
69+
$content
70+
71+
See [CHANGELOG](https://github.com/$gitRepository/blob/$tag/src/$packageName/CHANGELOG.md) for details.
72+
73+
"@
74+
}
75+
76+
if ($firstPackageVersion -match '-alpha' -or $firstPackageVersion -match '-beta' -or $firstPackageVersion -match '-rc')
77+
{
78+
gh release create $tag `
79+
--title $tag `
80+
--verify-tag `
81+
--notes $notes `
82+
--prerelease `
83+
--draft
84+
}
85+
else
86+
{
87+
gh release create $tag `
88+
--title $tag `
89+
--verify-tag `
90+
--notes $notes `
91+
--latest `
92+
--draft
93+
}
94+
}
95+
96+
Export-ModuleMember -Function CreateDraftRelease
97+
98+
function CreateStableVersionUpdatePullRequest {
99+
param(
100+
[Parameter(Mandatory=$true)][string]$tag,
101+
[Parameter()][string]$gitUserName=$gitHubBotUserName,
102+
[Parameter()][string]$gitUserEmail=$gitHubBotEmail,
103+
[Parameter()][string]$targetBranch="main"
104+
)
105+
106+
$match = [regex]::Match($tag, '.*?-(.*)')
107+
if ($match.Success -eq $false)
108+
{
109+
throw 'Could not parse version from tag'
110+
}
111+
112+
$packageVersion = $match.Groups[1].Value
113+
114+
$branch="release/post-stable-${tag}-update"
115+
116+
git config user.name $gitUserName
117+
git config user.email $gitUserEmail
118+
119+
git switch --create $branch origin/$targetBranch --no-track 2>&1 | % ToString
120+
if ($LASTEXITCODE -gt 0)
121+
{
122+
throw 'git switch failure'
123+
}
124+
125+
(Get-Content Directory.Packages.props) `
126+
-replace '<OTelLatestStableVer>.*<\/OTelLatestStableVer>', "<OTelLatestStableVer>$packageVersion</OTelLatestStableVer>" |
127+
Set-Content Directory.Packages.props
128+
129+
git add Directory.Packages.props 2>&1 | % ToString
130+
if ($LASTEXITCODE -gt 0)
131+
{
132+
throw 'git add failure'
133+
}
134+
135+
git commit -m "Update OTelLatestStableVer in Directory.Packages.props to $packageVersion." 2>&1 | % ToString
136+
if ($LASTEXITCODE -gt 0)
137+
{
138+
throw 'git commit failure'
139+
}
140+
141+
git push -u origin $branch 2>&1 | % ToString
142+
if ($LASTEXITCODE -gt 0)
143+
{
144+
throw 'git push failure'
145+
}
146+
147+
$body =
148+
@"
149+
Note: This PR was opened automatically by the [package workflow](https://github.com/$gitRepository/actions/workflows/publish-packages-1.0.yml).
150+
151+
Merge once packages are available on NuGet and the build passes.
152+
153+
## Changes
154+
155+
* Sets ``OTelLatestStableVer`` in ``Directory.Packages.props`` to ``$packageVersion``.
156+
"@
157+
158+
gh pr create `
159+
--title "[repo] Core stable release $packageVersion updates" `
160+
--body $body `
161+
--base $targetBranch `
162+
--head $branch `
163+
--label infra `
164+
--draft
165+
}
166+
167+
Export-ModuleMember -Function CreateStableVersionUpdatePullRequest

0 commit comments

Comments
 (0)