Skip to content

Commit 2931fae

Browse files
committed
Add GitHub Actions workflow to check OpenAPI breaking changes
1 parent 46e4f4c commit 2931fae

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/openapi-spec.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
env:
15+
GO_VERSION: "1.25.1"
16+
17+
jobs:
18+
oasdiff:
19+
name: OASDiff Check
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: ${{ env.GO_VERSION }}
32+
33+
- name: Install oasdiff
34+
run: go install github.com/oasdiff/oasdiff@latest
35+
36+
- name: Add Go bin to PATH
37+
run: echo "${HOME}/go/bin" >> $GITHUB_PATH
38+
39+
- name: Determine base branch and fetch OpenAPI file
40+
id: get_base_openapi
41+
run: |
42+
BASE_BRANCH="${{ github.event.pull_request.base.ref || github.event.inputs.target_branch || 'main' }}"
43+
echo "Comparing against base branch: $BASE_BRANCH"
44+
git fetch origin "$BASE_BRANCH"
45+
git show origin/"$BASE_BRANCH":internal/api/docs/openapi.yaml > /tmp/base-openapi.yaml \
46+
|| (touch /tmp/base-openapi.yaml; echo "No base OpenAPI file found, using empty file.")
47+
48+
- name: Run oasdiff to check for breaking changes
49+
run: |
50+
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
51+
echo "✅ No breaking changes detected in OpenAPI spec."
52+
else
53+
echo "❌ Breaking changes detected! Please review the OpenAPI spec."
54+
exit 1
55+
fi

0 commit comments

Comments
 (0)