PowerPlatformConnectors/.pipelines/swagger_validation.yml

89 строки
3.5 KiB
YAML
Исходник Обычный вид История

pool:
2020-08-01 08:32:59 +03:00
vmImage: "ubuntu-latest"
steps:
2020-08-01 08:32:59 +03:00
- pwsh: |
$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$'}
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-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-08-01 08:32:59 +03:00
$newFileContent = Get-Content $file -Raw
2020-08-01 08:32:59 +03:00
# Validate swagger
$isCertValidation = $file -Like "*certified-connectors/*" -Or $file -Like "*independent-publisher-connectors/*"
$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-08-01 08:32:59 +03:00
if ($errors) {
$errorsTotal += $errors.Count
$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
$warnings | foreach { Write-Host "##vso[task.logissue type=warning;sourcepath=$file;]$_" }
2020-08-01 08:32:59 +03:00
} # If Swagger Warnings
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-08-01 08:32:59 +03:00
$changeValidation = @{
OldSwagger = $oldSwagger
NewSwagger = $newSwagger
}
2020-08-07 01:39:46 +03:00
$changeValidationJson = ConvertTo-Json $changeValidation -Depth 100 -Compress
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-08-01 08:32:59 +03:00
$errors = $results.Errors
$warnings = $results.Warnings
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-08-01 08:32:59 +03:00
if ($warnings) {
$warningsTotal += $warnings.Count
$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-08-01 08:32:59 +03:00
} # If previous commit exists perform breaking change validation
2019-07-12 21:12:34 +03:00
} # For each file
if ($errorsTotal -gt 0) {
Write-Host "##vso[task.complete result=Failed;]Errors encountered."
2019-07-12 21:12:34 +03:00
}
elseif ($warningsTotal -gt 0) {
2019-07-12 21:12:34 +03:00
Write-Host "##vso[task.complete result=SucceededWithIssues;]Warnings encountered."
}
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)