Skip to content

Commit 32148ab

Browse files
committed
4881: Comment on PR with API spec result
1 parent 7cc4195 commit 32148ab

1 file changed

Lines changed: 39 additions & 15 deletions

File tree

.github/workflows/api-spec.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
task --yes api:spec:export
2929
3030
- name: Check for changes in specification
31-
run: git diff --diff-filter=ACMRT --exit-code public/spec.yaml
31+
run: git diff --diff-filter=ACMRT --exit-code public/spec.yaml --markdown api-spec-result.md
3232

3333
detect-breaking-changes:
3434
runs-on: ubuntu-latest
@@ -46,24 +46,48 @@ jobs:
4646
ref: ${{ github.head_ref }}
4747
path: head
4848

49-
- name: Run OpenAPI Diff (from HEAD rev)
50-
id: api-diff
49+
- name: Run OpenAPI Changes (from HEAD rev)
50+
id: api-changes
5151
continue-on-error: true
5252
uses: docker://openapitools/openapi-diff:latest
5353
with:
54-
args: --fail-on-incompatible base/public/spec.yaml head/public/spec.yaml
54+
args: --fail-on-changes base/public/spec.yaml head/public/spec.yaml --markdown api-spec-changes.md
5555

56-
- name: Comment PR with API diff results
57-
if: always()
56+
- name: Run OpenAPI Incompatible (from HEAD rev)
57+
id: api-incompatible
58+
continue-on-error: true
59+
uses: docker://openapitools/openapi-diff:latest
60+
with:
61+
args: --fail-on-incompatible base/public/spec.yaml head/public/spec.yaml --markdown api-spec-incompatible.md
62+
63+
- name: Comment PR with no changes
64+
if: steps.api-changes.outcome == 'success' && steps.api-incompatible.outcome == 'success'
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
run: |
68+
gh pr comment ${{ github.event.pull_request.number }} --body "✅ **No changes detected in API specification**" --create-if-none --edit-last
69+
70+
- name: Comment PR with non-breaking changes
71+
if: steps.api-.outcome == 'failure' && steps.api-incompatible.outcome == 'success'
5872
env:
5973
GH_TOKEN: ${{ github.token }}
6074
run: |
61-
if [ -f result.md ]; then
62-
gh pr comment ${{ github.event.pull_request.number }} --body-file result.md
63-
else
64-
if [ "${{ steps.api-diff.outcome }}" == "failure" ]; then
65-
gh pr comment ${{ github.event.pull_request.number }} --body "⚠️ **Breaking changes detected in API specification**"
66-
else
67-
gh pr comment ${{ github.event.pull_request.number }} --body "✅ **No breaking changes detected in API specification**"
68-
fi
69-
fi
75+
echo "## ⚠️ Non-Breaking changes detected in API specification" > ../comment.md
76+
echo "" >> ../comment.md
77+
cat api-spec-changes.md >> ../comment.md
78+
gh pr comment ${{ github.event.pull_request.number }} --body-file ../comment.md --create-if-none --edit-last
79+
80+
- name: Comment PR with breaking changes
81+
if: steps.api-incompatible.outcome == 'failure'
82+
env:
83+
GH_TOKEN: ${{ github.token }}
84+
run: |
85+
echo "## 🛑 Breaking changes detected in API specification" > ../comment.md
86+
echo "" >> ../comment.md
87+
cat api-spec-changes.md >> ../comment.md
88+
gh pr comment ${{ github.event.pull_request.number }} --body-file ../comment.md --create-if-none --edit-last
89+
90+
- name: Fail if breaking changes detected
91+
if: steps.api-incompatible.outcome == 'failure'
92+
run: |
93+
exit 1

0 commit comments

Comments
 (0)