This directory contains scripts for detecting and reporting API changes using openapi-changes.
Main script that compares OpenAPI specifications against the master branch.
Usage:
# From the repo root
./scripts/api-diff/api-diff.sh [--fail-on-breaking] [--html-report] [filename.yaml]
# Check all xero*.yaml files
./scripts/api-diff/api-diff.sh
# Check a single file
./scripts/api-diff/api-diff.sh xero_accounting.yaml
# Fail on breaking changes (CI mode)
./scripts/api-diff/api-diff.sh --fail-on-breaking
# Generate HTML reports
./scripts/api-diff/api-diff.sh --html-reportEnvironment Variables:
OPENAPI_CHANGES_DOCKER_IMAGE- Docker image to use (default:pb33f/openapi-changes:latest)BASE_BRANCH- Branch to compare against (default:origin/master)
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:
Compare current branch against a different target branch:
# Compare against origin/develop
BASE_BRANCH=origin/develop ./scripts/api-diff/api-diff.sh
# Compare against origin/main
BASE_BRANCH=origin/main ./scripts/api-diff/api-diff.sh
# Compare against a feature branch
BASE_BRANCH=origin/feature/new-api ./scripts/api-diff/api-diff.sh
# Compare specific file against different branch
BASE_BRANCH=origin/v2-api ./scripts/api-diff/api-diff.sh xero-webhooks.yamlCompare two specific branches (advanced usage): If you need to compare two arbitrary branches, you can temporarily switch to one branch and set BASE_BRANCH to the other:
# Compare feature-branch against develop
git checkout feature-branch
BASE_BRANCH=origin/develop ./scripts/api-diff/api-diff.sh
# Compare main against a tag
git checkout main
BASE_BRANCH=v1.0.0 ./scripts/api-diff/api-diff.shUnit tests for the branch logic pattern matching used in GitHub Actions.
Usage:
./scripts/api-diff/api-diff.test.shTests validate that:
- Branches containing
breakinganywhere in the name are correctly identified - Other branches are handled with breaking change enforcement
- All command-line flags (
--fail-on-breaking,--allow-breaking,--dry-run,--html-report) are parsed correctly - Flag precedence and override behavior works as expected
These scripts are integrated into the GitHub Actions workflow at .github/workflows/api-diff.yml:
- test-branch-logic job - Runs unit tests
- api-diff job - Runs API diff checks with conditional breaking change enforcement
- html-reports job - Generates HTML reports and uploads them as artifacts
The GitHub Actions workflow automatically adjusts its behavior based on branch names:
Allow Breaking Changes:
- Any branch containing
breakingin the name - Examples:
breaking-api-v2,feature-breaking-change,api-breaking-update - The
--fail-on-breakingflag is NOT passed to the script
Fail on Breaking Changes:
- All other branches (main, master, develop, feature branches, etc.)
- The
--fail-on-breakingflag IS passed to the script - Build will fail if breaking changes are detected
This allows developers to explicitly signal when they're working on breaking changes by including breaking in their branch name.