# GitHub Actions

<div class="view-markdown-wrapper">
<ViewMarkdown />
</div>

Run Shiplight E2E tests on GitHub-hosted runners such as `ubuntu-latest`, and upload the results to [Shiplight Cloud](https://app.shiplight.ai) for trend tracking, flaky-test detection, and team visibility.

::: tip Let your agent wire this up: `/shiplight ci`
The fastest way to author the CI test workflow is to run **`/shiplight ci`** in your coding agent. It generates the workflow and wires the report upload for you, and it sets up failure triage the current way (classification on the server, with an optional autofix workflow). Use this page to understand the test workflow and to configure it by hand when needed.
:::

## Minimal Workflow Example

### On GitHub-hosted runners

In your existing GitHub Actions workflow, make these changes:

Set `SHIPLIGHT_API_TOKEN` (an org token from [app.shiplight.ai/api-tokens](https://app.shiplight.ai/api-tokens)) at the job's **`env` (global) scope**. `shiplight test` uploads its completed report automatically with this token; AI-powered actions also use it through the Shiplight LLM proxy. Deterministic YAML tests don't need it for execution. `shiplight report` likewise uploads by default when regenerating a report. Set `SHIPLIGHT_REPORT_TO_CLOUD=0` to keep reports local.

With the default `auto` cache backend, GitHub Actions sets `CI=true`, so the same token also enables the shared Shiplight Cloud action cache when it has `action-cache:read` and `action-cache:write`. Healed locators from passing tests are persisted for later runs.

```yaml
jobs:
  e2e:
    runs-on: ubuntu-latest
    env: # [!code ++]
      SHIPLIGHT_API_TOKEN: ${{ secrets.SHIPLIGHT_API_TOKEN }} # [!code ++]
    steps:
      # Keep your existing checkout, Node.js 22 setup, dependency-install,
      # and Playwright browser-install steps. Put Bun setup before dependency
      # installation when this project uses Bun.

      - uses: oven-sh/setup-bun@v2 # [!code ++]
        with: # [!code ++]
          bun-version: latest # [!code ++]

      - name: Run E2E tests
        working-directory: tests/e2e
        run: bun run shiplight test # [!code ++]

```

The highlighted lines set up Bun and replace the Playwright test command with Shiplight. The test command uploads its report automatically when the API token is set. Keep your Node.js and Playwright browser setup, and adjust `working-directory` if your tests live somewhere else.

For Shiplight-hosted runners, set `runs-on` to a supported `shiplight-*` size label instead. The Shiplight runner installs the browser and configures credentials for the job; see [CI Runners](/cloud_v2/ci-runners).

Store the token as a repository or organization secret named `SHIPLIGHT_API_TOKEN` — never hardcode it in the workflow file, which is committed to your repo. For non-GitHub providers (GitLab, Jenkins, CircleCI, …), see the [CI/CD overview](/local/ci).

## Upload results

With `SHIPLIGHT_API_TOKEN` set, `shiplight test` uploads test results — including per-step screenshots, videos, and traces — to [Shiplight Cloud](https://app.shiplight.ai). Results appear in the **Test Results** section, linked to your organization.

::: warning
The `shiplight test` command uploads its completed report after the test process exits, including failed test runs. Use `shiplight report` when regenerating or merging a report separately.
:::

### Manage action cache in your own CI

Set `SHIPLIGHT_ACTION_CACHE_BACKEND=local` to use file-backed action cache even when this workflow has a Shiplight API token. Persist `.shiplight/action-cache/` with either:

- [GitHub Actions cache](/local/ci/action-cache#option-1-github-actions-cache): restore before tests and save under a workflow-and-branch key after tests.
- [Automatic Git commits](/local/ci/action-cache#option-2-commit-cache-changes-to-git): checkout restores tracked cache; CI commits changed JSON files and rebases them onto the latest branch, favoring this run when changes conflict.

Both recipes, the backend options, and the logs that confirm actual reuse are in [Action cache in CI](/local/ci/action-cache).

### Sharded runs (GHA matrix)

When using [Playwright sharding](https://playwright.dev/docs/test-sharding) with a GitHub Actions matrix, each shard produces its own report. Use [`shiplight report --merge`](/local/cli-reference#shiplight-report) to combine them into a single upload so the cloud dashboard shows one unified run instead of N separate ones.

## Auto-triage CI failures (optional)

::: warning Legacy setup
This section describes the earlier `ShiplightAI/ci-triage` reusable workflow. Existing pinned callers keep working with their own keys, but new setups should use `/shiplight ci`, which classifies uploaded runs on the server and adds a workflow only for optional autofix.
:::

When an E2E workflow goes red, Shiplight can have an AI agent diagnose the failure and — for fixable spec issues — repair it automatically. The pipeline lives in the reusable workflow [`ShiplightAI/ci-triage`](https://github.com/ShiplightAI/ci-triage). On a failed run it reads the run logs **and** the uploaded report artifacts (screenshots, traces), classifies each failure, and for failures it classifies as fixable spec issues it applies the fix, re-runs the test, and opens a PR. It never auto-merges.

The reusable workflow does **not** post to Slack, Linear, or any other system of yours. It publishes its diagnosis as an artifact; a job you own decides what to notify or file, using your own credentials (Step 3).

::: tip GitHub Actions only
Auto-triage is built on the GitHub `workflow_run` trigger and reusable workflows, so it is available on GitHub Actions only.
:::

Set this up only once a test workflow (from the examples above) exists — triage triggers off that workflow's completion.

### Step 1 — upload the report artifact from the test workflow

Triage reads failure evidence from a GitHub artifact, which is separate from the cloud upload. Add this step to your `e2e.yml`, after the test step:

```yaml
- name: Upload test report (for triage)
  if: ${{ !cancelled() }}
  uses: ShiplightAI/ci-triage/upload-report@v1.1
  # sharded/matrix jobs: give each shard a unique name
  # with:
  #   name: test-report-shard-${{ matrix.shardIndex }}
  #   retention-days: "1"
```

The helper bakes in the `shiplight-report/` path and drops the heavy Playwright traces (`*.zip`) and videos (`*.webm`) the agent never reads (~80% of the artifact size). The cloud upload from `shiplight test` still includes those files for humans.

### Step 2 — add the caller workflow

The `workflow_run` trigger and the per-repo credential mapping **must** live in your repo — a `workflow_run` trigger is illegal inside a reusable workflow, and secret names differ per repo. Everything else lives in the reusable workflow. Create `.github/workflows/ci-failure-triage.yml`:

```yaml
name: CI Failure Triage

on:
  workflow_run:
    workflows: [E2E Tests] # exact `name:` of each test workflow to watch
    types: [completed]

jobs:
  triage:
    uses: ShiplightAI/ci-triage/.github/workflows/triage.yml@v1.1 # pin to a release tag, not @main
    permissions:
      contents: write
      pull-requests: write
      actions: read
    with:
      triage-runner: ubuntu-latest # read-only diagnosis job
      autofix-runner: ubuntu-latest # re-runs tests, so needs browsers/network
      node-version: "22"
      allowed-paths: "tests templates" # top-level dirs the autofix agent may edit (hard guard)
    secrets:
      claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
      openai_api_key: ${{ secrets.OPENAI_API_KEY }} # Codex fallback when Claude is unavailable
      autofix_github_token: ${{ secrets.AUTOFIX_GITHUB_TOKEN }} # PAT/App token to open the PR; falls back to GITHUB_TOKEN
      # Per-repo credential mapping → generic env for the autofix re-run.
      # One KEY=VALUE per line; values must be single-line.
      extra_env: |
        BASE_URL=${{ vars.BASE_URL || 'https://example.com' }}
        MY_TEST_USER_PASSWORD=${{ secrets.MY_TEST_USER_PASSWORD }}
        MY_TEST_USER_2FA_SECRET=${{ secrets.MY_TEST_USER_2FA_SECRET }}
```

Notes:

- `workflows:` must list the exact `name:` of each test workflow to watch. Never list the triage workflow itself there.
- `extra_env` maps your repo's secret names onto the generic env the autofix job uses, so the CLI and MCP browser can authenticate during the re-run. Mirror the `env:` block from your test workflow.
- Provide at least one model credential (`claude_code_oauth_token` or `anthropic_api_key`); `openai_api_key` enables the Codex fallback. `autofix_github_token` is optional.
- `autofix-runner` re-runs the failing test, so it needs browsers and network — install Chromium on the runner the same way your test workflow does.
- These examples assume the Shiplight project lives at the repository root. If it lives in a subdirectory, adjust the report path and add `working-directory` to the relevant steps.

::: warning
The triage job runs privileged — `contents: write` plus live credentials for the autofix re-run. Pin `uses:` to a release tag (`@v1.1`), never a moving branch like `@main`. For an immutable supply-chain pin, use the full commit SHA of the tag with the tag as a comment.
:::

### Step 3 — notify your own system (optional)

Triage publishes its diagnosis as the `triage-context` artifact: `verdict.json` (machine-readable) and `triage.md` (the human-readable write-up). Add a normal job you own to read it and call Slack, Linear, Jira, or anything else — your provider credentials stay in that job and are never visible to the triage agent.

```yaml
publish-triage-incidents:
  needs: triage
  if: ${{ needs.triage.result != 'skipped' }}
  continue-on-error: true # an external system must never block triage or autofix
  runs-on: ubuntu-latest
  permissions:
    actions: read
    contents: read
  steps:
    - uses: actions/download-artifact@v4
      with:
        name: triage-context
        path: /tmp/triage-context
    - name: Publish to your system
      env:
        # Keep provider credentials here, never in `extra_env`.
        SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
        LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
      run: jq '.failures[]' /tmp/triage-context/verdict.json
```

Each entry in `verdict.json`'s `failures[]` has the test path, `classification`, `confidence`, `fixable`, a `fix_summary`, and a stable `dedup_key`. Pick your own policy — notify every failure, or file incidents only for `fixable == false`. For an issue tracker, key on `dedup_key` so a repeated failure updates the existing incident instead of opening a new one on every run.

Each autofix job additionally uploads an `autofix-result-<test>-<index>` artifact with the PR URL, verification status, and whether the fix was skipped. Read those in a later job if you want a separate post-autofix notification.

## Troubleshooting

### Test results not appearing in the dashboard

- Check that `SHIPLIGHT_API_TOKEN` reaches the `shiplight test` step; that command uploads the completed report automatically.
- Check the step logs for errors.

### Playwright can't find a browser

GitHub-hosted runners don't ship Playwright's browsers. Add a step such as `bun run playwright install --with-deps chromium` before the test step.

## Related

- [CI/CD overview](/local/ci) — how the pieces fit together, and other providers
- [CLI Reference](/local/cli-reference) — full `shiplight test`, `shiplight report`, and other command documentation
- [Local Testing](/local/run-locally) — project structure, authentication, and configuration
