# CI/CD & Pipeline Automations

<p align="center">
  <strong>Automate agent regression testing in pull requests with GitHub Actions, Argo Workflows, Jenkins, and GitLab CI.</strong>
</p>

---

Shipyard's dedicated CI ecosystem (`shipyard-ci`) turns agent evaluation into a deterministic blocking quality gate in continuous integration pipelines.

## GitHub Actions

Drop the composite action into your workflow file (`.github/workflows/agent-gate.yml`):

```yaml
name: Agent Regression Gate

on:
  pull_request:
    branches: [main]

jobs:
  shipyard:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4

      - name: Run Shipyard Gate
        uses: shivamjain/shipyard-ci@v1
        with:
          path: 'evalsets/starter-eval/'
          baseline: 'baselines/main.json'
          repeat: '3'
          policy: '.shipyard/gate.toml'
          junit-file: 'shipyard-junit.xml'
          baseline-artifact: 'main-baseline'
          post-comment: 'true'
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

      - name: Archive Rollout Trajectories
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: shipyard-rollouts
          path: evalsets/starter-eval/rollouts/
```

### Action inputs

| Input | Purpose |
|---|---|
| `path` | Eval or evalset directory to run. |
| `baseline` | Path to the committed baseline to compare against. |
| `repeat` | Repeats for the candidate run (passed through to `--repeat`). Use `3` so the noise margin applies and flakes are visible. |
| `policy` | Gate policy file to overlay for this run (`--policy`). |
| `junit-file` | Name of the JUnit XML file the action writes and surfaces in the test pane. |
| `baseline-artifact` | Artifact name to download a baseline from when it is not in the checkout. This is the baseline-from-artifact fallback for repositories that regenerate the baseline on `main` instead of committing it from PRs. |
| `post-comment` | Update the sticky delta comment with the verdict and per-eval table. |

### What lands on the pull request

- **Sticky delta comment.** One comment per pull request, updated in place
  instead of reposted, with the per-eval delta table (`improved`, `same`,
  `regressed`, `flaked`, `errored`, `skipped`), the score and cost margins,
  and the gate verdict.
- **JUnit in the test pane.** Every eval reports as a test case, so a blocked
  eval shows up as a failing test next to the run without opening the log.
- **Annotations on eval directories.** Blocked evals annotate their eval
  directory in the diff, so the reason lands where the change was made.
- **Job summary.** The same delta table is written to the workflow run summary
  for merge decisions that are made later, not live.
- **Rollout artifacts.** `rollouts/` is uploaded (with `if: always()`), ready
  for post-mortems when the verdict blocks.

### Baseline regeneration (main only)

Treat the baseline like a lockfile. Regenerate it on `main` after merges,
never from a pull request, and fan it out as an artifact for PRs that do not
have it in their checkout:

```yaml
name: Refresh main baseline

on:
  push:
    branches: [main]

jobs:
  baseline:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v4

      - name: Install shipyard
        run: >-
          curl -fsSL https://raw.githubusercontent.com/dock-at-the-yards/shipyard-cli/main/install.sh
          | sh -s -- --channel stable --yes

      - name: Run the suite with repeats
        run: >-
          shipyard run evalsets/starter-eval --repeat 3
          --run-name main-${{ github.sha }}

      - name: Save the baseline
        run: >-
          shipyard baseline save evalsets/starter-eval --name main
          --run-id main-${{ github.sha }}
          --created-by "github-actions[bot]"

      - name: Commit the refreshed baseline
        run: |
          git add evalsets/starter-eval/baselines/main.json
          git diff --cached --quiet || git commit -m "chore: refresh main baseline"
          git push

      - name: Publish the baseline artifact
        uses: actions/upload-artifact@v4
        with:
          name: main-baseline
          path: evalsets/starter-eval/baselines/main.json
```

PR workflows then compare against the committed baseline, or pull
`main-baseline` through the action's `baseline-artifact` fallback when the
branch predates the last refresh.

