Skip to content

Commit 600ac3d

Browse files
committed
feat: improve reporting and skip xero-webhooks.yaml (for now)
1 parent 03f58d7 commit 600ac3d

File tree

4 files changed

+102
-13
lines changed

4 files changed

+102
-13
lines changed

scripts/api-diff/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ Main script that compares OpenAPI specifications against the master branch.
2929
- `OPENAPI_CHANGES_DOCKER_IMAGE` - Docker image to use (default: `pb33f/openapi-changes:latest`)
3030
- `BASE_BRANCH` - Branch to compare against (default: `origin/master`)
3131

32+
### Comparing Different Branches
33+
34+
By default, `api-diff.sh` compares your current branch against `origin/master`. You can compare against any other branch by setting the `BASE_BRANCH` environment variable:
35+
36+
**Compare current branch against a different target branch:**
37+
```bash
38+
# Compare against origin/develop
39+
BASE_BRANCH=origin/develop ./scripts/api-diff/api-diff.sh
40+
41+
# Compare against origin/main
42+
BASE_BRANCH=origin/main ./scripts/api-diff/api-diff.sh
43+
44+
# Compare against a feature branch
45+
BASE_BRANCH=origin/feature/new-api ./scripts/api-diff/api-diff.sh
46+
47+
# Compare specific file against different branch
48+
BASE_BRANCH=origin/v2-api ./scripts/api-diff/api-diff.sh xero-webhooks.yaml
49+
```
50+
51+
**Compare two specific branches (advanced usage):**
52+
If you need to compare two arbitrary branches, you can temporarily switch to one branch and set BASE_BRANCH to the other:
53+
54+
```bash
55+
# Compare feature-branch against develop
56+
git checkout feature-branch
57+
BASE_BRANCH=origin/develop ./scripts/api-diff/api-diff.sh
58+
59+
# Compare main against a tag
60+
git checkout main
61+
BASE_BRANCH=v1.0.0 ./scripts/api-diff/api-diff.sh
62+
```
63+
3264
### `api-diff.test.sh`
3365
Unit tests for the branch logic pattern matching used in GitHub Actions.
3466

@@ -40,6 +72,8 @@ Unit tests for the branch logic pattern matching used in GitHub Actions.
4072
Tests validate that:
4173
- Branches containing `breaking` anywhere in the name are correctly identified
4274
- Other branches are handled with breaking change enforcement
75+
- All command-line flags (`--fail-on-breaking`, `--allow-breaking`, `--dry-run`, `--html-report`) are parsed correctly
76+
- Flag precedence and override behavior works as expected
4377

4478
## Integration
4579

scripts/api-diff/api-diff.sh

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ fi
6565
# Fetch master if not already done
6666
git fetch "${BASE_BRANCH%%/*}" "${BASE_BRANCH##*/}" 2>/dev/null || echo "Warning: Could not fetch ${BASE_BRANCH}"
6767

68-
# Create temp directory for master branch files (outside repo to avoid overlap with /current mount)
69-
TEMP_DIR=$(mktemp -d)
70-
trap "rm -rf $TEMP_DIR" EXIT
68+
# Use tmp directory for master branch files (outside repo to avoid overlap with /current mount)
69+
TEMP_DIR="./tmp"
70+
71+
REPORTS_DIR="./reports"
72+
73+
# Ensure tmp directory exists
74+
rm -rf "$TEMP_DIR"
75+
mkdir -p "$TEMP_DIR"
7176

7277
# Get list of xero*.yaml files (excluding any master_*.yaml files)
7378
if [ -n "$TARGET_FILE" ]; then
@@ -80,7 +85,7 @@ if [ -n "$TARGET_FILE" ]; then
8085
echo "Running diff for single file: $TARGET_FILE"
8186
else
8287
# All xero*.yaml files
83-
files=$(ls xero*.yaml 2>/dev/null | grep -v "^master_")
88+
files=$(ls xero*.yaml 2>/dev/null)
8489
if [ -z "$files" ]; then
8590
echo "No xero*.yaml files found"
8691
exit 1
@@ -98,6 +103,12 @@ echo "Using Docker image: $DOCKER_IMAGE"
98103
echo "Base branch: $BASE_BRANCH"
99104
echo "========================================"
100105

106+
# Ensure reports directory exists (only once, not per file)
107+
if [ "$HTML_REPORT" = true ]; then
108+
rm -rf "$REPORTS_DIR"
109+
mkdir -p "$REPORTS_DIR"
110+
fi
111+
101112
for file in $files; do
102113
TOTAL_FILES=$((TOTAL_FILES + 1))
103114
echo ""
@@ -115,18 +126,32 @@ for file in $files; do
115126
continue
116127
fi
117128

