Skip to content

Commit 5deb69a

Browse files
dido18lucarin91
andauthored
Add GitHub Actions workflow to check OpenAPI breaking changes (#168)
* Add GitHub Actions workflow to check OpenAPI breaking changes * Update .github/workflows/openapi-spec.yml Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc> * Update .github/workflows/openapi-spec.yml Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc> * Pin oasdiff installation to version 1.11.7 --------- Co-authored-by: Luca Rinaldi <l.rinaldi@arduino.cc>
1 parent 19c9d62 commit 5deb69a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/openapi-spec.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Check for breaking OpenAPI changes
2+
3+
on:
4+
push:
5+
pull_request:
6+
paths:
7+
- "internal/api/docs/openapi.yaml"
8+
workflow_dispatch:
9+
inputs:
10+
target_branch:
11+
description: "Branch to compare against (used in manual runs)"
12+
required: false
13+
default: "main"
14+
15+
jobs:
16+
oasdiff:
17+
name: OASDiff Check
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version-file: go.mod
30+
31+
- name: Install oasdiff
32+
run: go install github.com/oasdiff/oasdiff@v1.11.7
33+
34+
- name: Add Go bin to PATH
35+
run: echo "${HOME}/go/bin" >> $GITHUB_PATH
36+
37+
- name: Determine base branch and fetch OpenAPI file
38+
id: get_base_openapi
39+
run: |
40+
BASE_BRANCH="${{ github.event.pull_request.base.ref || github.event.inputs.target_branch || 'main' }}"
41+
echo "Comparing against base branch: $BASE_BRANCH"
42+
git fetch origin "$BASE_BRANCH"
43+
git show origin/"$BASE_BRANCH":internal/api/docs/openapi.yaml > /tmp/base-openapi.yaml \
44+
|| (touch /tmp/base-openapi.yaml; echo "No base OpenAPI file found, using empty file.")
45+
46+
- name: Run oasdiff to check for breaking changes
47+
run: |
48+
if oasdiff breaking --format githubactions --filter-extension request-parameter-enum-value-added --fail-on ERR /tmp/base-openapi.yaml internal/api/docs/openapi.yaml; then
49+
echo "✅ No breaking changes detected in OpenAPI spec."
50+
else
51+
echo "❌ Breaking changes detected! Please review the OpenAPI spec."
52+
exit 1
53+
fi

0 commit comments

Comments
 (0)