### Pull request commenter
The candidate is compared to the baseline, not to a pass threshold, so the comment is a delta table:

| Evaluation | Status | Baseline | Candidate | Noise margin |
| :--- | :---: | :---: | :---: | :---: |
| `lookup-order-status` | ✅ same | `0.98` | `0.97` | ±0.08 |
| `apply-discount-code` | ✅ improved | `0.82` | `0.95` | ±0.10 |
| `refund-policy-cap` | ❌ regressed | `1.00` | `0.30` | ±0.11 |

A pass to fail flip, a flake, an infra error, or a score drop beyond both the
2% budget and the noise margin blocks the check. The vocabulary is defined in
[Gate policy](/docs/gate-policy).

---

## Argo Workflows (Kubernetes WFT)

For large-scale, parallel Kubernetes evaluations, `shipyard-ci` provides a native `WorkflowTemplate`:

```bash
kubectl apply -f argo/workflow-template.yaml
kubectl apply -f argo/cron-workflow.yaml
```

The pod installs the CLI from the stable channel at startup
(`install.sh`), so there is no container image to pre-pull.

Run distributed eval matrices with S3/MinIO ATIF artifact storage, repeats,
and the baseline gate:

```bash
argo submit --from wft/shipyard-eval-runner \
  -p eval-path="evalsets/starter-eval" \
  -p agent-name="claude-code" \
  -p baseline="evalsets/starter-eval/baselines/main.json" \
  -p repeat="3"
```

The template runs the suite, uploads the rollout artifacts for every eval, and
runs `shipyard compare` against the baseline; the workflow fails when the gate
blocks, so Argo's own retry and notification machinery applies.

---

## Jenkins Pipelines

### Declarative Pipeline (Docker Agent)

Integrate Shipyard into your Jenkins declarative pipeline using the standard Docker execution agent:

```groovy
pipeline {
    agent {
        docker {
            image 'golang:1.23-bookworm'
            args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
        }
    }
    stages {
        stage('Validate') {
            steps {
                sh 'shipyard validate evalsets/starter-eval/'
            }
        }
        stage('Run Agent Evals') {
            steps {
                sh '''shipyard run evalsets/starter-eval/ --agent claude-code \
                       --repeat 3 --report markdown,json,junit --json > results.json'''
            }
        }
        stage('Gate') {
            steps {
                sh '''shipyard compare evalsets/starter-eval/ \
                       --baseline evalsets/starter-eval/baselines/main.json \
                       --candidate results.json \
                       --policy .shipyard/gate.toml'''
            }
        }
    }
    post {
        always {
            junit 'shipyard-junit.xml'
            archiveArtifacts artifacts: 'evalsets/starter-eval/rollouts/**, results.json, shipyard-report.md', allowEmptyArchive: true
        }
    }
}
```

`junit 'shipyard-junit.xml'` puts every eval into the Jenkins test results, so
a blocked eval is a failed test case rather than a line in a log.

### Groovy Shared Library Step

Alternatively, import the Shipyard shared library step into your pipeline:

```groovy
@Library('shipyard-shared-library') _

pipeline {
    agent any
    stages {
        stage('Eval') {
            steps {
                shipyardEval(
                    evalPath: 'evalsets/starter-eval/',
                    agent: 'claude-code',
                    ci: true,
                    baseline: 'evalsets/starter-eval/baselines/main.json',
                    repeat: 3
                )
            }
        }
    }
}
```

---

## GitLab CI

Drop the Shipyard evaluation stage into your `.gitlab-ci.yml` pipeline with Docker-in-Docker support. The run job produces the reports and the results file; the gate job compares against the committed baseline:

