Pipelines
Reuse a step (composite steps)
Keep a list of steps with inputs in a file of its own, and use it from any job of the repository.
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.
The step, in .branchd/steps/setup-buf/step.yaml:
# .branchd/steps/setup-buf/step.yaml
# A composite step: steps with inputs, expanded into the job that uses it.
name: Set up buf
description: Installs buf, and signs in to the Buf Schema Registry when asked.
inputs:
version: {type: string, default: '1.56.0'}
login: {type: bool, default: 'false'}
secrets:
BUF_TOKEN: {required: false, description: 'A Buf Schema Registry token, for login.'}
outputs:
path: ${{ steps.install.outputs.path }}
steps:
- id: install
name: 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"
- name: Sign in
if: inputs.login
run: echo "$BUF_TOKEN" | buf registry login buf.build --token-stdin
The pipeline that uses it:
# .branchd/pipelines/ci.yaml
# Uses the composite step in .branchd/steps/setup-buf/ twice: once with its
# defaults, once with a version and a sign-in.
name: CI
on: [push, pull_request]
jobs:
lint:
image: golang:1.26
steps:
- uses: ./setup-buf
- run: buf lint
push:
if: branch == 'main' && event == 'push'
image: golang:1.26
secrets: [BUF_TOKEN]
steps:
- id: buf
uses: ./setup-buf
with:
version: '1.57.0'
login: true
- run: ${{ steps.buf.outputs.path }} push
uses: ./<name>names.branchd/steps/<name>/step.yamlof this repository, at the run's commit.<name>may have several segments (./go/setupis.branchd/steps/go/setup/step.yaml).- Expanded when the run is compiled. Its steps become the job's own, in
the job's shell: a tool it installs or a variable it exports is there for
the steps after it. The log labels them
<use's name>: <step's name>(Set up buf: Install). step.yamlhasname,description,inputs,secrets,outputsandsteps(required).stepsarerun:steps, other composite steps and, markedisolated: true, typed steps.- Inputs are
{type, default, required, description}, withtypestring(the default),boolorint. An input nobody gives reads its default, else'',falseor0.with:on the use gives them; an input the step does not declare is refused. - Secrets. The step reads a secret from the environment (
$BUF_TOKEN), so the job that uses it grants it in its ownsecrets:. Arequired: truesecret the job does not grant is refused; one withrequired: falseis optional, and the step must cope without it. - Outputs.
outputs:maps names to values, usually${{ steps.<id>.outputs.<name> }}of one of its steps. The job reads them through the use'sid:${{ steps.buf.outputs.path }}. - The use takes
id,name,uses,with,if,env,isolatedandworkspace(see Isolate a step).if:applies to all its steps;env:is given to each of them, and then each runs in a subshell, so its exports no longer reach the steps after it. - What its expressions can read: the run's facts (
branch,event, …), its owninputsand its own steps' outputs. The calling job'smatrix,needs,envandvarsare refused there: pass them inwith:. - To share it with other repositories, see Steps and pipelines of another repository.
- It is not isolated. A composite step runs in the job's shell with everything the job has: its secrets, its job token and its workspace.
- Limits.
uses:nests at most 4 deep; a cycle is refused; at most 64 uses are expanded in one file; a job has at most 256 steps, its composite steps' included.