CI contract gate on GitHub
Gate pull requests when an OpenAPI change breaks (or warns against) a published
Apiome project version. The Action wraps apiome diff
(CTG-2.1) and posts one sticky PR comment with the markdown changelog (CTG-2.2).
| CLI exit | Check result | Meaning |
|---|---|---|
0 | pass | No changes at or above --fail-on |
1 | fail | Threshold met (breaking or warn) |
2 | fail (::error::) | Auth, network, parse, or oversize error |
Prerequisites
- A published baseline in Apiome (
project@versionorproject@latest). - Repository secrets:
APIOME_API_KEY— workspace API key (prefer a read-only CI token withdiff:read)APIOME_TENANT_ID— tenant slug or UUID
- Optional repository variable
APIOME_BASE_URL(defaults tohttps://api.apiome.devin the Action).
Copy-paste workflow
Create .github/workflows/apiome-diff.yml:
name: Apiome contract gate
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: apiome/apiome/diff-action@main
with:
spec: openapi.yaml
project: payments-api@latest
fail-on: breaking
api-key: ${{ secrets.APIOME_API_KEY }}
tenant: ${{ secrets.APIOME_TENANT_ID }}
base-url: ${{ vars.APIOME_BASE_URL }}
Replace openapi.yaml and payments-api@latest with your spec path and project.
Sticky PR comment
The Action upserts a single comment marked with <!-- apiome-diff-action -->.
Subsequent pushes to the same PR update that comment in place — they do not spam
new comments. Requires permissions.pull-requests: write.
Set comment: false to skip the comment and only fail/pass the check.
Under each breaking change, the comment says what the change affects in the dependency graph:
- **Path removed** (`ctg.path_removed`) — `/paths/~1pets~1{petId}`
- Blast radius: affects 4 consumers across 2 teams (mobile, payments); 2 verification runs invalidated
Set blast-radius: false to leave that line out. It needs the API key to have projects:view, and it
never changes whether the check passes.
Suggested fixes
The comment also suggests the spec's mechanical lint fixes (GVM-3.4). Below the changelog, a Suggested fixes section lists, per rule, the number of ready fixes, the fix class and the first hunk. A fix that changes one region of the spec, on lines the pull request changes, is also posted as a review comment with a GitHub suggestion block. Accept it with Commit suggestion.
The changelog and the fixes are separate sections of the one sticky comment, so each push updates both in place. The full patch and overlay are written to the workspace for an upload step. Add it after the action:
- uses: apiome/apiome/diff-action@main
id: gate
with:
spec: openapi.yaml
project: payments-api@latest
api-key: ${{ secrets.APIOME_API_KEY }}
tenant: ${{ secrets.APIOME_TENANT_ID }}
- uses: actions/upload-artifact@v7
if: always()
with:
name: apiome-lint-fixes
path: |
${{ steps.gate.outputs.fix-patch-path }}
${{ steps.gate.outputs.fix-overlay-path }}
if-no-files-found: ignore
Set fix-suggestions: false to leave the fixes out. They never change whether the check passes,
and nothing is pushed to the branch. See
Suggested fixes for the details.
Compatibility mode
The gate grades changes by the baseline project's compatibility policy, so it agrees with
POST /v1/diff/{tenant}/classified and with the publish check.
For an Avro, JSON Schema, AsyncAPI or Protobuf baseline, point spec at the schema file and set
the mode for one workflow when you need to:
spec: schemas/order-created.avsc
project: orders-events@latest
mode: full
transitive: "true"
mode takes backward, forward, full or none, transitive takes true or false, and
category takes a Protobuf category (wire, wire_json, package or file). Leave them out to
use the policy. When one applied, the comment ends with what the changes were graded under, such as
_Graded under `FULL_TRANSITIVE` by avro-compatibility, against 2.0.0, 1.0.0._. See
Compatibility modes.
Fail on warnings too
fail-on: warn
warn fails on non-breaking and breaking changes. Docs-only changes alone
never fail the gate.
Not on GitHub?
The same container image backs copy-paste GitLab CI and Bitbucket Pipelines recipes — see CI contract gate on GitLab and Bitbucket.
CLI equivalent
export APIOME_BASE_URL=https://api.apiome.dev
export APIOME_API_KEY=… # from secrets
export APIOME_TENANT_ID=… # from secrets
apiome diff ./openapi.yaml --against payments-api@latest --fail-on breaking --format md --blast-radius
apiome diff ./order-created.avsc --against orders-events@latest --mode full --transitive
apiome lint suggest ./openapi.yaml # the Suggested fixes section
Related
- The action: diff-action
- GitLab / Bitbucket recipes: CI contract gate on GitLab and Bitbucket
- CLI quick-start: CLI quick-start
- Classified diff details:
apiome diff