Skip to content

Commit b1d3167

Browse files
turegjorupclaude
andcommitted
6654: Replace API spec workflow with oasdiff-based breaking change detection
Replace the old api-spec.yml (Java-based openapitools/openapi-diff, task runner) with a new api-spec.yaml using oasdiff (Go, FOSS). Fixes file name mismatch (spec.yaml -> api-spec-v1.yaml), uses docker compose pattern, and adds path filtering. Remove redundant apispec job from pr.yaml. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c954906 commit b1d3167

2 files changed

Lines changed: 172 additions & 247 deletions

File tree

.github/workflows/api-spec.yaml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: API Specification
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "src/**/*.php"
7+
- "config/**"
8+
- "composer.json"
9+
- "composer.lock"
10+
- "public/api-spec-v1.yaml"
11+
- "public/api-spec-v1.json"
12+
- "docker-compose.yml"
13+
14+
env:
15+
COMPOSE_USER: runner
16+
17+
jobs:
18+
api-spec-export:
19+
name: Ensure API specification is up to date
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v6
24+
25+
- name: Create docker network
26+
run: docker network create frontend
27+
28+
- name: Export API specification
29+
run: |
30+
docker compose up --detach
31+
docker compose exec phpfpm composer install --no-interaction
32+
docker compose exec phpfpm composer update-api-spec
33+
34+
- name: Check for uncommitted changes
35+
id: git-diff-spec
36+
continue-on-error: true
37+
run: |
38+
git diff --diff-filter=ACMRT --exit-code public/api-spec-v1.yaml public/api-spec-v1.json
39+
40+
- name: Comment PR if spec is outdated
41+
if: steps.git-diff-spec.outcome == 'failure'
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
run: |
45+
gh pr comment ${{ github.event.pull_request.number }} \
46+
--body "$(cat <<'EOF'
47+
## API specification not up to date
48+
49+
The committed API specification files do not match the exported output.
50+
51+
Please run the following command, then commit and push the changes:
52+
53+
```shell
54+
docker compose exec phpfpm composer update-api-spec
55+
```
56+
EOF
57+
)" \
58+
--create-if-none --edit-last
59+
60+
- name: Fail if spec is outdated
61+
if: steps.git-diff-spec.outcome == 'failure'
62+
run: exit 1
63+
64+
api-spec-breaking-changes:
65+
name: Detect breaking changes in API specification
66+
runs-on: ubuntu-latest
67+
needs: [api-spec-export]
68+
permissions:
69+
pull-requests: write
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v6
73+
74+
- name: Fetch base branch for comparison
75+
run: git fetch --depth=1 origin ${{ github.base_ref }}
76+
77+
- name: Detect breaking changes
78+
id: breaking
79+
continue-on-error: true
80+
uses: oasdiff/oasdiff-action/breaking@main
81+
with:
82+
base: 'origin/${{ github.base_ref }}:public/api-spec-v1.yaml'
83+
revision: 'public/api-spec-v1.yaml'
84+
fail-on: ERR
85+
86+
- name: Generate changelog
87+
id: changelog
88+
continue-on-error: true
89+
uses: oasdiff/oasdiff-action/changelog@main
90+
with:
91+
base: 'origin/${{ github.base_ref }}:public/api-spec-v1.yaml'
92+
revision: 'public/api-spec-v1.yaml'
93+
format: markdown
94+
output-to-file: changelog.md
95+
96+
- name: Comment PR - no changes
97+
if: steps.breaking.outcome == 'success' && hashFiles('changelog.md') == ''
98+
env:
99+
GH_TOKEN: ${{ github.token }}
100+
run: |
101+
gh pr comment ${{ github.event.pull_request.number }} \
102+
--body "## API Specification
103+
104+
No changes detected in API specification." \
105+
--create-if-none --edit-last
106+
107+
- name: Comment PR - non-breaking changes
108+
if: steps.breaking.outcome == 'success' && hashFiles('changelog.md') != ''
109+
env:
110+
GH_TOKEN: ${{ github.token }}
111+
run: |
112+
{
113+
echo "## API Specification - Non-breaking changes"
114+
echo ""
115+
cat changelog.md
116+
} > comment.md
117+
gh pr comment ${{ github.event.pull_request.number }} \
118+
--body-file comment.md \
119+
--create-if-none --edit-last
120+
121+
- name: Comment PR - breaking changes
122+
if: steps.breaking.outcome == 'failure'
123+
env:
124+
GH_TOKEN: ${{ github.token }}
125+
run: |
126+
{
127+
echo "## API Specification - Breaking changes detected"
128+
echo ""
129+
if [ -s changelog.md ]; then
130+
cat changelog.md
131+
else
132+
echo "The breaking changes action detected incompatible changes. Review the action logs for details."
133+
fi
134+
} > comment.md
135+
gh pr comment ${{ github.event.pull_request.number }} \
136+
--body-file comment.md \
137+
--create-if-none --edit-last
138+
139+
- name: Fail if breaking changes detected
140+
if: steps.breaking.outcome == 'failure'
141+
run: exit 1

0 commit comments

Comments
 (0)