# CI runner — GitHub-hosted

Read this only for a stock GitHub-hosted runner.

## Requirements

- Create an organization API token at `$SHIPLIGHT_WEB_URL/api-tokens`.
  `npx shiplight setup-api-token` configures a personal token for local use;
  do not use it as a shared CI credential.
- Store it as a repository or organization secret named
  `SHIPLIGHT_API_TOKEN`.
- Store the backend's API URL as a repository or organization variable named
  `SHIPLIGHT_API_URL`, and its web app URL as `SHIPLIGHT_WEB_URL`. There is no
  default host: with the token but no `SHIPLIGHT_API_URL`, `npx shiplight`
  exits 2.
- Put `SHIPLIGHT_API_TOKEN`, `SHIPLIGHT_API_URL` and `SHIPLIGHT_WEB_URL` at job
  `env` scope because every `npx shiplight` command needs them.
- Set `SHIPLIGHT_REPORT_TO_CLOUD=1` on the report step.
- Use `shiplightai` 0.1.103 or later. If the hosted service returns a 401
  saying the token is unknown, create a new organization token on that
  service and replace the CI secret.
- On the hosted service, uploads are paid from the organization's credit. A 402
  reply (`no_credit` or `no_plan`) on the report step means the plan is inactive
  or out of credit; its message links to the billing page.
- Install Chromium and its operating-system dependencies before running tests.

Use `assets/e2e-github-hosted.yml` as the root-project baseline. Merge it into
an existing workflow when one exists. Adapt the Node version, package-manager
install command, triggers, and test command to the repository's established
choices; do not introduce a second package manager.

For a project in a subdirectory, prefer `working-directory` on each Shiplight
`run:` step when merging into an existing job. Use job-level
`defaults.run.working-directory` only when every existing `run:` step belongs to
that project. Defaults affect only `run:` steps, not actions invoked with
`uses:`. Keep `actions/checkout` at repository root.

The finished job must retain:

- `npx playwright install --with-deps chromium` before the test run;
- `npx shiplight test` or the repository's equivalent Shiplight test script;
- `npx shiplight report` with `if: always()` and
  `SHIPLIGHT_REPORT_TO_CLOUD=1`.

## Bun projects

In a Bun project (`../_shared/package-manager.md`), use
`assets/e2e-github-hosted-bun.yml` instead. It sets up Bun with
`oven-sh/setup-bun` at the version in `package.json`'s `packageManager`, has no
Node setup step, and installs with `bun install --frozen-lockfile`, so the job
needs the committed Bun lockfile. `bun-version-file` must name the
`package.json` that holds the `packageManager` field the manager rule found, as a
path from the repository root: the test project's own, or a parent's such as the
repository root's. Only when no folder has the field (a project found by its
lockfile alone), record `"packageManager": "bun@<version>"` in the test project's
`package.json` first, with the version `bun --version` prints, as the manager
rule says, and point `bun-version-file` at that file. The requirements above
hold with the Bun forms: `bun run --bun shiplight setup-api-token` is the personal
token command, and `bun run --bun shiplight` exits 2 without `SHIPLIGHT_API_URL`.
The finished job must retain:

- `bun run --bun playwright install --with-deps chromium` (the browser-install row
  of the manager rule) before the test run;
- `bun run --bun shiplight test`, not `bun run test`: the project's `test`
  script may be another runner, or an old `shiplight test` that runs on Node;
- `bun run --bun shiplight report` with `if: always()` and
  `SHIPLIGHT_REPORT_TO_CLOUD=1`.
