# CI

> What the framework's CI runs for a push and a pull request, the debug lane and the full matrix, how to read a red run job by job, the size budget's warnings, and how to wait for a run without polling it.

Source: https://omardev29.github.io/rmp-docs/framework/contributing/ci.html

The framework's CI is one workflow, `.github/workflows/ci.yml`, and the same file every game gets. On the framework it runs everything the ladder runs and more: the platforms that catch most mistakes, beside the framework's own jobs. This page is what it runs, how to ask it for more, how to read it when it is red, and how to wait for it.

[Continuous integration](https://omardev29.github.io/rmp-docs/publishing/ci.html), in Publishing, is the same workflow seen from a game: every target's jobs, what is pinned, and what each platform's red means. This page adds what only the framework runs.

## The paths a run takes

Four things start a run of `ci.yml`, and every run begins with the `config` job, which reads `raylib_multiplatform.toml` once and hands every other job the same answers: the targets, whether this is the full matrix, whether this is the framework or a game, and where `linux-riscv64-glibc` is built. From there a run branches three ways: the checks, which only the framework's repository runs (but `lint`, which a game runs too, and `api`, which only a pull request runs); the platforms, one reusable workflow per family the `.toml` enables, each running what the fast set or the full matrix asks of it; and, on a tag, the release, which waits for every check and platform it needs to be green.

The jobs of `ci.yml` and the conditions that start them. A dashed box runs only in the full matrix, or only on a pull request; the dashed blue arrow is the one fallback.

The one branch that can go two ways is RISC-V. With `[ci] riscv64 = "rise"`, the framework's setting, or `"cloud-v"`, `riscv64-native` builds and starts `linux-riscv64-glibc` natively, in the `raylib-build-riscv64` image, on a RISC-V board: a [RISE](https://riscv-runners.riseproject.dev/) runner, which RISE lends to open-source projects, or a [Cloud-V](https://cloud-v.co/github-riscv-runner) Milk-V Pioneer, for a private repository. A board is the provider's to give, and a job it cannot serve must not cost a release, so that job is the one allowed to fail without failing the run. When it fails, or no board is ever free for it, the `riscv64` job runs instead: the cross build in the amd64 build image, started under QEMU. It ships, and the run's summary says that it fell back. With `"cross"`, what `rmp new` writes in a game, the cross build is the only path. A job with no board waits in GitHub's queue, up to a day, before the fallback starts.

`deep.yml` is the other workflow worth a picture: the search that runs while nobody watches, and the issues it opens.

The nightly and weekly search. Every failure is one `nightly-finding` issue per signature, found again as a comment.

## What a push and a pull request run

A push to `main` and every pull request run the fast lane. A push to any other branch runs nothing by itself: a branch is checked when its pull request is opened, and again on every push to it. On a pull request, what is checked out is the branch merged into `main`, so a green run says the merge works, not only the branch. A change to nothing but Markdown files or `LICENSE` runs nothing.

The fast lane builds Linux x64, Windows x64, the web and Android, and starts the framework's own jobs beside them, all at once, so the run takes as long as its longest job:

| Job | What it runs | On your machine |
|---|---|---|
| `config` | reads the `.toml` and decides what the run builds | `rmp test config` |
| `lint` | every stage of `rmp test` but the properties, which are the `deep` job's: actionlint over the workflows, the pins, every gate, the tests of `configure.py` and of `rmp`, the unit tests, the UI layout and render tests, a game's tests, the software-rendered frame, the formatting and cppcheck | `rmp test` |
| `tidy` | clang-tidy, held to `tools/lint_debt.txt` | `rmp lint` |
| `examples` | every example built, booted and seen to draw; the platformer played by its bot; the smoke boot on a virtual display | `rmp test examples`, its first half |
| `e2e` | every e2e script played, each shot compared with its golden exactly | `rmp test examples`, its second half, in the image |
| `coverage` | what the tests run of `src/rmp/`, against its floors | `rmp test coverage`, in the image |
| `deep` | the unit and layout tests under GCC's sanitizers, the properties at their fixed seeds, every committed fuzz input replayed | `rmp test sanitize`, `rmp test property`, `rmp test fuzz` |
| `docs` | this site's `main`, checked against the commit | [Keeping the docs true](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html) |
| `rmp_new` | a game made with `rmp new` from the commit, and that game's own checks | `./rmp new`, then `rmp test` in the game |
| `linux`, `windows`, `web`, `android` | the fast lane's platforms: built, packaged, started where a runner can start them, and held to their size budget | `rmp build release`, `rmp web`, `rmp android` |

A release of the framework waits for every one of them. In a game the same file skips the framework's own jobs, which test files a game does not have.

## Asking for more: the debug lane and the full matrix

The framework is checked in three sizes of run, and the rule is to use the smallest that answers the question. The fast lane, above, on every push to `main` and every pull request. When it is red, the fix is checked on a **debug lane**: a run started by hand that builds exactly the platforms involved, with every framework job beside them. Linux, Windows and macOS by default; Android or iOS only when the bug is there:

```shell
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macos
gh workflow run ci.yml --ref my-branch -f targets=linux-x64-glibc,windows-x64,macos,android
```

`targets` takes targets and groups, separated by commas, and builds what they come to. A name that is not one, a group the `.toml` switched off, a name given twice or an empty item between two commas stops the run in its first job, naming the item and its position. `--ref` runs the workflow on a branch instead of `main`.

The **full matrix** builds all 17 targets, in about twenty minutes, and runs on every release tag and once when a larger piece of work is done. Its targets are Linux x86-64, Linux ARM64, Linux RISC-V, Linux x86-64 (musl / Alpine), Windows x86-64, Windows ARM64, macOS (universal), iOS (simulator), Web (WebAssembly), Android, FreeBSD x86-64, FreeBSD ARM64, OpenBSD x86-64, OpenBSD ARM64, NetBSD x86-64, Linux DRM/KMS (no X11), Linux ARM64 DRM/KMS (no X11).

```shell
gh workflow run ci.yml -f full=true
```

macOS, iOS and the BSDs build only there, or on a debug lane that names them, and the BSDs build inside virtual machines, on their best effort. A failure on one of them after a green fast lane is a bug of that platform: it is fixed on its own, on a debug lane with that one target, and once fixed such a bug does not tend to come back.

## Reading a red run

Start from the first job that failed: what fails after it may only be its consequence. The `gh` commands that take you there, with `RUN` the run's number from the list:

```shell
gh run list --workflow ci.yml --limit 5
RUN=12345678
gh run view "$RUN"
gh run view "$RUN" --log-failed
```

`--log-failed` prints the log of the failed steps only, which is where the `FAIL` line is: almost every check here ends its failure with one that says what it found. Then reproduce it on your machine with the command in the table above. A job that fails in CI and passes on the laptop is the case for [the image](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#the-image), which is what CI ran it in.

| Red | Where to look |
|---|---|
| `lint` | The failing step's name is the gate or the test that refused; each stage of `rmp test` it runs is a step there, running the same command. |
| `tidy` | The warnings, by file and line, that `tools/lint_debt.txt` does not owe. |
| `examples` | The example that did not build, boot or draw. Its screenshots are the run's `example-screenshots` artifact. |
| `e2e` | A line `E2E FAIL`, the script's line number and the reason. The run's `e2e-pictures` artifact holds, for each shot that differed, the golden, what was drawn and their difference. |
| `coverage` | A file below its floor, or far enough above it that the floor should rise, or a public function no test calls. The report is the `coverage` artifact. |
| `deep` | A sanitizer's report under GCC; a property that failed, with the seed that replays it; or a committed fuzz input that failed again. |
| `docs` | Not red: on anything but a tag it warns, and only a tag fails on it. The step says which page and why. |
| `rmp_new` | What a game made from this commit fails: for instance a file the game needs that the manifest leaves out. |
| A platform | [Reading a red run](https://omardev29.github.io/rmp-docs/publishing/ci.html#reading-a-red-run), in Publishing, goes through every platform's checks. |

```shell
gh run download "$RUN" -n e2e-pictures
gh run rerun "$RUN" --failed
```

The first fetches an artifact to look at. The second runs the failed jobs again; that is for a failure that was not the code's — a runner that died, a service that was down — and never a way to make a flaky test pass.

### The size budget's warnings

A release binary within 1.5 % of its line in `tools/size_budget.txt` passes in silence. Between 1.5 % and 10 % it passes with a warning, which appears on the run's summary page, where a green job's log is never read; past 10 % its job fails. Either way the check printed the line it measured, in the file's own format, and one run's log rewrites every line it measured:

```shell
gh run view "$RUN" --log | python3 tools/size_check.py --update -
```

Commit that with the change that moved the size, and say in the message why it grew. A warning nobody acts on becomes the failure of whoever is next.

## Pushing without killing a run

A new run of a branch or a pull request cancels the run of the same branch or pull request still in progress; a tag's run is never cancelled. That saves minutes on a commit nobody wants any more, and it is how a full matrix of `main` started by hand dies twenty minutes in when someone pushes to `main`.

`rmp push` is `git push` with a question first: it asks `gh` for the last twenty runs of `ci.yml`, on any branch, and while one has not finished it refuses and names it. The first push of a branch also sets its upstream.

```shell
rmp push
rmp push force
```

`rmp push force` pushes anyway. On `main`, use it only when killing the run it named is what you meant. On a branch of your own, a push can only cancel your own pull request's earlier run; the runs `rmp push` names there may be other people's, which the push does not touch, and `force` is the right answer.

## Waiting for a run: never poll it

A fast lane takes minutes and a full matrix about twenty. Do not sit refreshing it, and do not ask somebody else to come back and say whether it finished. A person can hand the waiting to `gh`, which follows the run in the terminal and ends with its result:

```shell
gh run watch "$RUN" --exit-status
```

An agent starts a monitor in the background instead and keeps working: a loop that asks every 45 seconds, prints each job that ends other than green the moment it does, and stops with a summary when the run completes.

```shell
prev=""
while true; do
  s=$(gh run view "$RUN" --json jobs \
        --jq '.jobs[] | select(.conclusion != null and .conclusion != "") | "\(.conclusion)\t\(.name)"' 2>/dev/null || true)
  cur=$(printf '%s\n' "$s" | grep -v '^success' | sort || true)
  comm -13 <(printf '%s\n' "$prev") <(printf '%s\n' "$cur") 2>/dev/null || true
  prev=$cur
  st=$(gh run view "$RUN" --json status --jq .status 2>/dev/null || echo unknown)
  if [ "$st" = "completed" ]; then
    gh run view "$RUN" --json jobs \
      --jq '[.jobs[].conclusion] | group_by(.) | map("\(.[0])=\(length)") | join(" ")'
    break
  fi
  sleep 45
done
```

Each part is there for a reason. It prints every ending that is not a success — failed, cancelled, skipped, timed out — because a monitor that only waits for good news is silent through a crash, and silence looks like still running. `comm -13` prints each job once instead of every 45 seconds. It ends by itself. A `gh` call that fails does not end the watch. And 45 seconds is often enough for jobs that take minutes, and polite to an API with rate limits.

## The workflows that run on their own

`deep.yml`

Every night it fuzzes every target for ten minutes and runs the properties at a random seed; every Sunday it runs mutation testing, a job per module. What it finds becomes an issue labelled `nightly-finding`, one per signature, with the command that replays it. Those issues are taken before anything else: [Pull requests](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html#nightly-findings) says how.

`canary.yml`

Every week, the same build against the versions the framework is not pinned to — the newest image, Xcode, Mesa — to learn what is about to break before a pin has to move. Its failure blocks nothing.

Both run only in the framework's own repository, never in a game.

Next: [pull requests](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html).
