|
| 1 | +on: |
| 2 | + pull_request: |
| 3 | + |
| 4 | +name: API Spec review |
| 5 | + |
| 6 | +env: |
| 7 | + COMPOSE_USER: root |
| 8 | + |
| 9 | +jobs: |
| 10 | + api-spec: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + name: Ensure committed API specification is up to date |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v5 |
| 16 | + with: |
| 17 | + fetch-depth: 2 |
| 18 | + |
| 19 | + # https://taskfile.dev/installation/#github-actions |
| 20 | + - uses: go-task/setup-task@v1 |
| 21 | + |
| 22 | + - run: | |
| 23 | + docker network create frontend |
| 24 | + task --yes site:update |
| 25 | +
|
| 26 | + - name: Export API specification |
| 27 | + run: | |
| 28 | + task --yes api:spec:export |
| 29 | +
|
| 30 | + - name: Check for changes in specification |
| 31 | + id: git-diff-spec |
| 32 | + continue-on-error: true |
| 33 | + run: git diff --diff-filter=ACMRT --exit-code public/spec.yaml |
| 34 | + |
| 35 | + - name: Comment PR |
| 36 | + if: steps.git-diff-spec.outcome == 'failure' |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ github.token }} |
| 39 | + run: | |
| 40 | + echo '## 🛑 Exported API specification file not up to date' > var/comment.md |
| 41 | + echo '' >> var/comment.md |
| 42 | + echo 'Please run `task api:spec:export` to export the API specification. Then commit and push the changes.' >> var/comment.md |
| 43 | + gh pr comment ${{ github.event.pull_request.number }} --body-file var/comment.md --create-if-none --edit-last |
| 44 | +
|
| 45 | + - name: Fail job api spec is not up to date |
| 46 | + if: steps.git-diff-spec.outcome == 'failure' |
| 47 | + run: | |
| 48 | + exit 1 |
| 49 | +
|
| 50 | + detect-breaking-changes: |
| 51 | + name: Detect breaking changes in API specification |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: [api-spec] |
| 54 | + steps: |
| 55 | + - name: Check out BASE rev |
| 56 | + uses: actions/checkout@v5 |
| 57 | + with: |
| 58 | + ref: ${{ github.base_ref }} |
| 59 | + path: base |
| 60 | + |
| 61 | + - name: Check out HEAD rev |
| 62 | + uses: actions/checkout@v5 |
| 63 | + with: |
| 64 | + ref: ${{ github.head_ref }} |
| 65 | + path: head |
| 66 | + |
| 67 | + - name: Run OpenAPI Changed (from HEAD rev) |
| 68 | + id: api-changed |
| 69 | + continue-on-error: true |
| 70 | + uses: docker://openapitools/openapi-diff:latest |
| 71 | + with: |
| 72 | + args: --fail-on-changed base/public/spec.yaml head/public/spec.yaml --markdown api-spec-changed.md |
| 73 | + |
| 74 | + - name: Run OpenAPI Incompatible (from HEAD rev) |
| 75 | + id: api-incompatible |
| 76 | + continue-on-error: true |
| 77 | + uses: docker://openapitools/openapi-diff:latest |
| 78 | + with: |
| 79 | + args: --fail-on-incompatible base/public/spec.yaml head/public/spec.yaml --markdown api-spec-incompatible.md |
| 80 | + |
| 81 | + - name: Comment PR with no changes |
| 82 | + if: steps.api-changed.outcome == 'success' && steps.api-incompatible.outcome == 'success' |
| 83 | + working-directory: head |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ github.token }} |
| 86 | + run: | |
| 87 | + gh pr comment ${{ github.event.pull_request.number }} --body "✅ **No changes detected in API specification**" --create-if-none --edit-last |
| 88 | +
|
| 89 | + - name: Comment PR with non-breaking changes |
| 90 | + if: steps.api-changed.outcome == 'failure' && steps.api-incompatible.outcome == 'success' |
| 91 | + working-directory: head |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ github.token }} |
| 94 | + run: | |
| 95 | + echo "## ⚠️ Non-Breaking changes detected in API specification" > ../comment.md |
| 96 | + echo "" >> ../comment.md |
| 97 | + cat ../api-spec-changed.md >> ../comment.md |
| 98 | + gh pr comment ${{ github.event.pull_request.number }} --body-file ../comment.md --create-if-none --edit-last |
| 99 | +
|
| 100 | + - name: Comment PR with breaking changes |
| 101 | + if: steps.api-incompatible.outcome == 'failure' |
| 102 | + working-directory: head |
| 103 | + env: |
| 104 | + GH_TOKEN: ${{ github.token }} |
| 105 | + run: | |
| 106 | + echo "## 🛑 Breaking changes detected in API specification" > ../comment.md |
| 107 | + echo "" >> ../comment.md |
| 108 | + cat ../api-spec-incompatible.md >> ../comment.md |
| 109 | + gh pr comment ${{ github.event.pull_request.number }} --body-file ../comment.md --create-if-none --edit-last |
| 110 | +
|
| 111 | + - name: Fail if breaking changes detected |
| 112 | + if: steps.api-incompatible.outcome == 'failure' |
| 113 | + run: | |
| 114 | + exit 1 |
0 commit comments