# CI and Sypnia Run

> A push builds a preview, a merge can deploy, and any CI can report its checks.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://git.docs.sypnia.com/automation/ci-and-run/

For agents: Built in with Sypnia Run: on push to a branch with a pull request, Run builds a preview and posts status sypnia-run/preview with its URL; on merge to the default branch, Run deploys (production deploys follow Run's approval rules). Configured in sypnia.toml (the [run] table). External CI: subscribe to push/pull_request webhooks, report results with POST /v1/repos/{owner}/{repo}/statuses/{sha} (state, context, target_url). Required checks are set in branch rules.

## With Sypnia Run

Link a repository to a Run project once (in `sypnia.toml` or in the repository's settings). Then:

| When                                   | Run does             | You see                                                                                                |
| -------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------ |
| a branch with a pull request is pushed | builds a **preview** | a check `sypnia-run/preview` with the preview's address                                                |
| a pull request is merged into `main`   | **deploys**          | the deploy in the pull request; production follows [Run's approval rules](https://run.docs.sypnia.com) |

## With any other CI

Subscribe it to `push` and `pull_request` [webhooks](https://git.docs.sypnia.com/automation/webhooks) and report back with the status API:

```bash
curl -X POST https://git.api.sypnia.com/v1/repos/laespiga/web/statuses/$SHA \
  -H "Authorization: Bearer $SYPNIA_GIT_TOKEN" \
  -d '{"state":"success","context":"ci/tests","target_url":"https://ci.example.com/run/42"}'
```

## The contract check

With the repository linked to a map in [Sypnia Cases](https://cases.docs.sypnia.com/), Cases runs [`cases check`](https://cases.docs.sypnia.com/contract/the-check/) on every push to a pull request and posts the check `sypnia-cases/check`, with its findings as notes on the lines: code that does what no case says, a case that is not built, code that disagrees with its case. Make it required on `main`, and nothing off the map is merged, by people or by agents.

Any check can be made **required** in the [branch rules](https://git.docs.sypnia.com/repos/branches-and-protection).
