Skip to content

Commit ef8e4e9

Browse files
authored
[repo] Refactor release creation into a powershell module (open-telemetry#1801)
1 parent 137e43b commit ef8e4e9

File tree

4 files changed

+105
-44
lines changed

4 files changed

+105
-44
lines changed

.github/workflows/Component.Package.yml

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,18 @@ jobs:
4545
path: 'src/*/bin/Release/*.*nupkg'
4646

4747
- name: Publish NuGets
48+
env:
49+
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN != '' }}
50+
if: env.NUGET_TOKEN_EXISTS == 'true' # Skip NuGet publish if run on a fork without the secret
4851
run: |
4952
nuget push src/*/bin/Release/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_TOKEN }} -SymbolApiKey ${{ secrets.NUGET_TOKEN }}
5053
5154
- name: Create GitHub Release
5255
shell: pwsh
5356
run: |
54-
$packages = (Get-ChildItem -Path src/*/bin/Release/*.nupkg).Name
55-
56-
$notes = ''
57-
$firstPackageVersion = ''
58-
59-
foreach ($package in $packages)
60-
{
61-
$match = [regex]::Match($package, '(.*)\.(\d+\.\d+\.\d+.*?)\.nupkg')
62-
$packageName = $match.Groups[1].Value
63-
$packageVersion = $match.Groups[2].Value
64-
65-
if ($firstPackageVersion -eq '')
66-
{
67-
$firstPackageVersion = $packageVersion
68-
}
69-
70-
$notes +=
71-
@"
72-
* NuGet: [$packageName v$packageVersion](https://www.nuget.org/packages/$packageName/$packageVersion)
73-
74-
See [CHANGELOG](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/src/$packageName/CHANGELOG.md) for details.
75-
76-
"@
77-
}
78-
79-
$releaseName = '${{ inputs.release-name || inputs.project-name }}'
57+
Import-Module .\build\scripts\post-release.psm1
8058
81-
if ($firstPackageVersion -match '-alpha' -or $firstPackageVersion -match '-beta' -or $firstPackageVersion -match '-rc')
82-
{
83-
gh release create ${{ github.ref_name }} `
84-
--title "$releaseName v$firstPackageVersion" `
85-
--verify-tag `
86-
--notes "$notes" `
87-
--prerelease
88-
}
89-
else
90-
{
91-
gh release create ${{ github.ref_name }} `
92-
--title "$releaseName v$firstPackageVersion" `
93-
--verify-tag `
94-
--notes "$notes" `
95-
--latest
96-
}
59+
CreateRelease `
60+
-tag '${{ github.ref_name }}'
9761
env:
98-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
GH_TOKEN: ${{ github.token }}

build/Projects/OpenTelemetry.Instrumentation.AspNet.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<PackProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.csproj" />
1515
<PackProjects Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.AspNet\OpenTelemetry.Instrumentation.AspNet.csproj" />
1616

17-
<TestProjects Include="$(RepoRoot)\test\OpenTelemetry.Instrumentation.AspNet*.Tests\*.Tests.csproj" />
17+
<TestProjects Include="$(RepoRoot)\test\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests\OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests.csproj" />
18+
<TestProjects Include="$(RepoRoot)\test\OpenTelemetry.Instrumentation.AspNet.Tests\OpenTelemetry.Instrumentation.AspNet.Tests.csproj" />
1819
</ItemGroup>
1920

2021
<Target Name="Build">

build/scripts/post-release.psm1

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 CreateRelease {
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+
}
84+
else
85+
{
86+
gh release create $tag `
87+
--title $tag `
88+
--verify-tag `
89+
--notes $notes `
90+
--latest
91+
}
92+
}
93+
94+
Export-ModuleMember -Function CreateRelease
95+

opentelemetry-dotnet-contrib.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{45D2
387387
ProjectSection(SolutionItems) = preProject
388388
build\scripts\add-labels.ps1 = build\scripts\add-labels.ps1
389389
build\scripts\finalize-publicapi.ps1 = build\scripts\finalize-publicapi.ps1
390+
build\scripts\post-release.psm1 = build\scripts\post-release.psm1
390391
build\scripts\sanitycheck.py = build\scripts\sanitycheck.py
391392
build\scripts\test-aot-compatibility.ps1 = build\scripts\test-aot-compatibility.ps1
392393
build\scripts\update-changelogs.ps1 = build\scripts\update-changelogs.ps1

0 commit comments

Comments
 (0)