Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
642dcc4
poc: test oasfiff API changelog
Prajna1999 May 26, 2026
bb5ebdb
Merge branch 'main' into chore/diffs-in-api-contract
Prajna1999 May 26, 2026
192650f
fix: in CI generate and compare diffs on the fly
Prajna1999 May 26, 2026
954c594
fix: in CI generate and compare diffs on the fly
Prajna1999 May 26, 2026
69e3590
Merge remote-tracking branch 'refs/remotes/origin/chore/diffs-in-api-…
Prajna1999 May 26, 2026
81e2cb4
check CI
Prajna1999 May 27, 2026
d61c828
fix: base cwd for .env.example
Prajna1999 May 28, 2026
9eb4ffe
fix: path for Diff breaking changes step
Prajna1999 May 28, 2026
e352cf7
test: remove job_id from LLMJobImmediatePublic
Prajna1999 May 28, 2026
0b092d7
chore: better siren and labeling to bypass
Prajna1999 May 28, 2026
b90bb97
fix: conditional failure of breaking change
Prajna1999 May 28, 2026
c40815b
chore: prettify md files
Prajna1999 May 28, 2026
8264a02
test
Prajna1999 May 28, 2026
e2fcd4d
garnishing sticky message in the PR comment
Prajna1999 May 28, 2026
f385144
chore: test with non_breaking changes
Prajna1999 May 28, 2026
5fc4c82
chore: revert all schema changes
Prajna1999 May 28, 2026
f6a4a0f
test: breaking changes
Prajna1999 May 28, 2026
8dab138
Merge branch 'main' into chore/diffs-in-api-contract
Prajna1999 Jun 1, 2026
9781016
cosmetic UI changes
Prajna1999 Jun 1, 2026
b0266d4
test with creds
Prajna1999 Jun 1, 2026
60a88c5
another test
Prajna1999 Jun 1, 2026
984c4cc
chore: non breaking gree
Prajna1999 Jun 1, 2026
19b3b28
Merge branch 'main' into chore/diffs-in-api-contract
Ayush8923 Jun 1, 2026
985e738
chore: remove test breaking changes
Prajna1999 Jun 1, 2026
257b1cc
Merge remote-tracking branch 'refs/remotes/origin/chore/diffs-in-api-…
Prajna1999 Jun 1, 2026
9be2496
Update .github/workflows/oasdiff.yaml
Prajna1999 Jun 1, 2026
9020324
Update .github/workflows/oasdiff.yaml
Prajna1999 Jun 1, 2026
7653cc8
Update .github/workflows/oasdiff.yaml
Prajna1999 Jun 1, 2026
51350dd
Update .github/workflows/oasdiff.yaml
Prajna1999 Jun 1, 2026
bceb063
Update .github/workflows/oasdiff.yaml
Prajna1999 Jun 1, 2026
6dea5a7
fix: comments
Prajna1999 Jun 2, 2026
d1bfa4b
fix: oasdiff undefined
Prajna1999 Jun 2, 2026
e321c02
fix: workflow not triggering
Prajna1999 Jun 2, 2026
eb833cb
fix: logic fix at generate comment
Prajna1999 Jun 2, 2026
7c99e96
Merge branch 'main' into chore/diffs-in-api-contract
Ayush8923 Jun 2, 2026
2e87b88
chore: remove test fields
Prajna1999 Jun 2, 2026
c31cfe1
Merge remote-tracking branch 'refs/remotes/origin/chore/diffs-in-api-…
Prajna1999 Jun 2, 2026
6c49b2b
Update backend/scripts/kaapi_export_openapi.py
Ayush8923 Jun 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions .github/workflows/api-breaking-changes.yaml
Comment thread
Prajna1999 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Generate an API changelog by diffing the OpenAPI schema between base and HEAD.
name: API Breaking Changes Check

on:
pull_request:
branches: ["main"]
# Re-run when the approval label is added/removed so merge gating updates immediately.
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read
pull-requests: write
Comment thread
Prajna1999 marked this conversation as resolved.

# One run per PR. A new commit (or label toggle) cancels the in-flight run instead
concurrency:
group: api-changes-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
breaking-changes:
runs-on: ubuntu-latest
Comment thread
Ayush8923 marked this conversation as resolved.
timeout-minutes: 15
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
path: head
fetch-depth: 0
persist-credentials: false

- name: Checkout base ref
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
Comment thread
coderabbitai[bot] marked this conversation as resolved.
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v3
Comment thread
Prajna1999 marked this conversation as resolved.

- name: Prepare env files
run: |
cp head/.env.test.example head/.env.test
cp head/.env.test.example base/.env.test

- name: Export base OpenAPI schema
working-directory: base/backend
env:
ENVIRONMENT: testing
run: |
uv sync --frozen
if [ -f scripts/kaapi_export_openapi.py ]; then
uv run python scripts/kaapi_export_openapi.py "$GITHUB_WORKSPACE/base-openapi.yaml"
else
# Base ref predates this workflow; copy the HEAD script in to bootstrap.
cp "$GITHUB_WORKSPACE/head/backend/scripts/kaapi_export_openapi.py" scripts/
uv run python scripts/kaapi_export_openapi.py "$GITHUB_WORKSPACE/base-openapi.yaml"
fi

