|
| 1 | +name: Validate OAS Files |
| 2 | + |
| 3 | +on: [pull_request] |
| 4 | + |
| 5 | +jobs: |
| 6 | + discover-changed-files: |
| 7 | + name: Discover Changed OpenAPI Files |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 11 | + has_changes: ${{ steps.changed-files.outputs.any_changed }} |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + - name: Check for changed OAS files |
| 15 | + id: changed-files |
| 16 | + uses: tj-actions/changed-files@v41 |
| 17 | + with: |
| 18 | + files: | |
| 19 | + openapi/**/*.yml |
| 20 | + openapi/**/*.yaml |
| 21 | + - name: Build matrix from changed files |
| 22 | + id: set-matrix |
| 23 | + if: steps.changed-files.outputs.any_changed == 'true' |
| 24 | + run: | |
| 25 | + matrix_json=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | jq -R -s -c ' |
| 26 | + split(" ") | |
| 27 | + map(select(length > 0)) | |
| 28 | + map({ |
| 29 | + openapi_file: ., |
| 30 | + filename: (. | split("/")[-1]) |
| 31 | + }) |
| 32 | + ') |
| 33 | + echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT |
| 34 | + echo "Changed files matrix: ${matrix_json}" |
| 35 | +
|
| 36 | + validate-openapi: |
| 37 | + name: Validate ${{ matrix.filename }} |
| 38 | + needs: discover-changed-files |
| 39 | + if: needs.discover-changed-files.outputs.has_changes == 'true' |
| 40 | + runs-on: ubuntu-latest |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + include: ${{ fromJson(needs.discover-changed-files.outputs.matrix) }} |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v3 |
| 46 | + - name: Validate Schema for ${{ matrix.openapi_file }} |
| 47 | + uses: thiyagu06/openapi-validator-action@v1 |
| 48 | + with: |
| 49 | + filepath: ${{ matrix.openapi_file }} |
| 50 | + - name: Validate YAML for ${{ matrix.openapi_file }} |
| 51 | + uses: ibiqlik/action-yamllint@v3 |
| 52 | + with: |
| 53 | + file_or_dir: ${{ matrix.openapi_file }} |
| 54 | + config_file: .yamllint.yml |
0 commit comments