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