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
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. It is written in Go on the
branchd SDK (branchd.run/branchd/sdk, MIT licensed, from the public
repository branchd/sdk), the same SDK
branchd's own steps are written on. Start from
branchd/template-step: one
step, its tests and the CI that publishes it.
Write it
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. The file names no registry package: branchd names it from your repository and the directory.
package main
import (
"context"
"branchd.run/branchd/sdk/step"
)
type inputs struct {
Name string `step:"name,required"`
}
func main() { step.Run(hello) }
func hello(ctx context.Context, s *step.Step, in inputs) error {
s.Logf("hello %s", in.Name)
return s.Output("greeting", "hello "+in.Name)
}go get branchd.run/branchd/sdk@latest adds the SDK. A default is written in
step.yaml only: the build links it into the binary.
Test it
- In process:
steptest.NewAttempt(t, inputs)andsteptest.Run(a, fn)run the step's function against fixtures (inputs, staged files, tokens) and return its outputs, log and error. - Every manifest:
steptest.CheckManifests(t, ".", false)loads eachstep.yamlas the release does, so a manifest the publish would refuse fails a pull request. - The built binary:
branchd ci step run steps/hello --with name=Adabuilds it for your machine and runs it once in an environment like the sandbox's, with only the secrets you give (--secret-env NAME).
Release it
-
List the directory in
.branchd/packages.yamlon the default branch. -
Protect the default branch and
v*tags. -
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. -
Add a release pipeline that runs on
v*tags, withpermissions: {packages: write}:.branchd/pipelines/release.yamlname: Release on: push: tags: ['v*'] permissions: {packages: write} jobs: publish: image: golang:1.26.4 steps: - run: go run branchd.run/branchd/sdk/cmd/publish step steps/helloFor each directory, branchd reads
step.yamlitself, at the tag, holds it to the grant, and gives a push login on the package registry; the step is built for its platforms and its image pushed, and branchd records the version with your repository and commit as its source. Only a protectedvX.Y.Ztag at the run's commit publishes, once per version. -
Tag
vX.Y.Z, and use it from another repository as<team>/<repo>/<dir>@v1:@v1takes your newest publishedv1.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.
Getting it listed
A published step is listed in Steps & presets
for whoever can read your repository's code, with no submission. Give it a
human name:, a README.md beside step.yaml with a uses: example, and a
description on every input and secret. branchd ci step lint shows what it
lacks.