Components
uses: runs a component: on a step, a step component; on a job, a template that expands into jobs when the pipeline compiles. A reference is a path in the repository (./.hod/components/<name>) or a published component (hod/setup-go@v1, registry.example.com/ci/tool@2), pinned in hod.lock by hod component update.
Step components
A step component takes its inputs in with: and declares its outputs, which a step with an id: reads as steps.<id>.outputs.<name>. It runs in a container of its own (runs: container, the default) or inside the job (runs: job), and declares the secrets and hosts it needs; the step must grant them.
A step component's component.yaml, which posts to a chat webhook:
# A `runs: container` component (design/components.md): it runs in a
# container of its own, out of reach of what the job's earlier steps left
# running, gets the secret it needs as a file, and returns an output.
#
# steps:
# - id: notify
# uses: ./docs/examples/components/notify
# with: {channel: "#builds", message: '${{ "Built " + event.sha }}'}
# secrets: [WEBHOOK_URL]
# - run: echo "sent at $AT"
# env: {AT: '${{ steps.notify.outputs.sent_at }}'}
#
# Try it: hod component test docs/examples/components/notify
# --secret WEBHOOK_URL=env:WEBHOOK_URL
name: notify
description: Post a message to a chat webhook
image: alpine:3.22 # pin a digest in real use
entrypoint: notify.sh
shell: sh
inputs:
channel: string
message: string
dry_run: {type: bool, default: "false"}
outputs:
sent_at: string
needs:
secrets: [WEBHOOK_URL]
network: [hooks.example.com]
examples:
- with: {channel: "#test", message: hello, dry_run: "true"}
expect:
outputs: {sent_at: dry-run}
Templates
A template is a component.yaml with jobs: and typed inputs. The job that uses one takes uses, with, needs, if, matrix and secrets (mapping the template's secret names to yours), and becomes the template's jobs, named <job>/<template job> even when there's only one. Inside the template, a job names its siblings by their short names, in needs: and in expressions (jobs.build.outputs.version). hod plan --expand shows every job they make.
A template for a Rust service:
# A template: a platform team's standard jobs for a Rust service
# (design/components.md, section 9). A repository uses it as
#
# jobs:
# svc:
# uses: acme/templates/rust-service@v1
# with:
# toolchain: "1.91"
# test: [ { run: cargo test --all } ]
# secrets: { registry: CRATES_TOKEN }
#
# and gets the jobs svc/build and svc/publish.
name: rust-service
description: Builds, tests and, on a tag, publishes a Rust crate
inputs:
toolchain: { type: string, default: stable, description: The rust image's tag }
features: { type: list(string), default: [], description: Cargo features to build with }
test: { type: steps, default: [ { run: cargo test --locked } ], description: How the crate is tested }
secrets: [registry]
jobs:
build:
image: 'rust:${{ inputs.toolchain }}'
cache: [rust]
env:
FEATURES: '${{ inputs.features.join(",") }}'
steps:
- run: cargo build --locked --features "$FEATURES"
- steps: ${{ inputs.test }}
publish:
needs: [build]
if: event.tag != ""
image: 'rust:${{ inputs.toolchain }}'
steps:
- run: cargo publish --locked
secrets: [{ name: registry, env: CARGO_REGISTRY_TOKEN }]
Writing one
hod component init <dir> writes a skeleton, and hod component test <dir> runs the examples in its component.yaml. Which published components a server allows, and how they are verified, is in Components under Self-hosting.