# Quick start

> Write a first herald.toml and the workflow that runs it, store its secrets, and send one test message.

## Write the first file

Run `herald init` in your repository. From a few answers it writes a first `herald.toml` and the workflow that runs it. It asks the forge and the repository (read from the `origin` remote where it can), the chat and the way into it, the presets to announce with, and where Herald runs.

```sh
herald init
```

Each question is also a flag: `--forge`, `--repository`, `--api`, `--chat`, `--variant`, `--with <key>=<value>`, `--announce` (once per preset), `--store-token`, `--runs`, `--action`, `--runs-on` and `--host`. `--yes` takes the default of every question no flag answers and writes without asking. `--print` prints every file and writes none.

`herald init` never writes over a config or a workflow that exists. `herald setup` adds to a config you already have, and `herald doctor` judges it. Announcing some other way today? `herald import` writes a config from what announces now: the GitHub app in Slack or Teams, a forge's chat webhooks, or a workflow's announcing steps.

## The workflow

On GitHub, `herald init` writes `.github/workflows/herald.yml`, and on Forgejo `.forgejo/workflows/herald.yml`. It runs Herald's Action on every published release, with read access to the repository's contents only, one run at a time, and each secret the config names passed from the forge's own secret of that name.

`--action` pins the Action to a commit of `nightworksio/herald`, by its full 40-character id. A release build of Herald pins its own commit where `--action` is absent. On GitLab, `herald init` writes no job; `--runs none` writes the config alone.

## Store the secrets

The config names each secret and holds no secret's value. After writing, `herald init` says for each secret where the forge keeps it and how to make it.

Where Herald keeps what it sent depends on the way into your chat:

- A way in that reads its posts back, such as a bot, keeps "sent once" in the posts themselves: the `markers` store, which needs nothing more.
- A webhook can't read its posts back. On GitHub, Herald then keeps its records in the Actions cache; on Forgejo and GitLab, on the repository's `herald-state` branch. Each is sealed with `HERALD_STORE_KEY`, a key `herald init` makes and prints once. Store it before you close the window.

## Send a test message

Once the config is written, `herald init` shows the test message and asks whether to post it. It is posted once, on the config's first route: a message that says it is a test and announces nothing. With `--yes`, or later, the same test is:

```sh
herald doctor --online --post
```

Without `--post`, `herald doctor --online` asks each destination, with nothing posted, whether it takes its credential and grants what each route needs.

## An example: Herald's own file

Herald announces its own releases and pre-releases into the NightWorksIO Discord's `package-releases` announcement channel, with this `herald.toml`:

```toml
#:schema https://raw.githubusercontent.com/nightworksio/herald/main/herald.schema.json
version = 1

[store]
kind = "markers"

[markers]
key = { secret = "HERALD_MARKER_SECRET" }

[destinations.discord]
kind = "discord"
token = { secret = "HERALD_DISCORD_TOKEN" }

[sources.herald]
kind = "github"
repository = "nightworksio/herald"

[[routes]]
id = "herald-releases"
sources = ["herald"]
kinds = ["release"]
destination = "discord"
channel = "1566184281406177531"
template = "package-release"
crosspost = true
thread = { name = "{{ event.project }} {{ event.attributes.version }}", archive_after = "14d" }
pin = "markers"

[templates.package-release]
title = "📦 {{ event.project }} {{ event.attributes.version }}{% if event.attributes.prerelease %} · pre-release{% endif %}"
body = "{{ event.body }}"
```

And this workflow, `.github/workflows/announce.yml`, with the Action pinned by commit:

```yaml
on:
  release:
    types: [published]

permissions:
  contents: read

concurrency:
  group: herald

jobs:
  announce:
    runs-on: ubuntu-latest
    environment: announce
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - uses: nightworksio/herald@<commit-sha>
        env:
          HERALD_DISCORD_TOKEN: ${{ secrets.HERALD_DISCORD_TOKEN }}
          HERALD_MARKER_SECRET: ${{ secrets.HERALD_MARKER_SECRET }}
```

The `markers` store keeps Herald's never-twice ledger in the posts it makes, so the run writes nothing to the repository. It has no compare-and-set, so the `concurrency` group keeps to one Herald run at a time. `herald token marker` prints a new `HERALD_MARKER_SECRET`, once.

## Next

Every key `herald.toml` takes is listed, with its type and what it sets, in the settings reference in Herald's repository (`.docs/settings.md`), generated from the schema.
