-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathverifyNoticeMdAgainstNugetPackages.ps1
81 lines (62 loc) · 2.26 KB
/
verifyNoticeMdAgainstNugetPackages.ps1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$path
)
$noticeFile = Get-Content -Raw "NOTICE.md"
Write-Host $noticeFile
Write-Host "Verifying NuGet packages"
$projFiles = Get-ChildItem $path -Filter *.csproj -force -Recurse
$projFiles.Count
Write-Host "Going through all csproj files"
$totalList = $projFiles | ForEach-Object -Parallel {
$csproj = $_
$nugetTemp = @();
#Workaround for preventing exit code from dotnet process from reflecting exit code in PowerShell
$procInfo = New-Object System.Diagnostics.ProcessStartInfo -Property @{
FileName = "dotnet.exe";
Arguments = "list $csproj package";
RedirectStandardOutput = $true;
RedirectStandardError = $true;
}
$proc = [System.Diagnostics.Process]::Start($procInfo);
while (!$proc.StandardOutput.EndOfStream) {
$nugetTemp += $proc.StandardOutput.ReadLine();
}
$proc = $null;
$procInfo = $null;
if($nugetTemp -is [array] -and $nugetTemp.count -gt 3)
{
# Need to debug this script? Uncomment this line.
# Write-Host $csproj "`r`n" $nugetTemp "`r`n"
$temp = New-Object System.Collections.ArrayList
$temp.AddRange($nugetTemp)
$temp.RemoveRange(0, 3)
foreach($p in $temp)
{
# ignore "Auto-referenced" string in the output
if ($p -match "Auto-referenced") {
continue
}
# breaking item down to usable array and getting 1 and 2, see below of a sample output
# > PACKAGE VERSION VERSION
# if a package is Auto-referenced, "(A)" will appear in position 1 instead of a version number.
$p = -split $p
$p = $p[1, 2]
$tempString = $p[0] + " " + $p[1]
if(![string]::IsNullOrWhiteSpace($tempString))
{
echo "- $tempString";
}
}
$csproj = $null;
}
} -ThrottleLimit 4 | Sort-Object
$returnList = [System.Collections.Generic.HashSet[string]]($totalList) -join "`r`n"
Write-Host $returnList
if (!$noticeFile.Trim().EndsWith($returnList.Trim()))
{
Write-Host -ForegroundColor Red "Notice.md does not match NuGet list."
exit 1
}
exit 0