> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tryardent.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CI / CD

> A fresh database for every PR. Isolated, production-like, torn down after merge.

Every PR can run against its own fresh database branch cloned from your connected source. No shared staging database that drifts out of sync. No test runs that corrupt each other. No production credentials handed to CI.

## Prerequisites

You need:

* An Ardent account with one ready connector. If you do not have one yet, follow the [Quickstart](/quickstart).
* An API token stored as a CI secret named `ARDENT_TOKEN`.
* The project and connector names you want CI to use.

Find project and connector names locally:

```bash theme={null}
ardent project list
ardent connector list
```

## GitHub Actions workflow

Copy this to `.github/workflows/ardent-branch.yml`, replacing `my-project`, `my-connector`, and `npm test` for your repo.

```yaml theme={null}
name: Test with Ardent branch

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      ARDENT_TOKEN: ${{ secrets.ARDENT_TOKEN }}
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "22"

      - name: Install dependencies
        run: npm ci

      - name: Install Ardent CLI
        run: npm install -g ardent-cli

      - name: Select project and connector
        run: |
          ardent project switch my-project
          ardent connector switch my-connector

      - name: Create database branch
        run: |
          BRANCH_NAME="pr-${{ github.event.pull_request.number }}-${{ github.run_id }}"
          DATABASE_URL="$(ardent branch create "$BRANCH_NAME" --print-url)"
          if [ -z "$DATABASE_URL" ]; then
            echo "Ardent did not return a database URL" >&2
            exit 1
          fi
          echo "DATABASE_URL=$DATABASE_URL" >> "$GITHUB_ENV"
          echo "ARDENT_BRANCH=$BRANCH_NAME" >> "$GITHUB_ENV"

      - name: Run tests
        run: npm test

      - name: Delete database branch
        if: always() && env.ARDENT_BRANCH != ''
        run: ardent branch delete "$ARDENT_BRANCH"
```

## Why this shape works

* `ARDENT_TOKEN` authenticates the CLI without writing an interactive login session.
* `ardent project switch` and `ardent connector switch` make the workflow deterministic.
* `ardent branch create --print-url` returns only the connection URL, which is safer and cleaner than scraping human output.
* The branch name includes both PR number and run ID so re-runs and concurrent jobs do not collide.
* Cleanup runs with `if: always()` so failed tests still delete the branch.

## Other CI providers

The pattern is the same everywhere:

```bash theme={null}
npm install -g ardent-cli
ardent project switch my-project
ardent connector switch my-connector
export DATABASE_URL="$(ardent branch create "$CI_BRANCH_NAME" --print-url)"
# run tests
ardent branch delete "$CI_BRANCH_NAME"
```

Store `ARDENT_TOKEN` in your CI provider's secret manager. Do not commit tokens to the repository.

## JSON variant

If your CI step wants more than the URL, use JSON output:

```bash theme={null}
BRANCH_JSON="$(ardent branch create "$BRANCH_NAME" --format json)"
DATABASE_URL="$(node -e 'console.log(JSON.parse(process.argv[1]).branch_url)' "$BRANCH_JSON")"
```

## Compared to shared staging

* **Production-like data:** branches are not schema-only copies.
* **Isolation:** each PR gets its own database.
* **Fast branch creation:** once a connector is ready, branch creation is independent of source database size.
* **Clean teardown:** branches can be deleted after each run and auto-suspend when idle.
