roave/backward-compatibility-check
Checks your PHP library for backward compatibility breaks between git tags/versions. Designed for CI: compares the last SemVer tag to current HEAD, reports API breaks, and exits non-zero on failure. Install via Composer or run in Docker.
Installation:
composer require --dev roave/backward-compatibility-check
Add to require-dev in composer.json for CI-only usage.
First Run:
vendor/bin/roave-backward-compatibility-check
HEAD against the last minor Git tag (e.g., v1.2.0 → v1.3.0).Prerequisites Check:
composer.json has "autoload" sections for all source paths.v1.2.3).fetch-depth: 0).Example GitHub Actions Workflow (.github/workflows/bc-check.yml):
name: BC Check
on: [push, pull_request]
jobs:
bc-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Critical: Fetches all tags
- run: composer install
- run: vendor/bin/roave-backward-compatibility-check
Key Flags for Output:
| Flag | Use Case |
|---|---|
--format=github-actions |
CI annotations (e.g., GitHub PR comments). |
--format=markdown |
Generate changelog-friendly output. |
--baseline=custom-tag |
Compare against a non-last-minor tag. |
Tagging Strategy:
vX.Y.Z (e.g., v1.2.0).v2.0.0).Daily Workflow:
main/develop:
git checkout feature-branch
vendor/bin/roave-backward-compatibility-check --baseline=origin/main
Integration with Tests:
composer.json scripts:
"scripts": {
"test": [
"@phpunit",
"@roave-bc-check"
],
"roave-bc-check": "roave-backward-compatibility-check"
}
composer test in CI.Compare against a specific tag (e.g., v1.5.0):
vendor/bin/roave-backward-compatibility-check --baseline=v1.5.0
Create .roave-backward-compatibility-check.xml:
<roave-bc-check>
<baseline>
<ignored-regex>#\[BC\] CHANGED: Parameter \$param of MyClass\#method\(\)#</ignored-regex>
</baseline>
</roave-bc-check>
Generate JSON for programmatic use:
vendor/bin/roave-backward-compatibility-check --format=json > bc-results.json
Use the official image for zero setup:
steps:
- uses: docker://nyholm/roave-bc-check-ga
False Positives:
symfony/console). Exclude them via:
vendor/bin/roave-backward-compatibility-check --exclude-dir=vendor/
protected → private in a final class is not a BC break (fixed in v8.18.0).Git Tag Issues:
git tag -a v1.0.0 -m "Initial release"
git push --tags
fetch-depth: 0 is mandatory in CI.PHP Version Mismatches:
Verbose Output:
vendor/bin/roave-backward-compatibility-check -v
Dry Run:
vendor/bin/roave-backward-compatibility-check --dry-run
Schema Validation:
.roave-backward-compatibility-check.xml fails, validate against:
vendor/roave/backward-compatibility-check/Resources/schema.xsd
Custom Formatters:
Roave\BackwardCompatibility\Formatter\FormatterInterface.Pre-Commit Hooks:
composer require --dev laravel-pint
composer require --dev roave/backward-compatibility-check
Add to .git/hooks/pre-commit:
#!/bin/sh
vendor/bin/roave-backward-compatibility-check --baseline=HEAD~1
Laravel-Specific Tips:
vendor/bin/roave-backward-compatibility-check --exclude-dir=bootstrap/cache
vendor/bin/roave-backward-compatibility-check --autoload-file=vendor/composer/autoload_psr4.php
Changelog Automation: Pipe output to a script that auto-updates CHANGELOG.md:
vendor/bin/roave-backward-compatibility-check --format=markdown | ./scripts/update-changelog.sh
Team Onboarding:
README.md:
.roave-backward-compatibility-check.xml file in CONTRIBUTING.md.Performance:
- name: Cache BC Check
uses: actions/cache@v3
with:
path: ~/.cache/roave-bc-check
key: ${{ runner.os }}-bc-check-${{ hashFiles('**/composer.lock') }}
How can I help you explore Laravel packages today?