A GitHub Action that detects breaking API changes in Go code and comments on pull requests. This action uses the official golang.org/x/exp/cmd/apidiff
tool to analyze API compatibility.
- 🔍 Automatically detects breaking API changes in pull requests
- 💬 Comments on PRs with detailed change reports
- ✅ Identifies both breaking and compatible changes
- 🚫 Can fail CI builds when breaking changes are detected
- 📊 Provides summary statistics in action outputs
Add this action to your workflow:
name: API Compatibility Check
on:
pull_request:
types: [opened, synchronize]
jobs:
apidiff:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # Required for commenting on PRs
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to access base commit
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- uses: imjasonh/apidiff-action@v1
with:
fail-on-breaking: true
Input | Description | Default |
---|---|---|
working-directory |
Directory to run apidiff in | . |
fail-on-breaking |
Whether to fail the action if breaking changes are detected | true |
comment-on-pr |
Whether to comment on the PR with results | true |
token |
GitHub token for commenting on PRs | ${{ github.token }} |
Output | Description |
---|---|
has-breaking-changes |
Whether breaking changes were detected (true /false ) |
breaking-count |
Number of breaking changes found |
compatible-count |
Number of compatible changes found |
The action will comment on your PR with a formatted report:
Type Count Breaking changes 1 Compatible changes 3
⚠️ This PR contains breaking API changes!
- (*Client).DoSomething: changed from func(string) error to func(context.Context, string) error
- NewOption: added
- WithTimeout: added
- DefaultTimeout: added
Example in action: #3
To get notified about breaking changes without failing the build:
- uses: imjasonh/apidiff-action@v1
with:
fail-on-breaking: false
To check a specific package or module:
- uses: imjasonh/apidiff-action@v1
with:
working-directory: ./api
- uses: imjasonh/apidiff-action@v1
id: apidiff
with:
fail-on-breaking: false
- name: Handle breaking changes
if: steps.apidiff.outputs.has-breaking-changes == 'true'
run: |
echo "Found ${{ steps.apidiff.outputs.breaking-count }} breaking changes"
# Add custom handling here
This action:
- Installs the official
apidiff
tool fromgolang.org/x/exp/cmd/apidiff
- Runs it to compare the base and head commits of your PR
- Parses the output to identify breaking and compatible changes
- Creates or updates a comment on the PR with the results
- Optionally fails the build if breaking changes are detected
The underlying apidiff
tool implements the compatibility rules from the Go 1 compatibility guarantee, checking for changes that would cause client code to stop compiling.
This action is available under the Apache License 2.0.