Skip to content

Commit 4252bef

Browse files
Improve release automation (#3317)
- Move script to bump the version from inline PowerShell to its own script. - Copy script from Polly to update Public API baselines. - Fix incorrectly sorted baseline document. - Remove obsolete Public API baselines for .NET 6.
1 parent cb39741 commit 4252bef

11 files changed

Lines changed: 127 additions & 47 deletions

File tree

.github/bump-version.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#! /usr/bin/env pwsh
2+
param(
3+
[Parameter(Mandatory = $false)][string] $NextVersion
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
if ($NextVersion.StartsWith("v")) {
9+
$NextVersion = $NextVersion.Substring(1)
10+
}
11+
12+
$repo = Join-Path $PSScriptRoot ".."
13+
$properties = Join-Path $repo "Directory.Build.props"
14+
15+
$xml = [xml](Get-Content $properties)
16+
$versionPrefix = $xml.SelectSingleNode('Project/PropertyGroup/VersionPrefix')
17+
$publishedVersion = $versionPrefix.InnerText
18+
19+
if (-Not [string]::IsNullOrEmpty($NextVersion)) {
20+
$version = [System.Version]::new($NextVersion)
21+
} else {
22+
$version = [System.Version]::new($publishedVersion)
23+
$version = [System.Version]::new($version.Major, $version.Minor, $version.Build + 1)
24+
}
25+
26+
$updatedVersion = $version.ToString()
27+
$versionPrefix.InnerText = $updatedVersion
28+
29+
$packageValidationBaselineVersion = $xml.SelectSingleNode('Project/PropertyGroup/PackageValidationBaselineVersion')
30+
$packageValidationBaselineVersion.InnerText = $publishedVersion
31+
32+
Write-Output "Bumping version from $publishedVersion to $version"
33+
34+
$settings = New-Object System.Xml.XmlWriterSettings
35+
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
36+
$settings.Indent = $true
37+
$settings.OmitXmlDeclaration = $true
38+
39+
try {
40+
$writer = [System.Xml.XmlWriter]::Create($properties, $settings)
41+
$xml.Save($writer)
42+
} finally {
43+
if ($writer) {
44+
$writer.Flush()
45+
$writer.Dispose()
46+
"" >> $properties
47+
}
48+
$writer = $null
49+
}
50+
51+
$githubOutput = $env:GITHUB_OUTPUT
52+
53+
if (($null -ne $githubOutput) -and (Test-Path $githubOutput)) {
54+
"version=${updatedVersion}" >> $githubOutput
55+
}

.github/update-baselines.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#! /usr/bin/env pwsh
2+
param()
3+
4+
$ErrorActionPreference = "Stop"
5+
6+
$encoding = New-Object System.Text.UTF8Encoding($true)
7+
$releasedName = "PublicAPI.Shipped.txt"
8+
$unshippedName = "PublicAPI.Unshipped.txt"
9+
10+
$repo = Join-Path $PSScriptRoot ".."
11+
$src = Join-Path $repo "src"
12+
$files = Get-ChildItem -Path $src -Filter $unshippedName -Recurse
13+
14+
# See https://github.com/dotnet/roslyn-analyzers/blob/b07c100bfc66013a8444172d00cfa04c9ceb5a97/src/PublicApiAnalyzers/Core/CodeFixes/DeclarePublicApiFix.cs#L373-L390
15+
$comparer = {
16+
param(
17+
[string]$x,
18+
[string]$y
19+
)
20+
$comparison = [System.StringComparer]::OrdinalIgnoreCase.Compare($x, $y)
21+
if ($comparison -eq 0) {
22+
$comparison = [System.StringComparer]::Ordinal.Compare($x, $y)
23+
}
24+
return $comparison;
25+
}
26+
27+
foreach ($file in $files) {
28+
$directory = [System.IO.Path]::GetDirectoryName($file)
29+
$changesPath = Join-Path $directory $unshippedName
30+
$baselinePath = Join-Path $directory $releasedName
31+
32+
$baseline = Get-Content $baselinePath
33+
$baseline = [System.Collections.Generic.List[string]]$baseline
34+
35+
$additions = Get-Content $changesPath
36+
$additions = [System.Collections.Generic.List[string]]$additions
37+
38+
$edited = $false
39+
40+
# Skip any "#nullable enable" header
41+
$nullableHeader = "#nullable enable"
42+
$index = (($additions.Count -gt 0) -And ($additions[0] -eq $nullableHeader)) ? 1 : 0
43+
while ($additions.Count -gt $index) {
44+
$addition = $additions[$index]
45+
$additions.RemoveAt($index)
46+
$baseline.Add($addition)
47+
$edited = $true
48+
}
49+
50+
if ($edited) {
51+
$additions.Sort($comparer)
52+
$baseline.Sort($comparer)
53+
54+
if (($additions.Count -eq 1) -and ($additions[0] -eq $nullableHeader)) {
55+
$additions | Set-Content $changesPath -Encoding $encoding
56+
} else {
57+
$null | Set-Content $changesPath -Encoding $encoding
58+
}
59+
60+
$baseline | Set-Content $baselinePath -Encoding $encoding
61+
}
62+
}

.github/workflows/bump-version.yml

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,11 @@ jobs:
3535
shell: pwsh
3636
env:
3737
NEXT_VERSION: ${{ inputs.version }}
38-
run: |
39-
$properties = Join-Path "." "Directory.Build.props"
40-
41-
$xml = [xml](Get-Content $properties)
42-
$versionPrefix = $xml.SelectSingleNode('Project/PropertyGroup/VersionPrefix')
43-
$publishedVersion = $versionPrefix.InnerText;
44-
45-
if (-Not [string]::IsNullOrEmpty(${env:NEXT_VERSION})) {
46-
$version = [System.Version]::new(${env:NEXT_VERSION})
47-
} else {
48-
$version = [System.Version]::new($publishedVersion)
49-
$version = [System.Version]::new($version.Major, $version.Minor, $version.Build + 1)
50-
}
51-
52-
$updatedVersion = $version.ToString()
53-
$versionPrefix.InnerText = $updatedVersion
54-
55-
$packageValidationBaselineVersion = $xml.SelectSingleNode('Project/PropertyGroup/PackageValidationBaselineVersion')
56-
$packageValidationBaselineVersion.InnerText = $publishedVersion
38+
run: ./.github/bump-version.ps1 ${env:NEXT_VERSION}
5739

58-
$settings = New-Object System.Xml.XmlWriterSettings
59-
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
60-
$settings.Indent = $true
61-
$settings.OmitXmlDeclaration = $true
62-
63-
$writer = [System.Xml.XmlWriter]::Create($properties, $settings)
64-
65-
$xml.Save($writer)
66-
67-
$writer.Flush()
68-
$writer.Close()
69-
$writer = $null
70-
71-
"" >> $properties
72-
73-
"version=${updatedVersion}" >> $env:GITHUB_OUTPUT
40+
- name: Update public API baselines
41+
shell: pwsh
42+
run: ./.github/update-baselines.ps1
7443

7544
- name: Push changes to GitHub
7645
id: push-changes

Swashbuckle.AspNetCore.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,19 @@ EndProject
9595
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{3BA087DA-788C-43D6-9D8B-1EF017014A4A}"
9696
ProjectSection(SolutionItems) = preProject
9797
.github\actionlint-matcher.json = .github\actionlint-matcher.json
98+
.github\bump-version.ps1 = .github\bump-version.ps1
9899
.github\dependabot.yml = .github\dependabot.yml
100+
.github\update-baselines.ps1 = .github\update-baselines.ps1
99101
EndProjectSection
100102
EndProject
101103
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{A0EC16BE-C520-4FCF-BB54-2D79CD255F00}"
102104
ProjectSection(SolutionItems) = preProject
103105
.github\workflows\actions-lint.yml = .github\workflows\actions-lint.yml
104106
.github\workflows\build.yml = .github\workflows\build.yml
107+
.github\workflows\bump-version.yml = .github\workflows\bump-version.yml
105108
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
106109
.github\workflows\ossf-scorecard.yml = .github\workflows\ossf-scorecard.yml
110+
.github\workflows\release.yml = .github\workflows\release.yml
107111
.github\workflows\stale.yml = .github\workflows\stale.yml
108112
.github\workflows\update-dotnet-sdk.yml = .github\workflows\update-dotnet-sdk.yml
109113
EndProjectSection

src/Swashbuckle.AspNetCore.Annotations/PublicAPI/net6.0/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Swashbuckle.AspNetCore.Annotations/PublicAPI/net6.0/PublicAPI.Unshipped.txt

Whitespace-only changes.

src/Swashbuckle.AspNetCore.Swagger/PublicAPI/PublicAPI.Shipped.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ static Microsoft.Extensions.DependencyInjection.SwaggerOptionsExtensions.SetCust
77
static Microsoft.Extensions.DependencyInjection.SwaggerServiceCollectionExtensions.ConfigureSwagger(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Swashbuckle.AspNetCore.Swagger.SwaggerOptions> setupAction) -> void
88
Swashbuckle.AspNetCore.Swagger.IAsyncSwaggerProvider
99
Swashbuckle.AspNetCore.Swagger.IAsyncSwaggerProvider.GetSwaggerAsync(string documentName, string host = null, string basePath = null) -> System.Threading.Tasks.Task<Microsoft.OpenApi.Models.OpenApiDocument>
10+
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentMetadataProvider
11+
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentMetadataProvider.GetDocumentNames() -> System.Collections.Generic.IList<string>
1012
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentSerializer
1113
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentSerializer.SerializeDocument(Microsoft.OpenApi.Models.OpenApiDocument document, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) -> void
1214
Swashbuckle.AspNetCore.Swagger.ISwaggerProvider
1315
Swashbuckle.AspNetCore.Swagger.ISwaggerProvider.GetSwagger(string documentName, string host = null, string basePath = null) -> Microsoft.OpenApi.Models.OpenApiDocument
14-
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentMetadataProvider
15-
Swashbuckle.AspNetCore.Swagger.ISwaggerDocumentMetadataProvider.GetDocumentNames() -> System.Collections.Generic.IList<string>
1616
Swashbuckle.AspNetCore.Swagger.SwaggerEndpointOptions
1717
Swashbuckle.AspNetCore.Swagger.SwaggerEndpointOptions.PreSerializeFilters.get -> System.Collections.Generic.List<System.Action<Microsoft.OpenApi.Models.OpenApiDocument, Microsoft.AspNetCore.Http.HttpRequest>>
1818
Swashbuckle.AspNetCore.Swagger.SwaggerEndpointOptions.SwaggerEndpointOptions() -> void

src/Swashbuckle.AspNetCore.Swagger/PublicAPI/net6.0/PublicAPI.Shipped.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Swashbuckle.AspNetCore.Swagger/PublicAPI/net6.0/PublicAPI.Unshipped.txt

Whitespace-only changes.

src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/net6.0/PublicAPI.Shipped.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)