Writing a step
Publish a composite step or a typed step for other repositories to use.
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.yamlor.xeonr-ci.yaml. See What is available.
A composite step for others
A composite step needs no build. Put it in a directory of a repository, list
the directory in .branchd/packages.yaml, and tag a version.
# xeonr/forge/steps: .branchd/packages.yaml
# What other repositories may use from xeonr/forge/steps. It is read at the head
# of the default branch, never at the commit being used.
packages:
- setup-buf
- .branchd/pipelines/deploy.yaml
# xeonr/forge/steps: setup-buf/step.yaml
# Used from another repository as xeonr/forge/steps/setup-buf@v1.
name: Set up buf
description: Installs buf.
inputs:
version: {type: string, default: '1.56.0'}
outputs:
path: ${{ steps.install.outputs.path }}
steps:
- id: install
run: |
curl -fsSLo /usr/local/bin/buf \
"https://github.com/bufbuild/buf/releases/download/v${{ inputs.version }}/buf-$(uname -s)-$(uname -m)"
chmod +x /usr/local/bin/buf
echo "path=/usr/local/bin/buf" >> "$BRANCHD_OUTPUT"
- Lay it out. One directory per step, holding
step.yaml(setup-buf/step.yaml). The directory's path is the step's name in a reference:xeonr/forge/steps/setup-buf@v1. Its keys are those of a composite step. - List it in
.branchd/packages.yamlon the default branch. Pipeline files declaringon: callare listed by their path the same way. - Tag it
vX.Y.Z. Consumers write@v1and get your newestv1.x.ywhen their next run is compiled, so a new tag reaches them without their changing anything. Break compatibility only in a new major. - Set the repository's visibility to who should use it: company or organisation for a shared step repository. A private repository's steps are usable by that repository alone.
- Test it from a second repository with
branchd ci plan, which reads a sibling checkout's tags and commits (never its working tree): commit and tag in the step repository's clone first.
Keep a published step honest about what it touches: it runs with the caller's secrets and token, and callers read it before they use it.
A typed step
Not yet available (publishing): a repository on branchd cannot publish its own typed steps yet; it is rolling out (the step manifest below is final).
A typed step is one program that branchd runs in its own image. It reads
typed inputs, writes typed outputs, can ask for a token for one Xeonr
product, and fails with an error or an exit code. Its directory holds the
Go main package and a manifest version 2 step.yaml:
# steps/hello/step.yaml
# A typed step (manifest v2): one program, built from the Go main package in
# this directory, run in its own image. Its registry name comes from the
# repository and directory, so the file names none.
manifest: 2
name: Hello
description: Greets someone and says how long the greeting was.
runs:
main: .
platforms: [linux/amd64, linux/arm64]
source: true
inputs:
who:
type: string
default: world
description: Who to greet.
outputs:
length:
type: int
description: The greeting's length in bytes.
secrets:
GREETING_TOKEN:
optional: true
description: Not needed to greet; shown here to declare a secret.
Step and package files lists every key.
- Lay it out as for a composite step: one directory per step, listed
in
.branchd/packages.yaml. The file names no registry package: branchd names it from your repository and the directory. - Ask for a step grant if it needs
network,privilegedorhost_runtime, or takes secrets it does not declare (accepts_any_secret). An administrator of your repository's company grantsnetworkandany_secret;privilegedandhost_runtimeare an instance administrator's. Publishing refuses a step that declares more than its repository's grant. - Publish from a version tag. A job of the tag's run, with
permissions: {packages: write}, asks branchd to prepare the publish (RunService.PrepareStepPublish), pushes the step's image with the credential it is given, and records the version (RunService.PublishStep). branchd readsstep.yamlitself, at the tag, and records your repository and commit as the version's source. Only a protectedvX.Y.Ztag at the run's commit publishes, once per version. - Use it from another repository as
<team>/<repo>/<dir>@v1, like a composite step:@v1takes your newestv1.x.y.
A step's grant and its secrets are its caller's to see: a job that lists
secrets: narrows what the step gets, and a required secret it leaves out
is refused at compile, naming it.