Integrations
GitHub Actions
Use the official ContractHQ GitHub Action to automatically validate data contracts on every pull request. Violations block the merge and the built-in PR bot posts a detailed comment explaining what broke and how to fix it.
How It Works
Step 01
đ
PR Opened / Updated
Any PR that modifies a file under contracts/ triggers the workflow.
Step 02
đ
Validate Contracts
The Action diffs changed contracts against your warehouse and runs all checks.
Step 03
đ¤
Bot Comments + Status
Results are posted as a PR comment. Errors set the check to failed.
Step 1 â Add the Repository Secret
Generate a ContractHQ API key with validations:run scope and add it to your GitHub repository:
- Go to Repository â Settings â Secrets and variables â Actions.
- Click New repository secret.
- Name it
CONTRACTHQ_TOKEN. - Paste your API key and save.
Step 2 â Add the Workflow File
Create .github/workflows/contracthq.yml in your repository:
.github/workflows/contracthq.yml
name: Contract Validation
on:
pull_request:
paths:
- 'contracts/**'
jobs:
validate:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # needed for PR bot comments
steps:
- uses: actions/checkout@v4
- name: Validate Data Contracts
uses: contracthq/action@v2
with:
token: ${{ secrets.CONTRACTHQ_TOKEN }}
contracts-path: contracts/
post-comment: true
fail-on-error: trueAction Inputs Reference
| Input | Required | Default | Description |
|---|---|---|---|
| token | Yes | â | ContractHQ API key from repository secrets. |
| contracts-path | No | contracts/ | Path to the contracts directory. |
| post-comment | No | true | Post a summary comment on the PR. |
| fail-on-error | No | true | Fail the workflow step on contract errors. |
| fail-on-warning | No | false | Also fail on severity: warning checks. |
| changed-only | No | true | Only validate contracts changed in the PR. |
Example PR Bot Comment
C
contracthq-botjust nowđ Contract Validation Report
â contracts/user_signups.yml â 3 checks passed
â contracts/orders.yml â 1 error
ERROR: Field
amount changed type from integer to float. This is a breaking change â bump MAJOR version and notify consumers.âšī¸
The PR bot comment is updated (not duplicated) on every new push. You will always see the latest validation results at the top of the comment thread.
Enforcing with Branch Protection
To hard-block merges on contract failures, add the workflow check to your branch protection rules:
- Go to Repository â Settings â Branches.
- Edit the protection rule for
main(ormaster). - Under Require status checks to pass, search for validate.
- Enable Require branches to be up to date and save.
đĄ
Combine with CODEOWNERS to require approval from the data platform team on any file under
contracts/ â ensuring human review alongside automated checks.