forked from microsoftgraph/microsoft-graph-docs-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-changelog-json.ps1
28 lines (23 loc) · 1 KB
/
validate-changelog-json.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
$schemaFileName = "Changelog.Schema.json"
$schemaPath = "changelog/" + $schemaFileName
$schema = Get-Content $schemaPath | Out-String
$err = "";
Get-ChildItem -Filter "changelog/*.json" | Where-Object { $schemaFileName -notcontains $_.Name} | ForEach-Object {
# first test only json parsing to not mixup error
$json = Get-Content $_ | Out-String -ErrorAction:SilentlyContinue
if(($json | Test-Json -ErrorAction:SilentlyContinue) -eq $true){
# if json parsing is fine, let's check schema
if(($json | Test-Json -Schema $schema -ErrorAction:SilentlyContinue) -eq $true){
Write-Host ("Passed Validation : " + $_.Name) -ForegroundColor Green
} else {
$err += "File found with invalid changelog: " + $_.Name + "`nError Details: " + $Error[0].ErrorDetails.Message + "`r`n";
}
} else {
$err += $_.Name + "`t`t" + $Error[0].Exception.Message + "`r`n";
}
}
# only drop one error preventing
if($err -ne ""){
Write-Error $err
exit -1
}