Skip to content

Commit

Permalink
Script to mark API as shipped (#4837)
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie authored Apr 24, 2021
1 parent 5d05007 commit 5ba42a1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions eng/ApiCompatibility/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Mark Shipped Tool
========

This tool should be run after every supported release that has API changes. It will
merge the collection of PublicApi.Shipped.txt files with the PublicApi.Unshipped.txt
versions. This will take into account `*REMOVED*` elements when updating the files.

Usage:

``` cmd
mark-shipped.cmd
```
2 changes: 2 additions & 0 deletions eng/ApiCompatibility/mark-shipped.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\mark-shipped.ps1"
51 changes: 51 additions & 0 deletions eng/ApiCompatibility/mark-shipped.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[CmdletBinding(PositionalBinding=$false)]
param ()

Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"

function MarkShipped([string]$dir) {
$shippedFilePath = Join-Path $dir "PublicAPI.Shipped.txt"
$shipped = Get-Content $shippedFilePath
if ($null -eq $shipped) {
$shipped = @()
}

$unshippedFilePath = Join-Path $dir "PublicAPI.Unshipped.txt"
$unshipped = Get-Content $unshippedFilePath
$removed = @()
$removedPrefix = "*REMOVED*";
Write-Host "Processing $dir"

foreach ($item in $unshipped) {
if ($item.Length -gt 0) {
if ($item.StartsWith($removedPrefix)) {
$item = $item.Substring($removedPrefix.Length)
$removed += $item
}
else {
$shipped += $item
}
}
}

$shipped | Sort-Object | ?{ -not $removed.Contains($_) } | Out-File $shippedFilePath -Encoding Ascii
$null | Out-File $unshippedFilePath -Encoding Ascii
}

try {
Push-Location $PSScriptRoot\..\..

foreach ($file in Get-ChildItem -re -in "PublicApi.Shipped.txt") {
$dir = Split-Path -parent $file
MarkShipped $dir
}
}
catch {
Write-Host $_
Write-Host $_.Exception
exit 1
}
finally {
Pop-Location
}

0 comments on commit 5ba42a1

Please sign in to comment.