# AutoGovern deployment gate for CI/CD

Add one step to your pipeline. Before a deployment runs, it asks AutoGovern
whether the AI system may be deployed. If it may not, the step fails and the
deployment stops. Every check is recorded in AutoGovern, with the branch and
commit, so you have a record of which deployments were checked and what the
answer was.

## What is checked

| Check | Fails when |
| --- | --- |
| Approved for production | The system has not been approved under Workbench → AI Registry → the system → Intake & approval. |
| Model card in the repository | The pipeline found no model card (`MODEL_CARD.md`, `model_card.md`, `MODEL_CARD.json`, `model-card.md`, `docs/MODEL_CARD.md` or `docs/model_card.md`, or the path you set). |
| No high-risk change awaiting a decision | A high-risk change request for the system is still waiting for a decision. |
| No deployment hold | The Remediation Center or autopilot has put a deployment hold on the system. |
| Change gate | The system's change gate fails **and** your organization enforces its change gate. If it does not enforce it, a failing change gate is shown as a warning and does not stop the deployment. |

If AutoGovern cannot be reached, the step fails: a gate that cannot be
checked counts as failed. To let a deployment continue anyway, change your
pipeline (for example `continue-on-error: true` in GitHub Actions or
`allow_failure: true` in GitLab), knowing the deployment was not checked.

## Before you start

1. **Get the system ID.** Open Workbench → AI Registry and copy the system's
   ID (it starts with `ws_`).
2. **Issue an API key.** Open Account → Administration → API access & audit →
   Governance API keys and select **Issue a new key**. An owner or admin can
   issue keys. Keys issued before the gate was added lack the `gate:read`
   scope (the gate answers `403 forbidden_scope`): issue a new one. The key
   stops working if it is revoked or if the person who issued it leaves the
   organization.
3. **Store the key as a secret** in your CI system. Never commit it.

## GitHub Actions

1. Download [action.yml](https://autogovern.io/download/ci/github-action) and
   [autogovern-gate.sh](https://autogovern.io/download/ci/script) into
   `.github/actions/autogovern-gate/` in your repository.
2. Add the secret: Settings → Secrets and variables → Actions → New
   repository secret, named `AUTOGOVERN_API_KEY`.
3. Add the gate before your deploy step:

```yaml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4   # pin to a commit SHA if your policy requires it
      - uses: ./.github/actions/autogovern-gate
        with:
          system-id: ws_abc123
          api-key: ${{ secrets.AUTOGOVERN_API_KEY }}
          # model-card: docs/model-card.md   # if yours has another name
      - run: ./deploy.sh
```

The checkout step must come first: the gate looks for the model card in the
checked-out repository.

## GitLab CI/CD

1. Download [autogovern-gate.gitlab-ci.yml](https://autogovern.io/download/ci/gitlab)
   and [autogovern-gate.sh](https://autogovern.io/download/ci/script) into
   `ci/` in your repository.
2. Add the variable: Settings → CI/CD → Variables → Add variable, key
   `AUTOGOVERN_API_KEY`, with **Mask variable** and **Protect variable**
   selected.
3. Include the template and add a gate stage before deploy:

```yaml
include:
  - local: ci/autogovern-gate.gitlab-ci.yml

stages: [build, gate, deploy]

autogovern_gate:
  extends: .autogovern_gate
  stage: gate
  variables:
    AUTOGOVERN_SYSTEM_ID: ws_abc123
```

The template uses the `alpine:3.20` image and installs curl if it is missing.
Set `image:` in your job to use your own image instead; it needs `sh` and
`curl`.

## Any other CI system

Run `autogovern-gate.sh` with `sh`. It needs `sh` and `curl`, and reads:

| Variable | Required | Meaning |
| --- | --- | --- |
| `AUTOGOVERN_API_KEY` | yes | The API key, from a secret. |
| `AUTOGOVERN_SYSTEM_ID` | yes | The system ID (`ws_...`). |
| `AUTOGOVERN_URL` | no | Default `https://autogovern.io`. Must be HTTPS. |
| `AUTOGOVERN_MODEL_CARD` | no | Path to the model card. |
| `AUTOGOVERN_REF`, `AUTOGOVERN_COMMIT` | no | Branch and commit to record. GitHub and GitLab values are used if these are not set. |

Exit codes: `0` passed, `1` failed or AutoGovern could not be reached, `2` a
setting is missing or wrong.

## Calling the API yourself

```
GET https://autogovern.io/api/v1/gate/ws_abc123?model_card=present&ref=main&commit=<sha>
Authorization: Bearer <key with gate:read>
```

The answer is JSON:

```json
{
  "system": { "id": "ws_abc123", "name": "Claims triage", "approval_status": "approved_for_production" },
  "pass": false,
  "checks": [
    { "key": "approval", "label": "Approved for production", "status": "pass", "detail": "Approved through Intake & approval." },
    { "key": "model_card", "label": "Model card in the repository", "status": "pass", "detail": "The pipeline found a model card." },
    { "key": "changes", "label": "No high-risk change awaiting a decision", "status": "fail", "detail": "1 high-risk change request(s) awaiting a decision: Swap the base model." },
    { "key": "hold", "label": "No deployment hold", "status": "pass", "detail": "No hold." },
    { "key": "change_gate", "label": "Change gate", "status": "warn", "detail": "Failing: ... (a warning: your organization does not enforce its change gate)." }
  ],
  "ref": "main", "commit": "<sha>", "check_id": "cig_42", "evaluated_at": "2026-11-21T10:00:00.000Z"
}
```

Add `format=text` for plain lines suited to a CI log. The first line is
`AutoGovern deployment gate: PASS` or `AutoGovern deployment gate: FAIL`.

Errors: `401` no valid key; `403` the key lacks `gate:read`, or is not an
organization key whose issuer still belongs to the organization; `404` the
system is not one of your organization's systems; `429` too many calls (120
a minute); `500` treat as failed.