- name: Export HEAD OpenAPI schema
working-directory: head/backend
env:
ENVIRONMENT: testing
run: |
uv sync --frozen
uv run python scripts/kaapi_export_openapi.py "$GITHUB_WORKSPACE/head-openapi.yaml"

- name: Generate diff (JSON)
env:
OASDIFF_IMAGE: tufin/oasdiff:latest
run: |
set -euo pipefail

run_diff() {
local cmd="$1" out="$2"
docker run --rm -v "$PWD:/specs" "$OASDIFF_IMAGE" \
"$cmd" /specs/base-openapi.yaml /specs/head-openapi.yaml \
--format json > "$out" || true
if ! jq -e . "$out" >/dev/null 2>&1; then
echo "[]" > "$out"
fi
}
run_diff changelog changelog.json
run_diff breaking breaking.json

echo "breaking=$(jq 'length' breaking.json) changelog=$(jq 'length' changelog.json)"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- name: Debug raw oasdiff output
run: |
echo "=== breaking.json ==="
cat breaking.json || echo "(missing)"
echo
echo "=== changelog.json ==="
cat changelog.json || echo "(missing)"

- name: Build PR comment body
if: always()
run: |
plural() { if [ "$1" -ne 1 ]; then echo s; fi; }

# Render an oasdiff JSON array as a markdown table.
# Severity dot: red only for breaking (ERR), green for everything else
# (WARN / INFO — non-breaking additions like optional params).
to_table() {
jq -r '
def dot(lvl):
if lvl >= 2 then "🔴"
else "🟢" end;
if (. // []) | length == 0 then "_No entries._"
else
"| | Method | Path | Change |",
"|:-:|:-:|:--|:--|",
(.[] | "| \(dot(.level)) | `\(.operation // "—")` | `\(.path // "—")` | \((.text // "") | gsub("[\r\n]+"; " ")) |")
end
' "$1"
}

BREAKING=$(jq 'length' breaking.json)
CHANGES=$(jq 'length' changelog.json)

if [ "$BREAKING" -gt 0 ]; then
STATUS="🔴 **${BREAKING} breaking change$(plural $BREAKING)**"
ALERT='> [!CAUTION]'
HEADLINE="Downstream consumers may need an update before merging."
BREAKING_OPEN=" open"
elif [ "$CHANGES" -gt 0 ]; then
STATUS="🟢 **${CHANGES} non-breaking change$(plural $CHANGES)**"
ALERT='> [!TIP]'
HEADLINE="Safe to merge from an API-contract perspective."
BREAKING_OPEN=""
else
STATUS="⚪ **No API surface changes**"
ALERT='> [!NOTE]'
HEADLINE="This PR does not modify the API contract."
BREAKING_OPEN=""
fi

{
echo "## OpenAPI changes   ${STATUS}"
echo
echo "${ALERT}"
echo "> ${HEADLINE}"
echo

if [ "$BREAKING" -gt 0 ]; then
echo "<details${BREAKING_OPEN}>"
echo "<summary><b>Breaking changes</b> &nbsp;·&nbsp; <code>${BREAKING}</code></summary>"
echo
to_table breaking.json
echo
echo "</details>"
echo
fi

if [ "$CHANGES" -gt 0 ]; then
echo "<details>"
echo "<summary><b>Full changelog</b> &nbsp;·&nbsp; <code>${CHANGES}</code></summary>"
echo
to_table changelog.json
echo
echo "</details>"
echo
fi

echo "<sub><code>${GITHUB_BASE_REF}</code> ↔ <code>${GITHUB_SHA::8}</code> · generated by <a href=\"https://github.com/oasdiff/oasdiff\">oasdiff</a></sub>"
} > comment.md
cat comment.md >> "$GITHUB_STEP_SUMMARY"

- name: Post sticky PR comment
uses: marocchino/sticky-pull-request-comment@v3
with:
header: oasdiff
path: comment.md

- name: Enforce breaking-change gate
# Skip the hard fail when a reviewer has explicitly acknowledged the breaking change
# by applying the `breaking-change-approved` label to the PR.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'breaking-change-approved') }}
run: |
set -euo pipefail
count=$(jq 'length' breaking.json)
if [ "$count" -gt 0 ]; then
echo "::error::${count} breaking change(s) detected. Apply the 'breaking-change-approved' label to override the gate."
exit 1
fi
echo "No breaking changes detected."
23 changes: 23 additions & 0 deletions backend/scripts/kaapi_export_openapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Export the FastAPI app's OpenAPI schema to a YAML file.

Usage:
uv run python -m scripts.kaapi_export_openapi [output_path]
"""

import sys
from pathlib import Path

import yaml

from app.main import app


def main() -> None:
output = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("openapi.yaml")
schema = app.openapi()
output.write_text(yaml.safe_dump(schema, sort_keys=False))
print(f"[export_openapi] Wrote {output} ({output.stat().st_size} bytes)")


if __name__ == "__main__":
main()
Loading