|
| 1 | +# Contractual GitHub Action |
| 2 | + |
| 3 | +Schema contract lifecycle management for GitHub — lint, detect breaking changes, auto-generate changesets, and version contracts. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```yaml |
| 8 | +- uses: contractual-dev/action@v1 |
| 9 | + with: |
| 10 | + mode: pr-check |
| 11 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 12 | +``` |
| 13 | +
|
| 14 | +## Modes |
| 15 | +
|
| 16 | +### `pr-check` |
| 17 | + |
| 18 | +Runs on pull requests. Detects breaking changes, posts a PR comment with a diff table, and auto-commits a changeset. |
| 19 | + |
| 20 | +```yaml |
| 21 | +name: Contract Check |
| 22 | +
|
| 23 | +on: |
| 24 | + pull_request: |
| 25 | + paths: |
| 26 | + - 'specs/**' |
| 27 | + - 'schemas/**' |
| 28 | +
|
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + pull-requests: write |
| 32 | +
|
| 33 | +jobs: |
| 34 | + check: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + ref: ${{ github.head_ref }} |
| 41 | +
|
| 42 | + - uses: contractual-dev/action@v1 |
| 43 | + with: |
| 44 | + mode: pr-check |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | +``` |
| 47 | + |
| 48 | +### `release` |
| 49 | + |
| 50 | +Runs on push to main. Consumes changesets and opens a "Version Contracts" PR. |
| 51 | + |
| 52 | +```yaml |
| 53 | +name: Version Contracts |
| 54 | +
|
| 55 | +on: |
| 56 | + push: |
| 57 | + branches: [main] |
| 58 | + paths: |
| 59 | + - '.contractual/changesets/**' |
| 60 | +
|
| 61 | +permissions: |
| 62 | + contents: write |
| 63 | + pull-requests: write |
| 64 | +
|
| 65 | +jobs: |
| 66 | + release: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | +
|
| 73 | + - uses: contractual-dev/action@v1 |
| 74 | + with: |
| 75 | + mode: release |
| 76 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | +``` |
| 78 | + |
| 79 | +## Inputs |
| 80 | + |
| 81 | +| Input | Required | Default | Description | |
| 82 | +|-------|----------|---------|-------------| |
| 83 | +| `mode` | Yes | — | `pr-check` or `release` | |
| 84 | +| `github-token` | No | `${{ github.token }}` | Token for PR comments and commits | |
| 85 | +| `fail-on-breaking` | No | `true` | Fail if breaking changes detected | |
| 86 | +| `auto-changeset` | No | `true` | Auto-generate changeset if missing | |
| 87 | +| `version-pr-title` | No | `Version Contracts` | Title of the Version PR | |
| 88 | +| `version-pr-branch` | No | `contractual/version-contracts` | Branch for the Version PR | |
| 89 | +| `anthropic-api-key` | No | — | Anthropic API key for AI features | |
| 90 | + |
| 91 | +## Outputs |
| 92 | + |
| 93 | +| Output | Mode | Description | |
| 94 | +|--------|------|-------------| |
| 95 | +| `has-breaking` | `pr-check` | `'true'` if breaking changes detected | |
| 96 | +| `has-changes` | `pr-check` | `'true'` if any spec changes detected | |
| 97 | +| `changeset-created` | `pr-check` | `'true'` if a changeset was committed | |
| 98 | +| `version-pr-url` | `release` | URL of the Version Contracts PR | |
| 99 | + |
| 100 | +## Permissions |
| 101 | + |
| 102 | +```yaml |
| 103 | +permissions: |
| 104 | + contents: write # Commit changesets and version bumps |
| 105 | + pull-requests: write # Post PR comments and create Version PR |
| 106 | +``` |
| 107 | + |
| 108 | +## Documentation |
| 109 | + |
| 110 | +Full documentation at [contractual.dev](https://contractual.dev) |
| 111 | + |
| 112 | +## License |
| 113 | + |
| 114 | +MIT |
0 commit comments