-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromote-analyzer-release.ps1
More file actions
32 lines (26 loc) · 1.57 KB
/
Copy pathpromote-analyzer-release.ps1
File metadata and controls
32 lines (26 loc) · 1.57 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
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidatePattern('^\d+\.\d+\.\d+$')]
[string] $Version,
[string] $ShippedPath = (Join-Path $PSScriptRoot 'NTComponents.Analyzers/AnalyzerReleases.Shipped.md'),
[string] $UnshippedPath = (Join-Path $PSScriptRoot 'NTComponents.Analyzers/AnalyzerReleases.Unshipped.md')
)
$lineEnding = "`r`n"
$encoding = [System.Text.UTF8Encoding]::new($false)
$shippedText = [System.IO.File]::ReadAllText($ShippedPath)
$unshippedText = [System.IO.File]::ReadAllText($UnshippedPath)
$unshippedContent = (($unshippedText -split '\r?\n' | Where-Object { -not $_.StartsWith(';') }) -join $lineEnding).Trim()
if ($unshippedContent -notmatch '(?m)^NTC\d{4}\s*\|') {
Write-Host 'No unshipped analyzer rules were found.'
return
}
if ($shippedText -match "(?m)^## Release $([regex]::Escape($Version))\r?$") {
throw "Analyzer release $Version is already present in $ShippedPath."
}
$normalizedShippedText = ($shippedText -replace '\r?\n', $lineEnding).TrimEnd()
$newShippedText = $normalizedShippedText + $lineEnding + $lineEnding + "## Release $Version" + $lineEnding + $lineEnding + $unshippedContent + $lineEnding
$newUnshippedText = '; Unshipped analyzer release' + $lineEnding + '; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md' + $lineEnding + $lineEnding
[System.IO.File]::WriteAllText($ShippedPath, $newShippedText, $encoding)
[System.IO.File]::WriteAllText($UnshippedPath, $newUnshippedText, $encoding)
Write-Host "Promoted analyzer rules to release $Version."