> For AI agents: the complete documentation index is available at https://docs.hod.sh/llms.txt, the full documentation bundle is available at https://docs.hod.sh/llms-full.txt.

# Events and conditions

## Events

`on:` says which events a forge starts runs for: a list of event names, or a map from names to filters.

```yaml
version: 0
on:
  push:
    branches: [main, "release/*"]
    tags: ["v*"]
  pull_request:
    branches: [main]
jobs:
  test:
    image: alpine:3.22
    steps:
      - run: echo "$HOD_EVENT on $HOD_REF"
```

- **`push`** starts runs for pushes of branches and tags. Without filters, every push. With filters, a branch push needs `branches` to match and a tag needs `tags` to.
- **`pull_request`** starts runs for pull requests, filtered by their base branch. Without filters, every pull request. Pull requests from forks don't run yet.
- Filters are globs on the name, where `*` doesn't cross `/`.

Schedules aren't in the pipeline: they are created on the server (`hod schedule create nightly --cron 'H 3 * * *'`), and every pipeline runs on its project's schedules. Manual runs (`hod run trigger`) and scheduled runs start whatever `on:` says. `hod local run` runs any event you give it, and `hod plan` says whether the forge would have started it.

## Conditions

`if:` on a job or a step is a [CEL](https://cel.dev) expression. Every expression is type-checked when the pipeline compiles, so a typo in a field name is an error from `hod validate`, not a job that silently never runs.

| You want                                              | Write                                                                 |
| ----------------------------------------------------- | --------------------------------------------------------------------- |
| A push to the default branch                          | `event.type == "push" && event.is_default_branch`                     |
| A release tag (`v1.2.0`, not `v1.2.0-rc.1`)           | `has(event.semver) && event.semver.prerelease == ""`                  |
| Any version tag, release candidates too               | `has(event.semver)`                                                   |
| A release of one package in a monorepo (`api/v1.2.0`) | `has(event.semver) && event.semver.prefix == "api/"`                  |
| Files under some paths changed                        | `changed("api/**", "proto/**", "buf.yaml")`                           |
| A pull request into `main`                            | `has(event.pull_request) && event.pull_request.base_branch == "main"` |
| Only on the `nightly` schedule                        | `event.type == "schedule" && event.name == "nightly"`                 |
| Not on schedules                                      | `event.type != "schedule"`                                            |

Quote an expression that starts with `!` or contains `: `, or YAML reads it as something else. Every field of `event`, and the functions you can call, are in [Expressions and values](https://docs.hod.sh/reference/expressions.md).

## Changed files

`changed()` takes up to ten string patterns: `*` stays within a directory, `**` crosses directories, a directory name (`docs`) covers everything under it, and `./src` is the same as `src`. When Hod doesn't know what changed (tags, manual and scheduled runs, `hod local run` without `--changed`), `changed()` is true, so the work runs.

## Named values

`vars:` are named CEL expressions, evaluated once when the run is planned. Other expressions read them as `vars.<name>`. They can read `event` and the vars above them, not `jobs` or `matrix`.

```yaml
version: 0
on: [push]
vars:
  is_release: has(event.semver) && event.semver.prerelease == ""
  channel: 'vars.is_release ? "stable" : "nightly"'
jobs:
  publish:
    if: vars.is_release
    image: alpine:3.22
    env:
      CHANNEL: ${{ vars.channel }}
    steps:
      - run: echo "publishing to $CHANNEL"
```
