diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml deleted file mode 100644 index 1631651105..0000000000 --- a/.github/workflows/validation.yml +++ /dev/null @@ -1,109 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [ dev, master ] - pull_request: - branches: [ dev, master ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.1 - with: - fetch-depth: 2 - - name: "Swagger Validator" - id: SwaggerValidator - shell: pwsh - env: - swaggerValidator: "${{secrets.ValidatorUrl}}/ValidateSwagger" - changeValidator: "${{secrets.ValidatorUrl}}/ValidateChange" - token: ${{secrets.TOKEN}} - run: | - $errorsTotal = 0 - $warningsTotal = 0 - - # Get the list of files for the given PR - $currentLocation = Get-Location - - $files = git diff HEAD~1 --name-only - $swaggerFiles = $files | where {$_ -match '.+?apidefinition.swagger.json$'} - - $Headers = @{ - Authorization = $env:token - } - - foreach ($file in $swaggerFiles) { - $currentFilePath = Join-Path $currentLocation ($file.Replace('/', '\')) - $previousCommitHash = git log --max-count=1 --skip=1 --first-parent --pretty=format:%H $currentFilePath - - $newFileContent = Get-Content $file -Raw - - # Validate swagger - $results = Invoke-RestMethod -Uri $env:swaggerValidator -Headers $Headers -Method Post -ContentType "application/json" -Body $newFileContent - - $errors = $results.Errors - $warnings = $results.Warnings - - if ($errors) { - $errorsTotal += $errors.Count - $errors | foreach { Write-Host "::error file={$file}::$_" } - } # If Swagger Error - - if ($warnings) { - $warningsTotal += $warnings.Count - $warnings | foreach { Write-Host "::warning file={$file}::$_" } - } # If Swagger Warnings - - # Breaking change dectection - # 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 - - $changeValidation = @{ - OldSwagger = $oldSwagger - NewSwagger = $newSwagger - } - - $changeValidationJson = ConvertTo-Json $changeValidation - - # Validate changes - $results = Invoke-RestMethod -Uri $env:changeValidator -Headers $Headers -Method Post -ContentType "application/json" -Body $changeValidationJson - - $errors = $results.Errors - $warnings = $results.Warnings - - if ($errors) { - $errorsTotal += $errors.Count - $errors | foreach { Write-Host "::error file={$file}::$_" } - } # If there are any errors - - if ($warnings) { - $warningsTotal += $warnings.Count - $warnings | foreach { Write-Host "::warning file={$file}::$_" } - } # If there are any warnings - - } # If previous commit exists perform breaking change validation - } # For each file - - if ($errorsTotal -gt 0) { - Write-Host "::error::Errors encountered." - exit 1 - } - elseif ($warningsTotal -gt 0) { - Write-Host "::warning::Warnings encountered." - } - else { - Write-Host "No error or warnings encountered." - }