```yaml
stages:
  - test
  - gate

shipyard-agent-eval:
  stage: test
  image: alpine:3.20
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_TLS_CERTDIR: ""
    SHIPYARD_CHANNEL: stable
    EVAL_PATH: "evalsets/starter-eval/"
    AGENT: "claude-code"
  before_script:
    - apk add --no-cache bash curl ca-certificates
    - >-
      curl -fsSL https://raw.githubusercontent.com/dock-at-the-yards/shipyard-cli/main/install.sh
      | sh -s -- --channel "$SHIPYARD_CHANNEL" ${SHIPYARD_VERSION:+--version "$SHIPYARD_VERSION"} --yes
    - shipyard version
  script:
    - shipyard validate "$EVAL_PATH"
    - >-
      shipyard run "$EVAL_PATH" --agent "$AGENT" --repeat 3
      --report markdown,json,junit --json > results.json
  artifacts:
    when: always
    reports:
      junit: shipyard-junit.xml
    paths:
      - results.json
      - shipyard-report.md
      - shipyard-report.json
      - shipyard-junit.xml
      - $EVAL_PATH/rollouts/
    expire_in: 14 days

shipyard-gate:
  stage: gate
  image: alpine:3.20
  needs: ["shipyard-agent-eval"]
  variables:
    EVAL_PATH: "evalsets/starter-eval/"
  before_script:
    - apk add --no-cache bash curl ca-certificates
    - >-
      curl -fsSL https://raw.githubusercontent.com/dock-at-the-yards/shipyard-cli/main/install.sh
      | sh -s -- --channel stable --yes
  script:
    - >-
      shipyard compare "$EVAL_PATH"
      --baseline "$EVAL_PATH/baselines/main.json"
      --candidate results.json
      --policy .shipyard/gate.toml
```

The `reports: junit` artifact feeds GitLab's test tab, and the gate job exits
`1` when compare blocks, which fails the pipeline stage.

---

## Release Channels & Version Pinning

Every CI/CD integration accepts a release channel so your delivery pipeline can track a moving target during development or pin to an exact immutable version in production:

| Channel | Tracks | Recommended For |
| :--- | :--- | :--- |
| `stable` (default) | Latest non-prerelease | Production blocking gates |
| `dev` | Latest development build | Debugging the harness itself |

### Pinning Versions Across Platforms

| Platform | Channel Configuration | Version Pinning |
| :--- | :--- | :--- |
| **GitHub Actions** | `channel: 'stable'` | `version: 'v0.0.2'` |
| **GitLab CI** | `SHIPYARD_CHANNEL: "stable"` | `SHIPYARD_VERSION: "v0.0.2"` |
| **Jenkins** | `CHANNEL` parameter | `VERSION` parameter |
| **Groovy Shared Library** | `channel: 'stable'` | `version: 'v0.0.2'` |
| **Argo Workflows** | `install.sh --channel` at pod start | `install.sh --version` |

---

## Trajectory Rollout Artifacts

Every CI run captures complete **Agent Trajectory Interchange Format (ATIF)** logs saved under `<eval-path>/rollouts/<run-id>/`:

- **Step-by-step tool invocations**: bash commands, code edits, web requests, and environment stdout/stderr, plus the conversation transcript for rubric assertions.
- **Performance metrics and usage**: model latency, token consumption when the harness reports it, total elapsed time, and turn counts.
- **Provenance**: `run.json` records the engine/CLI commits, resolved command, model, environment, `config_hash`, and `suite_digest` behind the numbers.
- **Aggregates**: `aggregate.json` holds `k`, `pass@k`, `pass^k`, mean, sigma, flakes, and per-repeat records; `results.json` is what the gate job consumes.
- **Rubric breakdown**: individual criteria pass/fail results and numerical scores, including infra and rubric failures labeled as such.

With `--repeat 3` the per-repeat files live in `repeat-1/` ... `repeat-3/`
subdirectories at the run root. The file-by-file reference is
[Rollouts & ATIF](/docs/rollouts-and-atif); how the gate rules use them is
[Gate policy](/docs/gate-policy).
