URL: https://docs.xeonr.io/docs/branchd/pipelines/reference
Every page of the section, with worked examples: https://docs.xeonr.io/docs/branchd/pipelines/llms-full.txt
JSON Schema of a pipeline file: https://docs.xeonr.io/schemas/branchd/pipeline.json
Docs index: https://docs.xeonr.io/docs/branchd/pipelines

# Pipeline file reference

The complete reference for .branchd/pipelines/*.yaml on one page, with every key, what it takes, what is refused, the job token, superseding, other repositories and presets. Also served as Markdown at /docs/branchd/pipelines/reference.md.



> **Available** in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its `.forge-ci.yaml` or `.xeonr-ci.yaml`. See [What is available](/docs/branchd/pipelines#what-is-available).

This page is the whole language on one page, and is served as Markdown at
[`/docs/branchd/pipelines/reference.md`](/docs/branchd/pipelines/reference.md)
for agents. [Expressions](/docs/branchd/pipelines/expressions),
[Step files](/docs/branchd/pipelines/step-files),
[Limits](/docs/branchd/pipelines/limits) and
[Refusals](/docs/branchd/pipelines/errors) go into more detail. The
[JSON Schema](/schemas/branchd/pipeline.json) is generated from the same key
tables as the compiler. The compiler is `xeonr/forge/ci` v1.20.0.

## Files [#files]

* Each file in `.branchd/pipelines/` ending in `.yaml` is one pipeline. A file
  ending in `.yml` is refused.
* Each file is compiled on its own; a refused file does not stop the others.
* A repository with `.branchd/pipelines/` and an older CI file (such as
  `.xeonr-ci.yaml`) beside it is refused.
* YAML anchors and aliases (`&x`, `*x`, `<<: *x`) work.
* A repository that branchd has not switched to pipeline files ignores
  `.branchd/pipelines/` and runs its old files.
* One commit holds at most 50 pipeline files.

## Check names [#check-names]

Each job reports a check on the commit, `<pipeline> / <job>`, the job as the
file names it:

| Job                                        | Check                                                                                                        |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
| a job                                      | `CI / build`                                                                                                 |
| a matrix cell                              | `CI / test (1.26, linux)`, `CI / cell (1, x)`                                                                |
| a job of a called pipeline                 | `CI / deploy / plan`                                                                                         |
| a preset's job                             | `CI / preset.apps.api.build`                                                                                 |
| an isolated step's earlier parts           | `CI / build [1/2]`; the last part is `CI / build`                                                            |
| any job of the pipeline named exactly `ci` | `build`, without `ci / `, as the old files' checks were; but `ci / lib / prep` when the job's name holds `/` |

A branch rule's required check is written the same way, and keeps matching
while the file names the job the same.

## Push checks [#push-checks]

A push that changes `.branchd/pipelines/`, `.branchd/steps/` or
`.branchd/packages.yaml` is checked before it is accepted: each changed
pipeline file is compiled for the push's own run (or its pull request's)
and for **every event its `on:` lists**, with branch, tag, path, schedule
and `from:` filters treated as matching (a push to a branch and of a tag, a
pull request, each schedule up to three, manual and trigger with each
input's default, and for `on: call` a job of this repository calling it).

* A file the push breaks refuses the push, with `file:line:column: message`
  lines. A file that failed the same way at the branch's previous tip is a
  warning, so a revert or an old branch can always be pushed. Only the tip
  of each pushed branch is judged.
* Only what a file itself gets wrong refuses (syntax, unknown keys,
  expressions, limits, needs cycles, steps of this repository that do not
  exist). What depends on another repository is a warning.
* The check fails open: if it cannot run in time, the push goes through with
  a line saying so.
* `git push -o ci.allow-invalid` lets a broken file through, for those who
  may bypass the branch's rules; the push is recorded as bypassed.
* `branchd ci lint` (0.39.0 and later) runs the same every-event check
  locally.

## Top-level keys [#top-level-keys]

| Key            | Takes                                                | Meaning                                                                                                                                                                                                                                                                                                                                                                        |
| -------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`         | string                                               | The pipeline's name, 1 to 64 characters, no `/`. Default: the file name without `.yaml`. Unique in the repository. Checks are named `<name> / <job>`.                                                                                                                                                                                                                          |
| `on`           | event, list, or map                                  | When it runs. Required. See [on](#on).                                                                                                                                                                                                                                                                                                                                         |
| `env`          | map                                                  | Environment for every job. May read `inputs.*`.                                                                                                                                                                                                                                                                                                                                |
| `defaults`     | `{image, runs-on}`                                   | The `image` and `runs-on` of jobs that set neither.                                                                                                                                                                                                                                                                                                                            |
| `max-parallel` |                                                      | **Refused for now**: branchd cannot yet limit how many jobs of a run run at once.                                                                                                                                                                                                                                                                                              |
| `concurrency`  | `{group, cancel-in-progress}`                        | With `group`, the repository's runs in the group never overlap: a newer run waits for the older, or cancels it with `cancel-in-progress: true` (GitHub's concurrency group). Without `group`, `true` lets a newer run cancel this pipeline's runs on a protected branch too, and `false` stops newer runs cancelling or queueing behind them. See [Superseding](#superseding). |
| `permissions`  | map                                                  | What the job token may do, for every job that does not set its own. See [The job token](#the-job-token).                                                                                                                                                                                                                                                                       |
| `preset`       | `{uses, with, secrets, allow, runs-on, permissions}` | The jobs of a preset of another repository. See [Presets](#presets).                                                                                                                                                                                                                                                                                                           |
| `jobs`         | map of ids to jobs                                   | Required, at least one, unless the file has a preset. See [Job keys](#job-keys).                                                                                                                                                                                                                                                                                               |

`on` is required unless the file has a preset, whose default triggers it
then narrows.

**Refused:** `max-parallel`; and
the GitLab CI keys `stages`, `variables` (use `env`), `default` (use
`defaults`), `workflow` (use `on`), `include` (use `uses`) and `schedules`
(use `on: schedule`).

## on [#on]

`on:` is an event (`on: push`), a list (`on: [push, pull_request]`), or a map
of events to their keys. A run is for one event. A file whose `on:` does not
match the event has no run, and `branchd ci plan` says why.

| Event          | Keys                           | Runs when                                                                                                                                                        |
| -------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `push`         | `branches`, `tags`, `paths`    | A push of a branch or a tag. With only `branches`, tags never run it; with only `tags`, branches never do; with neither, both do. `paths` is not read for a tag. |
| `pull_request` | `paths`                        | A pull request's run, for each new head.                                                                                                                         |
| `schedule`     | list of `{cron, name, ref}`    | A scheduled run of one of the file's schedules.                                                                                                                  |
| `manual`       | `inputs`                       | A person starts this pipeline.                                                                                                                                   |
| `trigger`      | `from` (required), `inputs`    | Another repository's `trigger:` job starts it.                                                                                                                   |
| `call`         | `inputs`, `secrets`, `outputs` | Never on its own: a job's `uses:` brings this file's jobs into its run. See [Reusable pipelines](/docs/branchd/pipelines/reusable-pipelines).                    |

* **`branches`, `tags`, `paths`** are a glob or a list of globs. `*` matches
  within one path segment, `**` across segments; `?`, `[…]` and `{a,b}`
  work. A leading `!` excludes, and the last pattern that matches decides.
  `paths` holds when any changed path matches. A new branch, a tag, or a push
  with more changes than branchd lists counts as everything changed.
* **`schedule`**: `cron` (required) is five fields in UTC, firing at most
  every five minutes. `name` is letters, digits, `.`, `_` and `-`, at most
  64, unique in the repository; default `<file name>-<n>`. `ref` is a
  branch; empty is the default branch. At most 10 a file and 50 a
  repository. branchd keeps the schedules in line with the files on the
  **default branch**; each fire runs the file on `ref` at its newest commit.
* **`trigger.from`**: `organisation` (any repository), `company` (repositories
  of teams the same company owns as this repository's), or a list of
  repository paths. It is read from the default branch's file. A repository
  triggering its own pipeline must list itself.
* **The merge queue.** A merge-queue commit is a `push` to its target for
  `on:` alone, so `on: push: branches: [main]` runs on it. Its jobs see the
  queue's ref: `branch` is empty, `protected` false, `merge_queue` true, so a
  deploy gated on `branch == 'main'` is left out of it.
* **`inputs`** (under `manual`, `trigger` and `call`) map names to
  `{type, options, default, required, description}`:

  * `type`: `string` (default), `boolean`, `number` or `choice`;
  * `options`: the values of a `choice`, which needs them (and only a
    `choice` takes them);
  * `default`: the value when none is given;
  * `required`: a value must be given when there is no default;
  * `description`: for people.

  A run's inputs are checked against the types before it starts. An input
  the file does not declare is refused. On any other event an input reads
  its default, else `''`, `false` or `0`. A name declared under both
  `manual` and `trigger` must have one type. Two input names that differ
  only in case, `-` and `_` are refused.
* **`call.secrets`** map names to `{required, description}`.
  **`call.outputs`** map names to `${{ jobs.<id>.outputs.<name> }}`, or
  `{value, description}`.

## Job keys [#job-keys]

A job id is letters, digits, `_` and `-`, starting with a letter or `_`. Ids
starting with `preset.` are reserved. Two ids that differ only in `-` and
`_` are refused.

| Key                       | Takes                                                         | Meaning                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `steps`                   | list of steps                                                 | The job's steps. Required unless the job has `uses` or `trigger`. See [Step keys](#step-keys).                                                                                                                                                                                                                                                                                                             |
| `uses`                    | string                                                        | Instead of `steps`: call a reusable pipeline, `./<path>.yaml` or `<group>/<repo>/<path>.yaml@<version>`. See [Calling jobs](#calling-jobs).                                                                                                                                                                                                                                                                |
| `with`                    | map                                                           | The called pipeline's inputs. Only with `uses`.                                                                                                                                                                                                                                                                                                                                                            |
| `allow`                   | list: `environment`, `trigger`                                | Only with `uses` of another repository: what it may choose for this run. See [Consent](#consent).                                                                                                                                                                                                                                                                                                          |
| `needs`                   | id, list of ids, or `{job, optional, artifacts}`              | The jobs this one waits for, which must succeed. `optional: true`: the need is dropped when that job does not run for this event, and is an ordinary need when it does. `artifacts: false`: wait without downloading its artifacts. A need on a matrix job waits for each of its cells. A need on a job that does not run is refused unless optional. Needs name jobs of the same file only.               |
| `if`                      | expression                                                    | False leaves the job out, with the reason. Decided when the run is compiled. It may use `always()` (run even after a failed need) and `success()`, not `failure()`. It may not read outputs.                                                                                                                                                                                                               |
| `matrix`                  | map                                                           | One job per combination. See [matrix](#matrix).                                                                                                                                                                                                                                                                                                                                                            |
| `trigger`                 | map                                                           | Start a run of another repository's pipeline. See [trigger](#trigger).                                                                                                                                                                                                                                                                                                                                     |
| `image`                   | string                                                        | The container image the job's `run:` steps run in. Required for a `run:` job, here or under `defaults`. A whole `${{ needs.<job>.outputs.<name> }}` of a typed step's job runs in an image built earlier in the run.                                                                                                                                                                                       |
| `runs-on`                 | string or list                                                | Runner labels. The label `deploy` is reserved for branchd's own deploy steps.                                                                                                                                                                                                                                                                                                                              |
| `services`                | map of aliases                                                | Containers beside the job: an image, or `{image, env, command, entrypoint, ports}`. The alias is the service's host name.                                                                                                                                                                                                                                                                                  |
| `env`                     | map                                                           | Environment for the job's steps.                                                                                                                                                                                                                                                                                                                                                                           |
| `outputs`                 | map                                                           | Values the jobs that need this one read as `${{ needs.<job>.outputs.<name> }}`. Each is one line. A matrix job has none.                                                                                                                                                                                                                                                                                   |
| `artifacts`               | list of paths, or `{paths, when, expire-in}`                  | Files kept after the job and placed in each job that needs it. `when`: `success` (default), `failure` or `always`. A path that is, holds or could match `.branchd/run/` (`.`, `*`, `**`, `.branchd`) is refused.                                                                                                                                                                                           |
| `cache`                   | `{key, files, paths, policy, when, fallback-keys}`, or a list | `paths` (required) are kept between runs. `files` keys the cache on those files' contents, with `key` as the prefix. `policy`: `pull-push` (default), `pull` or `push`. `when`: `success` (default) or `always`. `fallback-keys` are tried when `key` has none.                                                                                                                                            |
| `secrets`                 | list of names, or map of names to `{type, target}`            | The secrets granted, as environment variables. `target` renames the variable; `type` is `env` (default) or `file` (a file secret; its path arrives in `target`). A listed secret set nowhere fails the job's attempt; a step's optional secret is skipped instead.                                                                                                                                         |
| `checkout`                | `false`, or `{depth, tags, submodules}`                       | The checkout is automatic and needs nothing in the image, not even git. `depth` defaults to 50; `0` is the whole history. `tags: true` fetches tags. `submodules: true` checks out the submodules, `recursive` theirs too; a submodule must be readable without a credential (public, or internal on branchd), since the job token reads this repository only. `false` leaves the working directory empty. |
| `repository-code-secrets` | boolean                                                       | Allows typed steps that execute repository code to receive secrets whose policy permits the step package. Anyone who can change that code can access those secrets.                                                                                                                                                                                                                                        |
| `permissions`             | map                                                           | What the job's token may do; replaces the file's. See [The job token](#the-job-token).                                                                                                                                                                                                                                                                                                                     |
| `environment`             | name, or `{name, url}`                                        | Record a deployment to this environment.                                                                                                                                                                                                                                                                                                                                                                   |
| `concurrency`             | lock name, or `{group, cancel-in-progress}`                   | `group`: one job holding the lock runs at a time in the repository; others queue. `cancel-in-progress: true`: a newer run may stop this job part-way; `false`: never. Unset, the run's default decides ([Superseding](#superseding)).                                                                                                                                                                      |
| `manual`                  | `true`, or `{wait, on-expiry, blocking}`                      | The job waits for a person to release it. `wait`: how long (`24h`); `on-expiry`: `fail` or `skip`; `blocking: false`: the run may finish without it.                                                                                                                                                                                                                                                       |
| `timeout`                 | duration                                                      | How long the job may run: `10m`, `1h30m`, `1 hour`.                                                                                                                                                                                                                                                                                                                                                        |
| `resources`               | `{cpu, memory}`                                               | What the job's step asks for: `cpu` in cores (`2`, `0.5`) or millicores (`500m`), `memory` as `8Gi` or `512Mi`. Only a runner pool whose job sizes hold the request takes the job; one no pool can hold fails `no_worker`. A host job takes none.                                                                                                                                                          |
| `host`                    | `true`                                                        | The job's steps run in the shell of a runner's own machine, with no image or container.                                                                                                                                                                                                                                                                                                                    |
| `retry`                   | number, or `{max, when}`                                      | Retry a failed job up to `max` times (0 to 10). `when` lists failure kinds: `always`, `script_failure`, `stuck_or_timeout_failure`, `job_execution_timeout`, `runner_system_failure`, `unmet_prerequisites`, `missing_dependency_failure`, `api_failure`, `scheduler_failure`, `unknown_failure`, `data_integrity_failure`, `downstream_failure`.                                                          |
| `continue-on-error`       | `true`, or `{exit-codes: […]}`                                | The job may fail and the run goes on; with `exit-codes`, only for those codes.                                                                                                                                                                                                                                                                                                                             |

**Refused:** the GitLab CI job keys, each with its
replacement: `script` (`steps`), `before_script` (the first steps),
`after_script` (a last step with `if: always()`), `stage` (`needs`), `rules`
and `when` (`if`, or `manual: true`), `variables` (`env`), `allow_failure`
(`continue-on-error`), `resource_group` and `lock` (`concurrency`), `tags`
(`runs-on`), `parallel` (`matrix`), `extends` (`uses`, or YAML anchors),
`interruptible` (`concurrency: {cancel-in-progress: true}`) and
`module_token`.

## Step keys [#step-keys]

| Key                 | Takes                     | Meaning                                                                                                                                                                         |
| ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                | id                        | Names the step in its job; its outputs are `steps.<id>.outputs.<name>`. Unique in the job.                                                                                      |
| `name`              | string                    | What the log shows.                                                                                                                                                             |
| `run`               | string                    | Shell commands. A step has `run` or `uses`.                                                                                                                                     |
| `uses`              | string                    | A composite step, `./<name>` (`.branchd/steps/<name>/step.yaml`) or `<group>/<repo>/<path>@<version>`; or a typed step, `ci/<name>@<version>`, as the job's only step.          |
| `with`              | map                       | The inputs of what `uses` names.                                                                                                                                                |
| `if`                | expression                | `always()`, `failure()`, `success()`, and anything decided when the run is compiled. Without a status function it holds only while no step has failed. It may not read outputs. |
| `env`               | map                       | Added to the job's environment for this step.                                                                                                                                   |
| `working-directory` | path                      | Where the step runs, relative to the workspace and inside it.                                                                                                                   |
| `shell`             | `bash` or `sh`            | Run the step in that shell. Unset: the job's shell.                                                                                                                             |
| `timeout`           | duration                  | The step fails when it runs longer.                                                                                                                                             |
| `continue-on-error` | boolean                   | The job goes on if the step fails.                                                                                                                                              |
| `isolated`          | boolean                   | `true` runs the step as a node of its own, a part of the job. Required for a typed step among other steps. See [Isolated steps](#isolated-steps).                               |
| `workspace`         | `all`, or a list of paths | On an isolated step: what it receives from the steps before it, and hands back. Left out, the checkout only.                                                                    |

**How steps run.**

* A job's `run:` steps share one shell, bash when the image has it, else sh,
  with `set -e` (and `-o pipefail` under bash). A `cd` or an `export` in one
  step is seen by the next.
* A step with `env`, `working-directory`, `shell`, `timeout` or
  `continue-on-error` runs in a subshell of its own: its changes do not reach
  later steps. `shell` and `timeout` start a new shell, which sees exported
  variables only.
* When a step fails, the steps after it with `if: always()` or
  `if: failure()` still run, each in a subshell, and the job fails with the
  first failure's exit code. When the job is cancelled, its `if: always()`
  and `if: cancelled()` steps run after the cancel, in a fresh shell
  ([Cancelled jobs](/docs/branchd/pipelines/expressions#cancelled-jobs)).
* In a job with such a step, a step that sets or clears the shell's EXIT trap
  is refused. Set it inside a subshell, `( trap 'rm -f x' EXIT; make )`, or
  give the step a `shell:` of its own.
* A step writes outputs as `name=value` lines to `$BRANCHD_OUTPUT`.

**A typed step**, `uses: ci/<name>@<version>`, is a step that branchd
provides, run in its own image. As its job's only step it takes `id`,
`name`, `uses`, `with`, `env`, `timeout` and `continue-on-error`, its job
takes no `image` or `checkout`, and its `if:` goes on the job. Among other
steps it must be `isolated: true`, and also takes `if`, `isolated` and
`workspace`. `@1` or `@1.0` is the newest version with that prefix; `@1.0.1`
is exact. Its job's `outputs:` pass its outputs on, and they reach a
dependant's `image:` and `with:`.

**A step published by a product**, `uses: strata/migrate@1`, is a typed
step that the product publishes from its own repository and versions with
its own releases. The name resolves only through branchd's binding of the
namespace (`strata`) to the one repository that may publish into it
(`xeonr/strata/cli`), set by branchd and never by a pipeline file or the
product's repository: the step is the `step.yaml` in `steps/migrate` there,
at the newest `v1.x.y` tag, and it must name exactly `strata/migrate`. It is
also written by its path, `xeonr/strata/cli/steps/migrate@v1`. It gets only
what the job grants it (`secrets:` and `identity:` on the step), each of
which its `step.yaml` must declare. The run records the repository, tag,
commit and version each one resolved to, and the registry digest of that
version, and branchd refuses to start a run naming a product step that was
not read from its namespace's repository.

> **Not yet available** (product steps): no namespace is bound yet, so `uses: strata/migrate@1` is refused with a message saying so. Binary steps of your own repository are not available either.

**A composite step's use** takes `id`, `name`, `uses`, `with`, `if`, `env`,
`isolated` and `workspace`. See [Composite steps](/docs/branchd/pipelines/composite-steps)
and [Step files](/docs/branchd/pipelines/step-files).

## Isolated steps [#isolated-steps]

A step marked `isolated: true` runs as a node of its own; the job is split
into parts around it, chained by `needs:`. Full guide:
[Isolate a step from the job](/docs/branchd/pipelines/isolated-steps).

* `workspace:` lists globs relative to the working directory (at most 32,
  `dir/**` for a tree; `.git` only if listed), or `all`; left out, the step
  gets the checkout only and hands nothing back. A step that takes no
  source can be given `all` or nothing.
* What it writes inside those paths comes back; nothing outside the working
  directory, no exported variable, service or background process crosses.
  Step outputs cross.
* Refused: `if: failure()` on an isolated typed step, `continue-on-error` and
  a `concurrency` lock on the job, more than 8 isolated steps in a job.
* It gets only the secrets its package declares, and its identity tokens
  reach no other part.

## matrix [#matrix]

| Key               | Meaning                                                                                                                                                 |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<key>: [values]` | One dimension. The job runs once per combination of all dimensions.                                                                                     |
| `include`         | A list of maps. Each joins every combination whose values it agrees with, adding its other keys; one that agrees with none is a combination of its own. |
| `exclude`         | A list of maps. Each removes the combinations it matches.                                                                                               |
| `fail-fast`       | `true` (the default): once a cell fails, the others stop. `false`: every cell runs to its end.                                                          |

A cell is named `<id> (<values>)`, such as `test (1.26, linux)`. Values are
read as `${{ matrix.<key> }}`, and each cell's `if:` is decided on its own.
A matrix job has no `outputs`. At most 256 cells; the product of the
dimensions may be up to 1,024 before `exclude`; `include` and `exclude` take
up to 256 entries each.

## trigger [#trigger]

| Key        | Meaning                                                                |
| ---------- | ---------------------------------------------------------------------- |
| `repo`     | The repository to start a run in. Required.                            |
| `pipeline` | The name of the pipeline there (`.branchd/pipelines/<pipeline>.yaml`). |
| `ref`      | A branch there; empty is its default branch.                           |
| `inputs`   | Its `on.trigger.inputs`.                                               |
| `wait`     | `true`: this job takes the other run's result.                         |

The target must declare `on: trigger` with a `from` that allows this
repository. A trigger job takes only `trigger`, `needs`, `if`, `matrix`,
`environment`, `concurrency`, `manual` and `continue-on-error`.

## Calling jobs [#calling-jobs]

A job with `uses:` calls a reusable pipeline (a file with `on: call`). It
takes `uses`, `with`, `needs`, `if`, `secrets`, `allow`, `runs-on`,
`environment`, `concurrency`, `manual` and `matrix`, and runs nothing itself.
With `matrix`, the pipeline is called once per cell, its jobs named
`<calling job> (<values>) / <job>`, and `with:` and `if:` read `matrix.*`.

* The called jobs join the run as `<calling job> / <job>`.
* `if:` false leaves them all out; `always()` lets the first of them run after
  a failed need.
* `needs:` are what the called pipeline's first jobs wait for. A job that
  needs the calling job needs every called job.
* `with:` gives `on.call.inputs`: an input it does not declare, or a missing
  required one, is refused. A whole `${{ needs.<job>.outputs.<name> }}` of a
  job it needs passes that output to a `string` or `choice` input.
* `secrets:` lists the secrets passed; each must be in `on.call.secrets`, and
  every required one must be passed.
* `environment:`, `concurrency:` and `manual:` are set on every called job. A
  called job that also sets `environment` or `concurrency` is refused; the
  caller's `manual` replaces a called job's own.
* Dependants read `on.call.outputs` as `${{ needs.<calling job>.outputs.<name> }}`.
* A called pipeline's expressions read the run's facts, its inputs, its own
  `env:` and its own jobs; `vars` is refused there. Its top-level
  `concurrency` applies only when it runs on its own.
* The calling file's `env:` and the repository's settings variables reach a
  called pipeline of the same repository, and not one of another repository.
* `matrix:` on a calling job is refused.

### Consent [#consent]

For a pipeline of another repository, the calling job decides:

* an `environment:` on one of its jobs needs `allow: [environment]`;
* a `trigger:` job in it needs `allow: [trigger]`;
* each runner label it asks for (`runs-on`, or its `defaults.runs-on`) must be
  listed in the calling job's `runs-on`, which lends labels without setting
  them;
* a call inside it is allowed only what every calling job above it allowed.

A pipeline of the calling repository may set all of these.

## Other repositories [#other-repositories]

`uses:` of a step, `<group>/<repo>/<path>@<version>`, or of a pipeline,
`<group>/<repo>/<path>.yaml@<version>`, reads another repository when the
run is compiled. Full guide:
[Steps and pipelines of another repository](/docs/branchd/pipelines/other-repositories).

* **The form** has at most 8 parts. The shortest leading part of at least two
  that is a repository you may read is the repository
  (`xeonr/forge/steps/setup-buf@v1` is `setup-buf` in `xeonr/forge/steps`).
* **Versions are tags**, resolved to a commit at compile time: `@v1` the
  newest `v1.x.y`, `@v1.4` the newest `v1.4.y`, `@v1.4.2` exactly, `@1` for
  tags without `v`; a 40-character commit only if a version tag names it or
  the default branch reaches it. A branch (`@main`) is refused. Only
  `[v]X.Y.Z` tags count (`v1.5.0-rc1` never does).
* **`.branchd/packages.yaml`** at the head of the publisher's default branch
  lists the step directories, pipeline files and presets others may use;
  anything else is refused. Inside a used step, `./<name>` is the
  publisher's own `.branchd/steps/<name>`.
* **Who may use it** is the publisher's visibility, judged for the calling
  repository: **private, that repository only**; company, repositories of
  the same company's teams; organisation, every repository; public, anyone.
  A repository you may not read is refused exactly as one that does not
  exist. A nested reference must be readable by every repository in the
  chain.
* **Trust.** A used step runs in your job's shell with its secrets, job
  token and workspace; a used pipeline is that team's jobs running as your
  repository with the secrets you pass. `branchd ci plan` lists each with
  the tag and commit it resolved to.
* **Consent.** A called pipeline of another repository may set
  `environment:` only with `allow: [environment]` on the calling job, start
  `trigger:` jobs only with `allow: [trigger]`, and ask only for runner
  labels the calling job's `runs-on` lists.
* At most 32 distinct references to other repositories in a run, and 1,000
  version tags of one major per repository.

## Presets [#presets]

`preset: {uses: <group>/<repo>[/<path>]@<version>, with: {...}}` runs a
preset, a WebAssembly program in another repository
(`<path>/preset.wasm`, listed in its `packages.yaml`), and adds the jobs it
returns. Full guide: [Presets](/docs/branchd/pipelines/presets).

* One preset a file. `uses: ./<path>`, a preset of the same repository, is
  refused for now.
* Its jobs are at addresses under `preset.`: `preset.apps.api.build`
  (check `CI / preset.apps.api.build`, node `preset_apps_api_build`). A
  prefix is a group: `needs: [preset.apps.api]`, or `needs: [preset]` for
  all of it.
* A need on one preset job that does not run here is refused unless
  `optional: true`. Its outputs are
  `${{ needs.preset.<address>.outputs.<name> }}`, or
  `${{ preset.<address>.outputs.<name> }}` in any job that waits for it.
* `on:` is optional; the file's own `on:` only narrows the preset's default
  triggers, and an event the preset does not trigger on is refused.
* Nothing in the file redefines a preset job: change `with:`.
* Its jobs have the repository's full context (secrets, environments,
  triggers, runner labels, `permissions:`). `secrets: [...]`, `allow: [environment, trigger]`, `runs-on: [...]` and `permissions: {...}` under
  `preset:` narrow what they may use.
* A push runs at most 8 presets, 15 seconds of module time in all.

## The job token [#the-job-token]

Every job gets `BRANCHD_TOKEN`. `git` uses it with no set-up; the API takes
it as a bearer token (`POST $BRANCHD_API_URL/xeonr.forge.v1.<Service>/<Method>`,
JSON, lowerCamelCase fields). **It reads this repository only.** Full guide
with `curl` examples: [The job token](/docs/branchd/pipelines/job-token).

| Permission      | `read`                                              | `write`                                                            |
| --------------- | --------------------------------------------------- | ------------------------------------------------------------------ |
| `contents`      | Always: commits, trees, branches, tags, `git fetch` | `git push`, branches and tags                                      |
| `pull-requests` | Pull requests, diffs, reviews, comments             | Comment, resolve, a comment-only review, open, edit, close, reopen |
| `checks`        | Checks on commits                                   | Report an external check                                           |
| `releases`      | Releases and files                                  | Create, edit, delete, upload                                       |
| `packages`      | List and pull images                                | Push images                                                        |
| `pipelines`     | Runs, logs, plans                                   | Start, retry, cancel runs                                          |

* `permissions:` at the top is every job's default; a job's own replaces it;
  with neither, `contents: read`. An unknown name or level, or an empty
  `permissions:`, is refused.
* `contents`, `releases` and `packages` writes need a protected ref and a
  push or manual run by a person, an agent or the team's own bot. A
  scheduled or triggered run only reads them.
* On a pull request's run and any unprotected branch, writes are capped by
  the repository's ceiling (default `pull-requests: write`, `checks: write`,
  on that pull request and commit).
* Never: settings, variables, secrets, branch rules, members, visibility;
  approving, merging or queueing a pull request; releasing a manual job;
  another repository.
* A called pipeline's jobs get at most the calling job's permissions. A
  composite step has the using job's.
* Variables: `BRANCHD_TOKEN`, `BRANCHD_TOKEN_COMMAND` (prints a fresh token),
  `BRANCHD_API_URL`, `BRANCHD_REPOSITORY`, `BRANCHD_PR`.

## Superseding [#superseding]

A newer run of the same pipeline for the same pull request or branch
supersedes the older run. Runs of different pipelines never do.

| The older run is for                 | By default                                          | `concurrency: {cancel-in-progress: true}` at the top | `… false` at the top |
| ------------------------------------ | --------------------------------------------------- | ---------------------------------------------------- | -------------------- |
| a pull request                       | **cancelled**, its running jobs stopped             | cancelled                                            | runs side by side    |
| a push to an unprotected branch      | **cancelled**, its running jobs stopped             | cancelled                                            | runs side by side    |
| a push to a protected branch         | **runs to the end**; the newer run queues behind it | cancelled                                            | runs side by side    |
| a tag                                | runs side by side (each tag is its own ref)         | side by side                                         | side by side         |
| a manual, scheduled or triggered run | never superseded                                    | never                                                | never                |

* **Never stopped part-way**, whatever the default: a job with
  `environment:` (unless it says `cancel-in-progress: true`), a job whose
  typed step is not safe to interrupt (a deploy, a migration, a publish), and
  a job with `concurrency: {cancel-in-progress: false}`. Once one of those
  has started, the older run is not cancelled at all: it finishes, and the
  newer run queues behind it.
* A cancelled run's checks say `cancelled`, "superseded by run #N", never
  `failed`. A pull request's required checks are judged on its head commit
  only.
* A rollback is just a newer run: on a protected branch it queues behind the
  run in progress.

## Expressions in brief [#expressions-in-brief]

Everything in `${{ }}` and `if:` is decided when the run is compiled, except
`steps.<id>.outputs.<name>` and `needs.<job>.outputs.<name>`, which are read
while the job runs (in `run:`, `env:`, `image:`, `with:` and job
`outputs:`, and in `if:`: a step's `if:` is decided when the step's turn
comes, a job's when its needs have run). Contexts: `branch`, `tag`, `event`, `pr.number`,
`pr.source`, `pr.target`, `inputs.*`, `matrix.*`, `vars.*`, `env.*`, `sha`,
`ref`, `repository`, `default_branch`, `protected`, `merge_queue`,
`preset.<address>.outputs.*`. Functions: `changed()`, `exists()`,
`contains()`, `startsWith()`, `endsWith()`, `always()`, `success()`,
`failure()`, `cancelled()`. A `${{ }}` in a `run:` becomes an environment variable, never
shell text. Details: [Expressions](/docs/branchd/pipelines/expressions).

## Not available yet [#not-available-yet]

Each is refused with a message saying so, or documented as missing:

* `max-parallel`.
* A `run:` job's outputs as an `image:` or a typed step's `with:`.
* A preset of the same repository (`./<path>`).
* Steps published by other products; binary steps of your own repository.
* A trigger of another repository that is not yet switched to pipeline
  files (today, every other repository).
* The shared `xeonr/forge/steps` and `xeonr/forge/presets`, from any other
  repository: released (`v1`), but still private.
* A step-level `secrets:` for an isolated step.

