2020-07-24 03:09:22 +03:00
|
|
|
pool:
|
2020-08-01 08:32:59 +03:00
|
|
|
vmImage: "ubuntu-latest"
|
2020-07-24 03:09:22 +03:00
|
|
|
|
|
|
|
steps:
|
2020-08-01 08:32:59 +03:00
|
|
|
- pwsh: |
|
2020-07-24 03:09:22 +03:00
|
|
|
$errorsTotal = 0
|
|
|
|
$warningsTotal = 0
|
|
|
|
|
|
|
|
# Get the list of files for the given PR
|
|
|
|
$currentLocation = Get-Location
|
|
|
|
$files = git diff HEAD~1 --name-only
|
2020-08-01 08:32:59 +03:00
|
|
|
$swaggerFiles = $files | where {$_ -match '.+?apidefinition.swagger.json$'}
|
2020-07-31 23:50:23 +03:00
|
|
|
|
2023-08-09 08:37:59 +03:00
|
|
|
$token2 = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$(userpass)"))
|
2023-08-09 10:56:00 +03:00
|
|
|
|
2023-08-09 08:37:59 +03:00
|
|
|
$Headers = @{ Authorization = $token2 }
|
2020-07-31 23:50:23 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
foreach ($file in $swaggerFiles) {
|
|
|
|
$currentFilePath = Join-Path $currentLocation ($file.Replace('/', '\'))
|
|
|
|
$previousCommitHash = git log --max-count=1 --skip=1 --first-parent --pretty=format:%H $currentFilePath
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
$newFileContent = Get-Content $file -Raw
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
# Validate swagger
|
2021-10-11 22:02:10 +03:00
|
|
|
$isCertValidation = $file -Like "*certified-connectors/*" -Or $file -Like "*independent-publisher-connectors/*"
|
2020-08-11 01:55:21 +03:00
|
|
|
$swaggerValidatorUri = "$($env:swaggerValidator)?IsCertificationValidation=$isCertValidation"
|
2023-08-09 10:56:00 +03:00
|
|
|
Write-Host "Uri = $swaggerValidatorUri"
|
2020-12-19 04:32:39 +03:00
|
|
|
$results = Invoke-RestMethod -Uri $swaggerValidatorUri -Headers $Headers -Method Post -ContentType "application/json; charset=utf-8" -Body $newFileContent
|
2020-08-01 08:32:59 +03:00
|
|
|
|
|
|
|
$errors = $results.Errors
|
|
|
|
$warnings = $results.Warnings
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
if ($errors) {
|
|
|
|
$errorsTotal += $errors.Count
|
2020-08-06 02:00:06 +03:00
|
|
|
$errors | foreach { Write-Host "##vso[task.logissue type=error;]$_" }
|
2020-08-01 08:32:59 +03:00
|
|
|
} # If Swagger Error
|
|
|
|
|
|
|
|
if ($warnings) {
|
|
|
|
$warningsTotal += $warnings.Count
|
2020-08-06 02:00:06 +03:00
|
|
|
$warnings | foreach { Write-Host "##vso[task.logissue type=warning;sourcepath=$file;]$_" }
|
2020-08-01 08:32:59 +03:00
|
|
|
} # If Swagger Warnings
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
# Check for breaking changes when previous commit exits
|
|
|
|
# And there is NO swagger validation error
|
|
|
|
if ($previousCommitHash -AND -NOT $errors) {
|
|
|
|
$oldSwagger = git show "$($previousCommitHash):$($file)" | Out-String | ConvertFrom-Json
|
|
|
|
$newSwagger = $newFileContent | ConvertFrom-Json
|
2020-07-31 23:50:23 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
$changeValidation = @{
|
|
|
|
OldSwagger = $oldSwagger
|
|
|
|
NewSwagger = $newSwagger
|
|
|
|
}
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-07 01:39:46 +03:00
|
|
|
$changeValidationJson = ConvertTo-Json $changeValidation -Depth 100 -Compress
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
# Validate changes
|
2020-12-19 04:32:39 +03:00
|
|
|
$results = Invoke-RestMethod -Uri $env:changeValidator -Headers $Headers -Method Post -ContentType "application/json; charset=utf-8" -Body $changeValidationJson
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
$errors = $results.Errors
|
|
|
|
$warnings = $results.Warnings
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
if ($errors) {
|
|
|
|
$errorsTotal += $errors.Count
|
|
|
|
$errors | foreach { Write-Host "##vso[task.LogIssue type=error;]$_" }
|
|
|
|
} # If there are any errors
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
if ($warnings) {
|
|
|
|
$warningsTotal += $warnings.Count
|
2020-08-06 02:00:06 +03:00
|
|
|
$warnings | foreach { Write-Host "##vso[task.LogIssue type=warning;sourcepath=$file;]$_" }
|
2020-08-01 08:32:59 +03:00
|
|
|
} # If there are any warnings
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2020-08-01 08:32:59 +03:00
|
|
|
} # If previous commit exists perform breaking change validation
|
2020-07-24 03:09:22 +03:00
|
|
|
|
2019-07-12 21:12:34 +03:00
|
|
|
} # For each file
|
|
|
|
|
2020-07-24 03:09:22 +03:00
|
|
|
if ($errorsTotal -gt 0) {
|
2020-08-06 02:00:06 +03:00
|
|
|
Write-Host "##vso[task.complete result=Failed;]Errors encountered."
|
2019-07-12 21:12:34 +03:00
|
|
|
}
|
2020-07-24 03:09:22 +03:00
|
|
|
elseif ($warningsTotal -gt 0) {
|
2019-07-12 21:12:34 +03:00
|
|
|
Write-Host "##vso[task.complete result=SucceededWithIssues;]Warnings encountered."
|
|
|
|
}
|
2020-07-24 03:09:22 +03:00
|
|
|
else {
|
2019-07-12 21:12:34 +03:00
|
|
|
Write-Host "##vso[task.complete result=Succeeded;]No error or warnings encountered."
|
|
|
|
}
|
2020-08-01 08:32:59 +03:00
|
|
|
env:
|
|
|
|
swaggerValidator: "$(ValidatorUrl)/ValidateSwagger"
|
|
|
|
changeValidator: "$(ValidatorUrl)/ValidateChange"
|
|
|
|
token: $(token)
|