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

# CI runners

> [//]: # (smoke: not executed, a CI job needs a GitHub App installation on the caller's repository)

Run GitHub Actions jobs on Styne microVMs by naming a runner label. Each job gets its own VM, runs exactly one job and the VM is
destroyed afterwards. The dashboard's CI tab lists every job with its queue time, run time and cost.

## Set it up

1. Open the [CI tab](https://app.styne.ai/ci/github) in the dashboard and choose **Install the GitHub App**. Pick the account and
   the repositories that should use Styne runners.
2. Back in the dashboard, choose **Sign in with GitHub**. GitHub confirms that the installation is yours and the account is linked.
3. Change the label of a job:

```yaml theme={"theme":"css-variables"}
jobs:
  test:
    runs-on: tr-1x8
```

Push. The job appears in the CI tab as soon as GitHub queues it.

## Labels

A label is `tr-<vcpu>x<gib>`: the vCPU count and the memory in GiB. Five labels exist.

| Label | vCPU | Memory | Jobs at once |
| - | - | - | - |
| `tr-1x8` | 1 | 8 GiB | 16 |
| `tr-2x4` | 2 | 4 GiB | 16 |
| `tr-4x8` | 4 | 8 GiB | 12 |
| `tr-8x16` | 8 | 16 GiB | 8 |
| `tr-16x32` | 16 | 32 GiB | 4 |

A job that names any other `tr-` label is not picked up and waits in GitHub's queue.

## What a job runs on

An Ubuntu 24.04 microVM of the size in the label and a 32 GB root disk, running the GitHub Actions runner as the `runner` user (with
`sudo`). The image has git, curl, jq, Node 18, Python 3.12, PowerShell 7, Rust and Docker with Buildx. Your workflow installs
everything else the usual way, with `actions/setup-go`, `actions/setup-node` and the like.

The Docker daemon starts by itself when the job starts (about a second), so `docker build`, `docker run` and `docker compose` work in the
first step without `sudo dockerd &`; the `runner` user is in the `docker` group. Docker server 29.9.3, Buildx 0.38.2. Nothing is cached
between jobs: every job starts from the same clean image.

## Billing

A job is billed per second, from the moment GitHub assigns it to a runner until the job ends, as a VM of its size at the rates in
[Billing](https://docs.styne.ai/billing.md). Runners that are started in advance and wait for a job are not billed to you.

An account that is held by the [no-credit stop](https://docs.styne.ai/billing.md#when-an-account-has-no-credit) gets no new CI jobs: its jobs stay queued
in GitHub, and start again within a minute of credit coming back. A job that is already running is not stopped.

## Limits

* The number of jobs that run at the same time is limited per label, as in the table above. Further jobs wait in GitHub's queue and start when a runner frees up.
* A job is stopped by GitHub after 6 hours at most.
* Removing an installation in the CI tab stops new jobs from starting on Styne runners. The GitHub App stays installed on GitHub until
  you remove it there.

## Security

A job is customer code, so a runner is isolated like any other Styne VM: its own kernel, no access to the host or to other VMs, and
the same network limits as a sandbox. A runner takes its job's credentials once, at start, and the VM is destroyed when the job ends:
nothing from one job is visible to the next. The GitHub App asks only for the permissions it needs to register runners, read job status and start the
workflows you start with `POST /ci/jobs`.

## Start and read jobs from the API

Jobs are listed in the dashboard's CI tab, and the API reads and starts them with your API key. Every call sees only the jobs of
your account: another account's job id answers `404`.

`POST /ci/jobs` runs a workflow of a repository your GitHub App installation covers. The workflow needs an
`on: workflow_dispatch` trigger, and its jobs name a `tr-` label, so they run on Styne runners:

```bash theme={"theme":"css-variables"}
curl -X POST https://api.styne.ai/ci/jobs \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"repo": "acme/app", "workflow": "test.yml", "ref": "main", "inputs": {"suite": "unit"}}'
```

The answer is `201` with the job, `status` `queued`. `ref` is `main` when left out; `inputs` are the workflow's
`workflow_dispatch` inputs (`env` is accepted as the same). A request the job cannot start from is refused with the reason:

| Status | `code` | When |
| - | - | - |
| `400` | `bad_request` | `repo` is not `owner/name`, `workflow` is not a workflow file name, or an input name or value is malformed |
| `409` | `ci_not_linked` | no GitHub App installation linked to your account covers the repository |
| `404` | `workflow_not_found` | GitHub has no such workflow on that ref, or the App cannot see the repository |
| `422` | `workflow_refused` | GitHub refused the start, for example a workflow without `workflow_dispatch` or an input it does not declare |
| `403` | `github_permission` | GitHub refused the App on the repository; accept the App's updated permissions in the installation settings on GitHub |

`GET /ci/jobs/{id}` reads one job from queue to finish, and `GET /ci/jobs` lists your jobs, newest first (`limit`, 50 by
default, at most 1000). Jobs GitHub starts on its own (a push, a pull request) are listed as well, with ids of their own. A job
carries:

| Field | Meaning |
| - | - |
| `id` | `ci_...`; a job started with `POST /ci/jobs` keeps the id that call answered |
| `repo`, `workflow`, `ref`, `name`, `run_id`, `event` | where the job comes from; `run_id` is GitHub's workflow run |
| `status` | `queued`, `running`, `succeeded`, `failed` or `cancelled` |
| `runner`, `vcpu`, `memory_mb` | the label the job ran on and its size |
| `created_at`, `queued_at`, `started_at`, `finished_at` | RFC 3339 times; `started_at` is when GitHub gave the job to a runner |
| `queue_ms` | the wait for a runner, from GitHub's queue to the start (to now while it waits) |
| `duration_ms` | the time on the runner, to now while it runs |
| `cost_usd` | that time billed at the runner's size, as in [Billing](https://docs.styne.ai/billing.md) |
| `steps` | on `GET /ci/jobs/{id}` once the job ran: each step's `number`, `name`, `status` and times |

`GET /ci/jobs/{id}/steps` reads the steps alone, `GET /ci/jobs/{id}/logs` sends the job's log as server-sent events (one
event per line, from line `from`), and `GET /ci/queue` lists the jobs still waiting for a runner.

## Operations

| Method | Path | What it does |
| - | - | - |
| `POST` | `/ci/jobs` | Queue a CI job on a runner |
| `GET` | `/ci/jobs/{id}` | Read a CI job from queue to finish |
| `GET` | `/ci/jobs` | List the account's CI jobs, newest first |
| `GET` | `/ci/jobs/{id}/steps` | Read a CI job's steps with their timings |
| `GET` | `/ci/jobs/{id}/logs` | Read a CI job's log as server-sent events |
| `GET` | `/ci/queue` | Read the account's CI jobs waiting for a runner |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.