|
| 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 | +} |
0 commit comments