Skip to content

Commit 8f0874e

Browse files
committed
feat: move to another tool supporting OAS 3.1 with nicer reporting
1 parent 8c55202 commit 8f0874e

File tree

4 files changed

+83
-49
lines changed

4 files changed

+83
-49
lines changed

.github/workflows/api-diff.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
test-branch-logic:
15+
test:
1616
runs-on: ubuntu-latest
1717
permissions:
1818
contents: read
@@ -40,4 +40,30 @@ jobs:
4040
run: chmod +x scripts/api-diff/api-diff.sh
4141

4242
- name: Run API diff check
43-
run: ./scripts/api-diff/api-diff.sh
43+
run: ./scripts/api-diff/api-diff.sh
44+
45+
html-reports:
46+
runs-on: ubuntu-latest
47+
needs: test-branch-logic
48+
permissions:
49+
contents: read
50+
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0
56+
57+
- name: Make script executable
58+
run: chmod +x scripts/api-diff/api-diff.sh
59+
60+
- name: Generate HTML reports
61+
run: ./scripts/api-diff/api-diff.sh --html-report
62+
63+
- name: Upload HTML reports
64+
uses: actions/upload-artifact@v4
65+
if: always()
66+
with:
67+
name: openapi-diff-reports
68+
path: reports/
69+
retention-days: 30

scripts/api-diff/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# API Diff Scripts
22

