Skip to content

Commit

Permalink
[repo] Improve the scripts used in the release process (#5561)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Apr 23, 2024
1 parent efe97bf commit 994b890
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 98 deletions.
9 changes: 3 additions & 6 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{7CB2F02E
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\generate-combined-changelog.ps1 = build\generate-combined-changelog.ps1
build\GlobalAttrExclusions.txt = build\GlobalAttrExclusions.txt
build\InstrumentationLibraries.proj = build\InstrumentationLibraries.proj
build\opentelemetry-icon-color.png = build\opentelemetry-icon-color.png
build\OpenTelemetry.prod.loose.ruleset = build\OpenTelemetry.prod.loose.ruleset
build\OpenTelemetry.prod.ruleset = build\OpenTelemetry.prod.ruleset
build\OpenTelemetry.test.ruleset = build\OpenTelemetry.test.ruleset
build\process-codecoverage.ps1 = build\process-codecoverage.ps1
build\RELEASING.md = build\RELEASING.md
build\stylecop.json = build\stylecop.json
build\test-aot-compatibility.ps1 = build\test-aot-compatibility.ps1
build\test-threadSafety.ps1 = build\test-threadSafety.ps1
build\xunit.runner.json = build\xunit.runner.json
build\UnstableCoreLibraries.proj = build\UnstableCoreLibraries.proj
build\update-changelogs.ps1 = build\update-changelogs.ps1
build\xunit.runner.json = build\xunit.runner.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.Zipkin", "src\OpenTelemetry.Exporter.Zipkin\OpenTelemetry.Exporter.Zipkin.csproj", "{7EDAE7FA-B44E-42CA-80FA-7DF2FAA2C5DD}"
Expand Down Expand Up @@ -531,10 +532,6 @@ Global
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Release|Any CPU.Build.0 = Release|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Release|Any CPU.Build.0 = Release|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
102 changes: 33 additions & 69 deletions build/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,68 +57,32 @@
`OTelLatestStableVer` property in `Directory.Packages.props` has been
updated to the latest stable core version.

2. Run the following PowerShell from the root of the repo to get combined
changelog (to be used later).
2. Generate combined CHANGELOG

```powershell
$changelogs = Get-ChildItem -Path . -Recurse -Filter changelog.md
foreach ($changelog in $changelogs)
{
Add-Content -Path .\combinedchangelog.md -Value "**$($changelog.Directory.Name)**"
$lines = Get-Content -Path $changelog.FullName
$started = $false
$ended = $false
foreach ($line in $lines)
{
if($line -like "## Unreleased" -and $started -ne $true)
{
$started = $true
}
elseif($line -like "## *" -and $started -eq $true)
{
$ended = $true
break
}
else
{
if ($started -eq $true)
{
Add-Content -Path .\combinedchangelog.md $line
}
}
}
}
```
Run the PowerShell script `.\build\generate-combined-changelog.ps1
-minVerTagPrefix [MinVerTagPrefix]`. Where `[MinVerTagPrefix]` is the tag
prefix (eg `core-`) for the components being released. This generates a
combined changelog file to be used in GitHub release. The file is created in
the repo root but should not be checked in. Move it or copy the contents off
and then delete the file.

This generates combined changelog to be used in GitHub release. Once
contents of combined changelog is saved somewhere, delete the file.
3. Update CHANGELOG files

3. Run the following PowerShell script from the root of the repo. This updates
all the changelog to have release date for the current version being
released. Replace the version with actual version. In the script below,
replace `1.4.0-beta.1` with the tag name chosen for the package in Step 1.
```powershell
$changelogs = Get-ChildItem -Path . -Recurse -Filter changelog.md
foreach ($changelog in $changelogs)
{
(Get-Content -Path $changelog.FullName) -replace "Unreleased", "Unreleased
## 1.4.0-beta.1
Released $(Get-Date -UFormat '%Y-%b-%d')" | Set-Content -Path $changelog.FullName
}
```
Run the PowerShell script `.\build\update-changelogs.ps1 -minVerTagPrefix
[MinVerTagPrefix] -version [Version]`. Where `[MinVerTagPrefix]` is the tag
prefix (eg `core-`) for the components being released and `[Version]` is the
version being released (eg `1.9.0`). This will update `CHANGELOG.md` files
for the projects being released.

4. Normalize PublicApi files (Stable Release Only): Run the PowerShell script
`.\build\finalize-publicapi.ps1`. This will merge the contents of
Unshipped.txt into the Shipped.txt.
4. **Stable releases only**: Normalize PublicApi files

5. The scripts in steps 2-4 run over the entire repo. Remove and undo changes
under projects which are not being released. Submit a PR with the final
changes and get it merged.
Run the PowerShell script `.\build\finalize-publicapi.ps1 -minVerTagPrefix
[MinVerTagPrefix]`. Where `[MinVerTagPrefix]` is the tag prefix (eg `core-`)
for the components being released. This will merge the contents of any
detected `PublicAPI.Unshipped.txt` files in the `.publicApi` folder into the
corresponding `PublicAPI.Shipped.txt` files for the projects being released.

6. Tag Git with version to be released. We use
5. Tag Git with version to be released. We use
[MinVer](https://github.com/adamralph/minver) to do versioning, which
produces version numbers based on git tags.

Expand Down Expand Up @@ -151,7 +115,7 @@
git push origin Instrumentation.AspNetCore-1.6.0
```

7. Go to the [list of
6. Go to the [list of
tags](https://github.com/open-telemetry/opentelemetry-dotnet/tags) and find
the tag(s) which were pushed. Click the three dots next to the tag and
choose `Create release`.
Expand All @@ -164,47 +128,47 @@
MyGet
workflow](https://github.com/open-telemetry/opentelemetry-dotnet/actions/workflows/publish-packages-1.0.yml).

8. Validate using MyGet packages. Basic sanity checks :)
7. Validate using MyGet packages. Basic sanity checks :)

9. From the above build, get the artifacts from the drop, which has all the
8. From the above build, get the artifacts from the drop, which has all the
NuGet packages.

10. Copy all the NuGet files and symbols for the packages being released into a
9. Copy all the NuGet files and symbols for the packages being released into a
local folder.

11. Download latest [nuget.exe](https://www.nuget.org/downloads) into the same
folder from Step 10.
10. Download latest [nuget.exe](https://www.nuget.org/downloads) into the same
folder from Step 9.

12. Create or regenerate an API key from nuget.org (only maintainers have
11. Create or regenerate an API key from nuget.org (only maintainers have
access). When creating API keys make sure it is set to expire in 1 day or
less.

13. Run the following commands from PowerShell from local folder used in Step 10:
12. Run the following commands from PowerShell from local folder used in Step 9:

```powershell
.\nuget.exe setApiKey <actual api key>
get-childitem -Recurse | where {$_.extension -eq ".nupkg"} | foreach ($_) {.\nuget.exe push $_.fullname -Source https://api.nuget.org/v3/index.json}
```
14. Validate that the package(s) are uploaded. Packages are available
13. Validate that the package(s) are uploaded. Packages are available
immediately to maintainers on nuget.org but aren't publicly visible until
scanning completes. This process usually takes a few minutes.
15. If a new stable version of the core packages was released, open a PR to
14. If a new stable version of the core packages was released, open a PR to
update the `OTelLatestStableVer` property in `Directory.Packages.props` to
the just released stable version.
16. If a new stable version of a package with a dedicated `MinVerTagPrefix` was
15. If a new stable version of a package with a dedicated `MinVerTagPrefix` was
released (typically instrumentation packages) open a PR to update
`PackageValidationBaselineVersion` in the project file to reflect the stable
version which was just released.
17. If a new stable version of the core packages was released, open an issue in
16. 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.
18. Once the packages are available on nuget.org post an announcement in the
17. Once the packages are available on nuget.org post an announcement in the
[Slack channel](https://cloud-native.slack.com/archives/C01N3BC2W7Q). Note
any big or interesting new features as part of the announcement.
54 changes: 31 additions & 23 deletions build/finalize-publicapi.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
# After every stable release, all PublicApi text files (Shipped & Unshipped) should be merged.
$path = "src\*\.publicApi\**\";
$directory = Split-Path -Path $PSScriptRoot -Parent;
param(
[Parameter(Mandatory=$true)][string]$minVerTagPrefix
)

$searchPath = Join-Path -Path $directory -ChildPath $path;
Write-Host "Search Directory: $searchPath";
Write-Host "";
# For stable releases "Unshipped" PublicApi text files are merged into "Shipped" versions.

Get-ChildItem -Path $searchPath -Recurse -Filter *.Shipped.txt |
ForEach-Object {
Write-Host $_.FullName;
$projectDirs = Get-ChildItem -Path src/**/*.csproj | Select-String "<MinVerTagPrefix>$minVerTagPrefix</MinVerTagPrefix>" -List | Select Path | Split-Path -Parent

[string]$shipped = $_.FullName;
[string]$unshipped = $shipped -replace ".shipped.txt", ".Unshipped.txt";
$path = "\.publicApi\**\PublicAPI.Shipped.txt";

if (Test-Path $unshipped) {
Write-Host $unshipped;
foreach ($projectDir in $projectDirs) {
$searchPath = Join-Path -Path $projectDir -ChildPath $path;

Get-Content $shipped, $unshipped | # get contents of both text files
Where-Object {$_ -ne ""} | # filter empty lines
Sort-Object | # sort lines
Get-Unique | # filter duplicates
Set-Content $shipped; # write to shipped.txt
Write-Host "Search glob: $searchPath";

Clear-Content $unshipped; # empty unshipped.txt
Get-ChildItem -Path $searchPath -Recurse |
ForEach-Object {
Write-Host "Shipped: $_";

Write-Host "...MERGED and SORTED";
}
[string]$shipped = $_.FullName;
[string]$unshipped = $shipped -replace ".shipped.txt", ".Unshipped.txt";

if (Test-Path $unshipped) {
Write-Host "Unshipped: $unshipped";

Get-Content $shipped, $unshipped | # get contents of both text files
Where-Object {$_ -ne ""} | # filter empty lines
Sort-Object | # sort lines
Get-Unique | # filter duplicates
Set-Content $shipped; # write to shipped.txt

Write-Host "";
}
Clear-Content $unshipped; # empty unshipped.txt

Write-Host "...MERGED and SORTED";
}

Write-Host "";
}
}
42 changes: 42 additions & 0 deletions build/generate-combined-changelog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param(
[Parameter(Mandatory=$true)][string]$minVerTagPrefix
)

$projectDirs = Get-ChildItem -Path src/**/*.csproj | Select-String "<MinVerTagPrefix>$minVerTagPrefix</MinVerTagPrefix>" -List | Select Path | Split-Path -Parent

foreach ($projectDir in $projectDirs) {
$path = Join-Path -Path $projectDir -ChildPath "CHANGELOG.md"

$directory = Split-Path $Path -Parent | Split-Path -Leaf

$lines = Get-Content -Path $path

$headingWritten = $false
$started = $false
$content = ""

foreach ($line in $lines)
{
if ($line -like "## Unreleased" -and $started -ne $true)
{
$started = $true
}
elseif ($line -like "## *" -and $started -eq $true)
{
break
}
else
{
if ($started -eq $true)
{
$content += $line + "`r`n"
}
}
}

if ([string]::IsNullOrWhitespace($content) -eq $false)
{
Add-Content -Path ".\$($minVerTagPrefix)combinedchangelog.md" -Value "**$($directory)**"
Add-Content -Path ".\$($minVerTagPrefix)combinedchangelog.md" -NoNewline -Value $content
}
}
20 changes: 20 additions & 0 deletions build/update-changelogs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
param(
[Parameter(Mandatory=$true)][string]$minVerTagPrefix,
[Parameter(Mandatory=$true)][string]$version
)

$projectDirs = Get-ChildItem -Path src/**/*.csproj | Select-String "<MinVerTagPrefix>$minVerTagPrefix</MinVerTagPrefix>" -List | Select Path | Split-Path -Parent

$content = "Unreleased
## $version
Released $(Get-Date -UFormat '%Y-%b-%d')"

foreach ($projectDir in $projectDirs) {
$path = Join-Path -Path $projectDir -ChildPath "CHANGELOG.md"

Write-Host "Updating $path"

(Get-Content -Path $path) -replace "Unreleased", $content | Set-Content -Path $path
}

0 comments on commit 994b890

Please sign in to comment.