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

> ## Agent Instructions
> To set up Hatchmark for a user, follow https://hatchmark.dev/docs/get-started/agent-setup.md. Inside a Hatchmark project, prefer `hatchmark docs`: it prints the docs of the installed version.

# GitHub Action

> Check and build Hatchmark dashboards on every pull request, with annotations on the lines at fault and a comment showing each changed chart before and after.

The Hatchmark GitHub Action checks and builds your dashboards on every pull request, marks each
problem on the line that causes it, and comments with pictures of up to ten charts the pull request
changes, before and after. Reviewers see what a change does to the numbers without checking out the
branch.

```yaml theme={null}
# .github/workflows/hatchmark.yml
name: Hatchmark

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: write
  pull-requests: write

concurrency:
  group: hatchmark-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  hatchmark:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: hatchmark-dev/hatchmark@v0.1.0
```

That is the whole setup when `hatchmark.yaml` is at the root of the repository. Pin the action to a
release tag, so a new Hatchmark release never changes your checks under you. The action installs
the `hatchmark` package of the same version from npm, so the repository needs no `package.json`.

Keep the `concurrency` block: it cancels the run for an older push when a newer one starts, so one
run at a time writes the comment. The action also checks that its commit is still the pull
request's latest before it publishes anything.

## What it does

1. Runs `hatchmark check`. Each error and warning becomes an annotation on its file and line, so a
   pull request shows it in the diff. Problems in the files the pull request changed come first.
2. Runs `hatchmark build`, which writes the pages to the project's `outDir` as usual, so a later
   step can publish them.
3. On a pull request, builds the base branch's version of the project too, and compares the two
   builds card by card. A chart counts as changed when its card would be drawn differently: its
   numbers, its spec, the row it sits in, the theme, or the project's locale, currency and time
   zone.
4. Renders each changed chart on both sides with `hatchmark render --block`, and posts them side by
   side in one comment. Every later push updates the same comment instead of adding another.

The job fails when check or build finds an error. On a push, the action only checks and builds.

## The comment

The comment starts with the check and build results, then one section per changed chart with the
base version on the left and the pull request's on the right. The right side is the pull request
merged into the base, as GitHub checks it out. A chart the pull request adds shows only its new
version, and removed charts are listed by name. The pictures use the light theme at a 1280 px wide
page, with each dashboard's default filters.

Up to 10 charts are drawn; the comment names the rest. Text blocks are not drawn. When the base
branch's version doesn't build, the comment says so and shows the pull request's charts without
before images.

## Who can see the results

The images are committed to a branch named `hatchmark-renders` in the same repository, which is
why the workflow needs `contents: write`, and the comment links to them by commit. Anyone who can
read the repository can open them, and so can anyone who can read the pull request comment. The
branch only holds images: it never merges and nothing runs on it.

Treat the images like the comment and the job summary: as part of the repository. In a public
repository, check and build sample data in files, never production data. Deleting the branch
removes it from the branch list, but images already committed can stay reachable by their links
for a while, so don't rely on deleting it to take data back.

## Several projects

Give each project its own step. Each one gets its own comment.

```yaml theme={null}
- uses: hatchmark-dev/hatchmark@v0.1.0
  with:
    project: analytics/finance
- uses: hatchmark-dev/hatchmark@v0.1.0
  with:
    project: analytics/product
```

## Inputs

Both are optional.

| Input | Default | Meaning |
| - | - | - |
| `project` | `.` | The directory that holds `hatchmark.yaml`, from the repository root. |
| `github-token` | `${{ github.token }}` | The token that comments and stores the images. |

## Data

The action reads the same sources as `hatchmark build` anywhere else. Files in the repository
just work. For a database or cloud storage source in a private repository, give the step the
environment variables that `hatchmark.yaml` names, from your repository's secrets:

```yaml theme={null}
- uses: hatchmark-dev/hatchmark@v0.1.0
  env:
    SHOP_DATABASE_URL: ${{ secrets.SHOP_DATABASE_URL }}
```

A pull request runs whatever SQL and files its branch contains with those credentials, and its
charts are published as above. So give secrets only to workflows on pull requests from people you
trust with the data, and use a database user that can only read what the dashboards need, as for
[production](/docs/guides/production.md#secrets). Read-only access protects the database, not the numbers the
charts show.

A GitHub-hosted runner reaches only databases open to the internet. For a database inside a private
network, run the job on a [self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners)
in that network, or check pull requests against a sample of the data in files.

## Pull requests from forks

GitHub gives a pull request from a fork a read-only token and no repository secrets. The action
still checks and builds it, so a project whose sources are files works, while one that needs a
database secret fails to build unless it has file samples. It doesn't render, comment or store
images for a fork; the results are in the job summary.

## The browser

Rendering needs Chrome or Chromium. GitHub-hosted Ubuntu runners have Chrome; on a self-hosted
runner without one, the action downloads the Chromium headless shell once, as
`hatchmark render --install-browser` does ([render](/docs/reference/render.md#the-browser)).


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