3-
This directory contains scripts for detecting and reporting API changes using [openapi-diff](https://github.com/OpenAPITools/openapi-diff).
3+
This directory contains scripts for detecting and reporting API changes using [openapi-changes](https://pb33f.io/openapi-changes/).
44

55
## Files
66

@@ -10,7 +10,7 @@ Main script that compares OpenAPI specifications against the master branch.
1010
**Usage:**
1111
```bash
1212
# From the repo root
13-
./scripts/api-diff/api-diff.sh [--fail-on-breaking] [filename.yaml]
13+
./scripts/api-diff/api-diff.sh [--fail-on-breaking] [--html-report] [filename.yaml]
1414

1515
# Check all xero*.yaml files
1616
./scripts/api-diff/api-diff.sh
@@ -20,10 +20,13 @@ Main script that compares OpenAPI specifications against the master branch.
2020

2121
# Fail on breaking changes (CI mode)
2222
./scripts/api-diff/api-diff.sh --fail-on-breaking
23+
24+
# Generate HTML reports
25+
./scripts/api-diff/api-diff.sh --html-report
2326
```
2427

2528
**Environment Variables:**
26-
- `OPENAPI_DIFF_DOCKER_IMAGE` - Docker image to use (default: `openapitools/openapi-diff:latest`)
29+
- `OPENAPI_CHANGES_DOCKER_IMAGE` - Docker image to use (default: `pb33f/openapi-changes:latest`)
2730
- `BASE_BRANCH` - Branch to compare against (default: `origin/master`)
2831

2932
### `api-diff.test.sh`
@@ -43,6 +46,7 @@ Tests validate that:
4346
These scripts are integrated into the GitHub Actions workflow at `.github/workflows/api-diff.yml`:
4447
- **test-branch-logic** job - Runs unit tests
4548
- **api-diff** job - Runs API diff checks with conditional breaking change enforcement
49+
- **html-reports** job - Generates HTML reports and uploads them as artifacts
4650

4751
### Branch Naming Convention
4852
The GitHub Actions workflow automatically adjusts its behavior based on branch names:

scripts/api-diff/api-diff.sh

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
# Script to check API diffs using openapi-diff
4-
# Usage: ./scripts/api-diff/api-diff.sh [--fail-on-breaking] [filename.yaml]
3+
# Script to check API diffs using openapi-changes
4+
# Usage: ./scripts/api-diff/api-diff.sh [--fail-on-breaking] [--html-report] [filename.yaml]
55
# Assumes you have Docker installed and the repo is checked out with master branch available
66

77
set -e # Exit on error
@@ -11,19 +11,22 @@ set -o pipefail # Catch errors in pipes
1111
cd "$(dirname "$0")/../.."
1212

1313
# Configuration
14-
DOCKER_IMAGE="${OPENAPI_DIFF_DOCKER_IMAGE:-openapitools/openapi-diff:latest}"
14+
DOCKER_IMAGE="${OPENAPI_CHANGES_DOCKER_IMAGE:-pb33f/openapi-changes:latest}"
1515
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
1616

1717
FAIL_ON_BREAKING=false
1818
TARGET_FILE=""
1919
DRY_RUN=false
20+
HTML_REPORT=false
2021

2122
# Parse arguments
2223
for arg in "$@"; do
2324
if [ "$arg" = "--fail-on-breaking" ]; then
2425
FAIL_ON_BREAKING=true
2526
elif [ "$arg" = "--dry-run" ]; then
2627
DRY_RUN=true
28+
elif [ "$arg" = "--html-report" ]; then
29+
HTML_REPORT=true
2730
elif [[ "$arg" == *.yaml ]]; then
2831
TARGET_FILE="$arg"
2932
fi
@@ -112,21 +115,30 @@ for file in $files; do
112115
continue
113116
fi
114117

115-
# Run openapi-diff to check for changes and breaking changes
116-
echo "--- API Diff ---"
117-
set +e
118-
DIFF_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" /base/"$file" /current/"$file" --fail-on-incompatible 2>&1)
119-
DIFF_EXIT=$?
120-
set -e
121-
122-
echo "$DIFF_OUTPUT"
123-
124-
if [ $DIFF_EXIT -eq 0 ]; then
125-
echo "✓ No breaking changes detected"
118+
# Run openapi-changes
119+
if [ "$HTML_REPORT" = true ]; then
120+
echo "--- Generating HTML Report ---"
121+
# Create reports directory if it doesn't exist
122+
mkdir -p reports
123+
REPORT_FILE="reports/${file%.yaml}-diff.html"
124+
docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" html-report /base/"$file" /current/"$file" > "$REPORT_FILE"
125+
echo "✓ HTML report generated: $REPORT_FILE"
126126
else
127-
echo "⚠ Breaking changes detected (exit code: $DIFF_EXIT)"
128-
BREAKING_CHANGES_FOUND=true
129-
FILES_WITH_BREAKING_CHANGES+=("$file")
127+
echo "--- API Diff ---"
128+
set +e
129+
DIFF_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" summary --no-logo --no-color /base/"$file" /current/"$file" 2>&1)
130+
DIFF_EXIT=$?
131+
set -e
132+
133+
echo "$DIFF_OUTPUT"
134+
135+
if [ $DIFF_EXIT -eq 0 ]; then
136+
echo "✓ No breaking changes detected"
137+
else
138+
echo "⚠ Breaking changes detected (exit code: $DIFF_EXIT)"
139+
BREAKING_CHANGES_FOUND=true
140+
FILES_WITH_BREAKING_CHANGES+=("$file")
141+
fi
130142
fi
131143

132144
PROCESSED_FILES=$((PROCESSED_FILES + 1))
@@ -139,7 +151,15 @@ echo "Processed: $PROCESSED_FILES/$TOTAL_FILES files"
139151
echo "========================================"
140152

141153
# Summary
142-
if [ "$BREAKING_CHANGES_FOUND" = true ]; then
154+
if [ "$HTML_REPORT" = true ]; then
155+
echo ""
156+
echo "📊 HTML reports generated:"
157+
if [ -d "reports" ]; then
158+
ls -la reports/
159+
else
160+
echo "No reports directory found"
161+
fi
162+
elif [ "$BREAKING_CHANGES_FOUND" = true ]; then
143163
echo ""
144164
echo "❌ Breaking changes detected in the following files:"
145165
for file in "${FILES_WITH_BREAKING_CHANGES[@]}"; do

scripts/api-diff/test-api-diff.sh

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Script to check API diffs using openapi-diff
3+
# Script to check API diffs using openapi-changes
44
# Usage: ./scripts/api-diff/test-api-diff.sh [--fail-on-breaking] [filename.yaml]
55
# Assumes you have Docker installed and the repo is checked out with master branch available
66

@@ -11,7 +11,7 @@ set -o pipefail # Catch errors in pipes
1111
cd "$(dirname "$0")/../.."
1212

1313
# Configuration
14-
DOCKER_IMAGE="${OPENAPI_DIFF_DOCKER_IMAGE:-openapitools/openapi-diff:latest}"
14+
DOCKER_IMAGE="${OPENAPI_CHANGES_DOCKER_IMAGE:-pb33f/openapi-changes:latest}"
1515
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
1616

1717
FAIL_ON_BREAKING=false
@@ -87,38 +87,22 @@ for file in $files; do
8787
continue
8888
fi
8989

90-
# Note: openapi-diff provides deterministic results for change detection.
90+
# Note: openapi-changes provides deterministic results for change detection.
9191
# Both error and warning counts are consistent between runs.
9292

93-
# Run openapi-diff changelog
94-
echo "--- Changelog ---"
93+
# Run openapi-changes summary
94+
echo "--- API Diff Summary ---"
9595
set +e
96-
CHANGELOG_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" changelog --include-path-params /base/"$file" /current/"$file" 2>&1)
97-
CHANGELOG_EXIT=$?
96+
SUMMARY_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" summary /base/"$file" /current/"$file" 2>&1)
97+
SUMMARY_EXIT=$?
9898
set -e
9999

100-
echo "$CHANGELOG_OUTPUT"
100+
echo "$SUMMARY_OUTPUT"
101101

102-
if [ $CHANGELOG_EXIT -eq 0 ]; then
103-
echo "✓ Changelog generated successfully"
104-
else
105-
echo "⚠ Could not generate changelog (exit code: $CHANGELOG_EXIT)"
106-
fi
107-
108-
# Run breaking changes check
109-
echo ""
110-
echo "--- Breaking changes check ---"
111-
set +e
112-
BREAKING_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" breaking --fail-on ERR --include-path-params /base/"$file" /current/"$file" 2>&1)
113-
BREAKING_EXIT=$?
114-
set -e
115-
116-
echo "$BREAKING_OUTPUT"
117-
118-
if [ $BREAKING_EXIT -eq 0 ]; then
102+
if [ $SUMMARY_EXIT -eq 0 ]; then
119103
echo "✓ No breaking changes detected"
120104
else
121-
echo "⚠ Breaking changes detected (exit code: $BREAKING_EXIT)"
105+
echo "⚠ Breaking changes detected (exit code: $SUMMARY_EXIT)"
122106
BREAKING_CHANGES_FOUND=true
123107
FILES_WITH_BREAKING_CHANGES+=("$file")
124108
fi

0 commit comments

Comments
 (0)