Skip to Content
Xeonr Developer Docs
Pipelines

Writing a preset

What a preset program receives, what it returns, and the limits it runs under.

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.

Not yet available (preset SDK): the preset SDK, git.prod.wtf/xeonr/forge/ci/sdk/preset, is in branchd's private compiler module, so writing a preset needs access to it. Using a published preset is available (Presets).

A preset is a Go program, compiled to WebAssembly (wasip1), that branchd runs inside the compiler at every push. It is untrusted code, so it gets no network, no environment, no arguments, a fixed clock and a read-only view of the repository.

What it receives

  • Its configuration: the pipeline file's preset.with, decoded into the preset's own configuration type. An unknown key is refused, and the refusal lists the known ones. A refusal names a dotted path into with:, and the compiler shows it at that key's line.
  • The run's facts: the event, branch, tag, ref and commit, the changed paths, the run number, the repository's path and default branch, whether the ref is protected, and a pull request's number and target.
  • The repository's files at the commit, read-only: read a file, ask whether one exists, list files by glob.

What it returns

  • Jobs in the pipeline-file job form (reference), each at an address: the path of the configuration that produced it (apps.api.build). branchd adds preset.. An address is never another's prefix.
  • Default triggers, which a file's own on: narrows.
  • Notes and warnings, which branchd ci plan shows.

Return every job the configuration asks for and give each an if: for the events it runs on, rather than leaving it out: a need on a job that does not run then says why. Needs name the preset's own addresses, or the repository's own jobs the configuration names (by convention a needs: key on the entry).

Describe mode

The same program answers a description request with its name, summary, default triggers, the JSON Schema of its configuration, and its address patterns and outputs. The documentation and the compiler's messages come from it.

Publishing it

  1. Build the module for wasip1, from the preset's Go main package: GOOS=wasip1 GOARCH=wasm go build -trimpath -ldflags='-s -w' -o preset.wasm .
  2. Commit preset.wasm at <path>/preset.wasm in the publishing repository (service/preset.wasm in xeonr/forge/presets), so the commit a tag names holds the module.
  3. List <path> in .branchd/packages.yaml on the default branch.
  4. Tag vX.Y.Z. Users write preset: {uses: <group>/<repo>/<path>@v1} and get the newest v1.x.y when their next run is compiled. Keep each job's secrets, environments and runner labels stable within a major: a user's narrowing (preset.secrets, allow, runs-on) refuses a job past it.
  5. Set the visibility to who may use it: company or organisation. A private repository's preset is usable by that repository alone, and a repository cannot use its own preset (./<path> is refused for now).

Limits

LimitValue
Module size8 MiB
Memory64 MiB of linear memory
Time5 seconds a call
Output1 MiB on stdout (64 KiB of stderr kept)
Files1,000 different files a call, 1 MiB each
Globs1,000 a call
Request (its with: and the facts)4 MiB
A push8 presets, 15 seconds of module time in all

A preset that fails, passes a limit, or returns jobs that do not check fails the compile of that pipeline file only, with a message naming the preset (preset xeonr/forge/presets/service@v1: …). The repository's other files compile as usual.

On this page