-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathupdate-baselines.ps1
More file actions
56 lines (45 loc) · 1.72 KB
/
Copy pathupdate-baselines.ps1
File metadata and controls
56 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env pwsh
param()
$ErrorActionPreference = "Stop"
$encoding = New-Object System.Text.UTF8Encoding($true)
$releasedName = "PublicAPI.Shipped.txt"
$unshippedName = "PublicAPI.Unshipped.txt"
$repo = Join-Path $PSScriptRoot ".."
$src = Join-Path $repo "src"
$files = Get-ChildItem -Path $src -Filter $unshippedName -Recurse
# See https://github.com/dotnet/roslyn-analyzers/blob/b07c100bfc66013a8444172d00cfa04c9ceb5a97/src/PublicApiAnalyzers/Core/CodeFixes/DeclarePublicApiFix.cs#L373-L390
$comparer = {
param(
[string]$x,
[string]$y
)
$comparison = [System.StringComparer]::OrdinalIgnoreCase.Compare($x, $y)
if ($comparison -eq 0) {
$comparison = [System.StringComparer]::Ordinal.Compare($x, $y)
}
return $comparison;
}
foreach ($file in $files) {
$directory = [System.IO.Path]::GetDirectoryName($file)
$changesPath = Join-Path $directory $unshippedName
$baselinePath = Join-Path $directory $releasedName
$baseline = Get-Content $baselinePath
$baseline = [System.Collections.Generic.List[string]]$baseline
$additions = Get-Content $changesPath
$additions = [System.Collections.Generic.List[string]]$additions
$edited = $false
# Skip the "#nullable enable" header
$index = (($additions.Count -gt 0) -And ($additions[0] -eq "#nullable enable")) ? 1 : 0
while ($additions.Count -gt $index) {
$addition = $additions[$index]
$additions.RemoveAt($index)
$baseline.Add($addition)
$edited = $true
}
if ($edited) {
$additions.Sort($comparer)
$baseline.Sort($comparer)
$additions | Set-Content $changesPath -Encoding $encoding
$baseline | Set-Content $baselinePath -Encoding $encoding
}
}