Skip to content

Commit 89689d8

Browse files
authored
Public API diffs (SteeltoeOSS#1564)
* Add PublicAPI scripts * TEST: .\public-api-mark-shipped.ps1 * TEST: Steeltoe changes after release * TEST: .\public-api-mark-shipped.ps1 * Revert test commits
1 parent d2fe071 commit 89689d8

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

.github/workflows/package.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ jobs:
102102
echo "Package version suffix is empty. This should never happen."
103103
exit 1
104104
105+
- name: Verify public API files (for release)
106+
if: ${{ github.event_name == 'release' }}
107+
shell: pwsh
108+
run: |
109+
# To recover from this:
110+
# - Delete the GitHub release
111+
# - Run: git push --delete origin the-invalid-tag-name
112+
# - Run public-api-mark-shipped.ps1, commit and push
113+
# - Recreate the GitHub release
114+
./public-api-verify-shipped.ps1
115+
105116
- name: Build solution
106117
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
107118

public-api-mark-shipped.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This script merges the content of PublicAPI.Unshipped.txt files into PublicAPI.Shipped.txt.
2+
# Run this before creating a new release and commit the changes.
3+
# Based on https://github.com/dotnet/roslyn/blob/main/scripts/PublicApi/mark-shipped.ps1
4+
#
5+
# TIP: To obtain the public API diff between two releases, run:
6+
# git diff --unified=0 --text <previous-release-tag-name> head -- **/PublicAPI.Shipped.txt
7+
8+
[CmdletBinding(PositionalBinding=$false)]
9+
param ()
10+
11+
Set-StrictMode -version 2.0
12+
$ErrorActionPreference = 'Stop'
13+
14+
function MarkShipped([string] $dir) {
15+
$shippedFilePath = Join-Path $dir 'PublicAPI.Shipped.txt'
16+
$shipped = Get-Content $shippedFilePath
17+
if ($null -eq $shipped) {
18+
$shipped = @('#nullable enable')
19+
}
20+
21+
$unshippedFilePath = Join-Path $dir 'PublicAPI.Unshipped.txt'
22+
$unshipped = Get-Content $unshippedFilePath
23+
$removed = @()
24+
$removedPrefix = '*REMOVED*';
25+
Write-Host "Processing $dir"
26+
27+
foreach ($item in $unshipped) {
28+
if ($item.Length -gt 0) {
29+
if ($item.StartsWith($removedPrefix)) {
30+
$item = $item.Substring($removedPrefix.Length)
31+
$removed += $item
32+
}
33+
elseif (-not $item.StartsWith('#')) {
34+
$shipped += $item
35+
}
36+
}
37+
}
38+
39+
$shipped | Sort-Object -Unique | Where-Object { -not $removed.Contains($_) } | Out-File $shippedFilePath -Encoding Ascii
40+
'#nullable enable' | Out-File $unshippedFilePath -Encoding Ascii
41+
}
42+
43+
foreach ($file in Get-ChildItem -re -in 'PublicApi.Shipped.txt') {
44+
$dir = Split-Path -parent $file
45+
MarkShipped $dir
46+
}

public-api-verify-shipped.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This script verifies that all PublicAPI.Unshipped.txt files are empty.
2+
# Run this as a sanity check before creating a new release.
3+
4+
[CmdletBinding(PositionalBinding=$false)]
5+
param ()
6+
7+
Set-StrictMode -version 2.0
8+
$ErrorActionPreference = 'Stop'
9+
10+
function HasUnshipped([string] $dir) {
11+
$filePath = Join-Path $dir 'PublicAPI.Unshipped.txt'
12+
$content = Get-Content $filePath | Where-Object { $_ -NOTLIKE "#*" }
13+
return [bool]$content
14+
}
15+
16+
$dirsUnshipped = @()
17+
18+
foreach ($file in Get-ChildItem -re -in 'PublicApi.Unshipped.txt') {
19+
$dir = Split-Path -parent $file
20+
$hasUnshipped = HasUnshipped $dir
21+
22+
if ($hasUnshipped) {
23+
$dirsUnshipped += $dir
24+
}
25+
}
26+
27+
if ($dirsUnshipped.Count -gt 0) {
28+
Write-Error "Unshipped APIs found in the following directories:`n$($dirsUnshipped -join "`n")"
29+
return 1
30+
}

0 commit comments

Comments
 (0)