-
Notifications
You must be signed in to change notification settings - Fork 493
Expand file tree
/
Copy pathAnalyze-Code.ps1
More file actions
103 lines (86 loc) · 3.3 KB
/
Analyze-Code.ps1
File metadata and controls
103 lines (86 loc) · 3.3 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/env pwsh
#Requires -Version 7
. "$PSScriptRoot/../common/scripts/common.ps1"
Push-Location $RepoRoot
try {
$hasErrors = $false
Write-Host "Checking if solution files are up to date."
try {
& "$PSScriptRoot/Update-Solution.ps1" -All -Verify
} catch {
Write-Host "❌ Solution update failed: $_"
$hasErrors = $true
}
if ($LASTEXITCODE -ne 0) {
$hasErrors = $true
}
if (-not $hasErrors) {
Write-Host "✅ Solution files are up to date."
}
Write-Host "Running dotnet format to check for formatting issues..."
$solutionFile = "$RepoRoot/Microsoft.Mcp.slnx"
# Excluding diagnostics IL2026 and IL3050 due to known issues with source generator
# Can be removed when https://github.com/dotnet/sdk/issues/45054 is resolved
dotnet format $solutionFile --verify-no-changes --exclude-diagnostics IL2026 IL3050
# Run dotnet format
if ($LASTEXITCODE) {
Write-Host "❌ dotnet format detected formatting issues."
Write-Host "Please run 'dotnet format `"$solutionFile`"' to fix the issues and then try committing again."
$hasErrors = $true
} else {
Write-Host "✅ dotnet format did not detect any formatting issues."
}
# Run cspell spell check
if (!$env:TF_BUILD) {
Write-Host "Running cspell spell check..."
& "$RepoRoot/eng/common/spelling/Invoke-Cspell.ps1" *>&1
| Tee-Object -Variable cspellOutput
| Where-Object { $_ -like '*Unknown word*' }
if ($LASTEXITCODE) {
Write-Host "❌ Spell check detected issues. Please fix the above errors before committing."
$hasErrors = $true
} else {
Write-Host "✅ Spell check did not detect any issues."
}
}
# Run tool description evaluation
& "$PSScriptRoot/Test-ToolSelection.ps1"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Tool description evaluation failed"
} else {
Write-Host "✅ Tool description evaluation did not detect any issues."
}
# Run tool name length validation
$toolNameResult = & "$PSScriptRoot/Test-ToolNameLength.ps1"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Tool name length validation failed"
Write-Host "Maximum Length Allowed: $($toolNameResult.MaxAllowed). $($toolNameResult.ViolationCount) tool(s) exceeding this limit. Review the above output for details."
$hasErrors = $true
} else {
Write-Host "✅ Tool name length validation passed."
Write-Host "All tools are within the $($toolNameResult.MaxAllowed) character limit."
}
# Run tool id validation
$toolIdResult = & "$PSScriptRoot/Test-ToolId.ps1"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Tool id validation failed"
Write-Host "$($toolIdResult.ViolationCount) duplicated tool id(s) found. Review the above output for details."
$hasErrors = $true
} else {
Write-Host "✅ Tool id validation passed."
}
# Run changelog entry validation
& "$PSScriptRoot/Test-ChangelogEntry.ps1"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Changelog entry validation failed"
$hasErrors = $true
} else {
Write-Host "✅ Changelog entry validation passed."
}
if($hasErrors) {
exit 1
}
}
finally {
Pop-Location
}