129+
# Fix malformed YAML in base files (temporary workaround for xero-webhooks.yaml)
130+
if [ "$file" = "xero-webhooks.yaml" ]; then
131+
# Skip xero-webhooks.yaml for now
132+
echo "⚠ Skipping $file"
133+
continue
134+
fi
135+
118136
# Run openapi-changes
119137
if [ "$HTML_REPORT" = true ]; then
120138
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"
139+
140+
REPORT_FILE="$REPORTS_DIR/${file%.yaml}-diff.html"
141+
set +e
142+
docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base -v "$(pwd)/$REPORTS_DIR":/reports "$DOCKER_IMAGE" html-report --no-logo --no-color --report-file /reports/"${file%.yaml}-diff.html" /base/"$file" /current/"$file" 2>&1
143+
DOCKER_EXIT=$?
144+
set -e
145+
146+
if [ $DOCKER_EXIT -eq 0 ]; then
147+
echo "✓ HTML report generated: $REPORT_FILE"
148+
else
149+
echo "⚠ Failed to generate HTML report (exit code: $DOCKER_EXIT)"
150+
fi
126151
else
127152
echo "--- API Diff ---"
128153
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)
154+
DIFF_OUTPUT=$(docker run --rm -v "$(pwd)":/current -v "$TEMP_DIR":/base "$DOCKER_IMAGE" summary --markdown --no-logo --no-color /base/"$file" /current/"$file" 2>&1)
130155
DIFF_EXIT=$?
131156
set -e
132157

@@ -155,7 +180,7 @@ if [ "$HTML_REPORT" = true ]; then
155180
echo ""
156181
echo "📊 HTML reports generated:"
157182
if [ -d "reports" ]; then
158-
ls -la reports/
183+
ls -la $REPORTS_DIR
159184
else
160185
echo "No reports directory found"
161186
fi
@@ -170,7 +195,7 @@ elif [ "$BREAKING_CHANGES_FOUND" = true ]; then
170195
fi
171196
done
172197

173-
if [ "$FAIL_ON_BREAKING" = true ]; then
198+
if [ "$FAIL_ON_BREAKING" = true ] && [ "$HTML_REPORT" = false ]; then
174199
echo ""
175200
echo "Exiting with error due to breaking changes"
176201
exit 1

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,36 @@ else
8181
fi
8282
echo
8383

84+
echo "--- Test --dry-run flag ---"
85+
# Test that --dry-run exits early without doing actual work
86+
echo "Testing: --dry-run flag exits early"
87+
output=$("$SCRIPT_PATH" --dry-run 2>&1)
88+
if echo "$output" | grep -q "Dry run mode, exiting after branch check" && ! echo "$output" | grep -q "Starting API diff check"; then
89+
echo " ✓ PASS: --dry-run exits early without starting diff check"
90+
TESTS_PASSED=$((TESTS_PASSED + 1))
91+
else
92+
echo " ✗ FAIL: --dry-run did not exit early, output:"
93+
echo "$output"
94+
TESTS_FAILED=$((TESTS_FAILED + 1))
95+
fi
96+
echo
97+
98+
echo "--- Test --html-report flag parsing ---"
99+
# Test that --html-report flag is parsed correctly (basic parsing test)
100+
echo "Testing: --html-report flag parsing"
101+
# We'll test this by checking that the script doesn't immediately fail with unknown argument
102+
# and that it would proceed to the repo root check (which will fail since we're not in repo root)
103+
output=$("$SCRIPT_PATH" --html-report --dry-run 2>&1)
104+
if echo "$output" | grep -q "Dry run mode, exiting after branch check"; then
105+
echo " ✓ PASS: --html-report flag parsed correctly"
106+
TESTS_PASSED=$((TESTS_PASSED + 1))
107+
else
108+
echo " ✗ FAIL: --html-report flag not parsed correctly, output:"
109+
echo "$output"
110+
TESTS_FAILED=$((TESTS_FAILED + 1))
111+
fi
112+
echo
113+
84114
echo "========================================"
85115
echo "Test Results:"
86116
echo " Passed: $TESTS_PASSED"

xero-webhooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ components:
163163
"lastEventSequence": 1,
164164
"firstEventSequence": 1,
165165
"entropy": "S0m3r4Nd0mt3xt"
166-
}
166+
}

0 commit comments

Comments
 (0)