forked from dk-klein/PowerPlatformConnectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiProperties_validator.yml
49 lines (40 loc) · 1.82 KB
/
apiProperties_validator.yml
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
pool:
vmImage: "ubuntu-latest"
steps:
- pwsh: |
$errorsTotal = 0
$warningsTotal = 0
# Get the list of files for the given PR
$files = git diff HEAD~1 --name-only
$apiPropertiesFiles = $files | where {$_ -match '.+?apiProperties.json$'}
$Headers = @{
Authorization = $env:token
}
foreach ($file in $apiPropertiesFiles) {
$newFileContent = Get-Content $file -Raw
# Validate apiProperties json
$apiPropertiesValidatorUri = "$($env:apiPropertiesValidator)?api-version=2021-05-01&suppressWarnings=true"
$results = Invoke-RestMethod -Uri $apiPropertiesValidatorUri -Headers $Headers -Method Post -ContentType "application/json; charset=utf-8" -Body [$newFileContent]
$errors = $results | Where-Object { $_.level -EQ "Critical" -OR $_.Level -EQ "Error" }
$warnings = $results | Where-Object { $_.level -EQ "Warning" }
if ($errors) {
$errorsTotal += $errors.Count
$errors | foreach { Write-Host "##vso[task.logissue type=error;]$_" }
} # If Api Properties Error
if ($warnings -AND -NOT $suppressWarnings) {
$warningsTotal += $warnings.Count
$warnings | foreach { Write-Host "##vso[task.logissue type=warning;sourcepath=$file;]$_" }
} # If Api Properties Warnings
} # For each file
if ($errorsTotal -gt 0) {
Write-Host "##vso[task.complete result=Failed;]Errors encountered."
}
elseif ($warningsTotal -gt 0) {
Write-Host "##vso[task.complete result=SucceededWithIssues;]Warnings encountered."
}
else {
Write-Host "##vso[task.complete result=Succeeded;]No error or warnings encountered."
}
env:
apiPropertiesValidator: "$(apiPropertiesValidatorUrl)"
token: $(token)