Skip to content

PR Checks

In pr-check mode, the action runs on pull requests to detect breaking changes, post diff tables, and generate changesets.


  1. The Action checks out the branch at the latest commit
  2. contractual lint validates every contract
  3. contractual breaking compares each spec against its snapshot
  4. A PR comment is posted with a diff table
  5. A changeset file is generated and committed to the PR branch
  6. If fail-on-breaking: true and breaking changes are found, the check fails

name: Contractual PR Check
on:
pull_request:
paths:
- 'specs/**'
- 'schemas/**'
- 'contractual.yaml'
permissions:
contents: write
pull-requests: write
jobs:
contractual-check:
name: Check contracts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Run Contractual
uses: contractual-dev/action@v1
with:
mode: pr-check
github-token: ${{ secrets.GITHUB_TOKEN }}

InputDescriptionDefault
modeMust be pr-check
github-tokenToken for PR comments and commits${{ github.token }}
config-pathPath to contractual.yaml./contractual.yaml
fail-on-breakingFail if breaking changes detectedtrue
auto-changesetAuto-generate changeset if missingtrue
anthropic-api-keyAnthropic API key for AI explanations

OutputDescription
has-breaking'true' if breaking changes detected
has-changes'true' if any spec changes detected
changeset-created'true' if a changeset was committed

- uses: contractual-dev/action@v1
with:
mode: pr-check
fail-on-breaking: false

Use the output for conditional logic:

- uses: contractual-dev/action@v1
id: check
with:
mode: pr-check
fail-on-breaking: false
- name: Warn on breaking
if: steps.check.outputs.has-breaking == 'true'
run: echo "::warning::Breaking changes detected"
- uses: contractual-dev/action@v1
with:
mode: pr-check
auto-changeset: false

Add the Anthropic API key to get AI-powered change explanations:

- uses: contractual-dev/action@v1
with:
mode: pr-check
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
  1. Go to Settings > Secrets and variables > Actions
  2. Add ANTHROPIC_API_KEY with the key

Use paths filters to run only when relevant files change:

on:
pull_request:
paths:
- 'specs/**'
- 'schemas/**'
- 'contractual.yaml'

For monorepos:

on:
pull_request:
paths:
- 'services/orders/specs/**'
- 'services/orders/contractual.yaml'

GitHub does not allow fork PRs to have write permissions by default. Options:

  1. Use pull_request_target: runs with base branch permissions (use with caution)
  2. Require contributors to create a branch on the upstream repo
  3. Disable auto-changeset for forks:
- uses: contractual-dev/action@v1
with:
mode: pr-check
auto-changeset: ${{ github.event.pull_request.head.repo.fork == false }}