# GitHub Actions

On GitHub Actions, a readerly command prints the `text` report without color or prompts, and writes workflow commands on stderr so the pull request marks the lines. `createOut` does this when it detects the runner. You call nothing.

## Detection

`detect()` reads `GITHUB_ACTIONS` from the environment and returns `reader: "ci"` with `ci: { name: "github-actions" }`. The runner sets the variable on every job. A `CI` set to `0`, `false`, `no` or `off` turns CI detection off, see the [CI table](https://readerly.loadsheet.dev/guide/readers).

The profile for that run, from `resolveProfile` with no flags:

| Field | Value | `profile.why` |
| --- | --- | --- |
| `format` | `text` | `detected ci (CI:github-actions)` |
| `color` | `false` | `stdout is not a TTY` |
| `interactive` | `false` | `reader is ci` |
| `budget` | `Infinity` | `no budget for ci on text` |
| `annotations` | `"github"` | |

`profile.annotations` is `"github"` only when the reader is `ci`, the provider is `github-actions` and the format is `text`. `--format json`, `--format jsonl` and `--json` turn annotations off. Annotations are a side channel next to `text`, not a [format](https://readerly.loadsheet.dev/guide/formats).

## What the runner prints

The `acme check` example from [`test/golden/check.ts`](https://github.com/loadsheet/readerly/blob/main/test/golden/check.ts) exits `1`. On stdout, GitHub Actions gets:

```text
✖ 2 errors, 1 warning in 212 files (0.8s)

error ACME001  src/app.ts:14:3  Route handler reads process.env at module scope
├▶ why: The value is fixed at build time
╰▶ fix: Read it inside the handler
error ACME004  src/db.ts:3:1  Top-level await in a server entry
╰▶ fix: Move the call into the plugin setup
warn  ACME010  vite.config.ts:8:5  Alias shadows a workspace package

next: acme check --fix   (applies 2 safe fixes)
next: acme explain <code>   (explains one code)
```

The command asks "Apply 2 safe fixes?" at a terminal. In CI nobody can answer, so `out.confirm` takes its default and adds the `next: acme check --fix` line instead. The row cap is off in CI, so every finding prints.

On stderr, GitHub Actions gets:

```text
::error title=ACME001,file=src/app.ts,line=14,col=3::Route handler reads process.env at module scope
::error title=ACME004,file=src/db.ts,line=3,col=1::Top-level await in a server entry
::warning title=ACME010,file=vite.config.ts,line=8,col=5::Alias shadows a workspace package
```

Annotations go to stderr so `acme check > report.txt` keeps the file free of workflow commands, and the runner still reads them.

## githubAnnotations

The `text` renderer calls `githubAnnotations` from `readerly/github`. A [custom renderer](https://readerly.loadsheet.dev/guide/renderers) or another tool can call it too. It takes `DiagnosticRecord`s and a cap, `10` by default, returns one line per annotation, and prints nothing itself:

```ts [annotate.ts]
import type { DiagnosticRecord } from "readerly";
import { githubAnnotations } from "readerly/github";

const records: DiagnosticRecord[] = [
  {
    severity: "error",
    code: "ACME020",
    message: "Port 3000:3001 is taken, 100% of the time",
    docs: "https://acme.dev/codes/ACME020",
    file: "src/a,b.ts",
    line: 2,
    column: 7,
  },
  { severity: "warn", message: "No file, so no annotation" },
  { severity: "info", message: "Infos never get one", file: "src/app.ts" },
];

process.stderr.write(githubAnnotations(records));
```

It writes one line:

```text
::error title=ACME020,file=src/a%2Cb.ts,line=2,col=7::Port 3000:3001 is taken, 100%25 of the time%0Ahttps://acme.dev/codes/ACME020
```

- Errors become `::error` and warnings `::warning`. Infos and records without a `file` are skipped and don't use up the cap.
- The cap counts each kind on its own, in input order: at most 10 errors and 10 warnings.
- `title` is the `code`, then come `file`, `line` and `col`. A range on one line adds `endLine` and `endColumn`. A range over several lines gives `line` and `endLine` only.
- `docs` goes on a second line of the message.
- Messages escape `%`, `\r` and `\n`. Property values also escape `:` and `,`.

## A workflow step

A readerly CLI needs no flag on the runner:

```yaml [.github/workflows/check.yml]
name: check
on: [push, pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 24
      - run: npm ci
      - run: npx acme check
```

The step fails when `acme check` exits `1`, and the pull request shows each annotation on its line.

## Coding agents in CI

An agent that runs on a runner reads the output, so it gets the `agent` format. `AI_AGENT` and strong markers such as `CLAUDECODE` win over CI. Weak markers never do. With `AI_AGENT=claude-code` and `GITHUB_ACTIONS=true`, `acme check` prints the same compact report an agent gets on a laptop, byte for byte, and nothing on stderr. Annotations need `text`. See [coding agents](https://readerly.loadsheet.dev/guide/agents) for the markers.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://readerly.loadsheet.dev/raw/integrations.md)
- [GitHub Actions](https://readerly.loadsheet.dev/raw/integrations/github-actions.md) (this page)
- [Argument parsers](https://readerly.loadsheet.dev/raw/integrations/argument-parsers.md)
- [Testing your CLI](https://readerly.loadsheet.dev/raw/integrations/testing.md)
- [Progress](https://readerly.loadsheet.dev/raw/integrations/progress.md)
- [Markdown answers](https://readerly.loadsheet.dev/raw/integrations/markdown-answers.md)
- [nostics](https://readerly.loadsheet.dev/raw/integrations/nostics.md)

Next: [Argument parsers](https://readerly.loadsheet.dev/raw/integrations/argument-parsers.md)

All pages: [llms.txt](https://readerly.loadsheet.dev/llms.txt)
