-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Swagger-Prettier-Check.ps1
53 lines (47 loc) · 1.55 KB
/
Swagger-Prettier-Check.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
[CmdletBinding()]
param (
[switch]$CheckAll = $false
)
Set-StrictMode -Version 3
. $PSScriptRoot/ChangedFiles-Functions.ps1
. $PSScriptRoot/Logging-Functions.ps1
$repoPath = Resolve-Path "$PSScriptRoot/../.."
$pathsWithErrors = @()
if ($CheckAll) {
LogInfo "npm exec --no -- prettier --check $repoPath/specification/**/*.json --log-level warn"
npm exec --no -- prettier --check $repoPath/specification/**/*.json --log-level warn
if ($LASTEXITCODE) {
$pathsWithErrors += "$repoPath/specification/**/*.json"
}
}
else
{
$filesToCheck = @(Get-ChangedSwaggerFiles)
if (!$filesToCheck) {
LogInfo "No specification files found to check."
}
else {
foreach ($file in $filesToCheck) {
LogInfo "npm exec --no -- prettier --check $repoPath/$file --log-level warn"
npm exec --no -- prettier --check $repoPath/$file --log-level warn
if ($LASTEXITCODE) {
$pathsWithErrors += $file
}
}
}
}
if ($pathsWithErrors.Count -gt 0)
{
# DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first and then as many of the individual ones as can be found afterwards
LogError "Code style issues found in the above file(s), please run prettier to update. For more detailed docs see https://aka.ms/azsdk/specs/prettier"
LogJobFailure
foreach ($path in $pathsWithErrors)
{
$errorString = "Code style issues found, please run prettier."
$errorString += "`n > npm install"
$errorString += "`n > npx prettier --write $path"
LogErrorForFile $path $errorString
}
exit 1
}
exit 0