Run tests on a pull request
Test every pull request and every push to main, and require the checks before a pull request merges.
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.
# .branchd/pipelines/ci.yaml
# Test every pull request, and every push to main. The checks are
# "CI / lint" and "CI / test (1.25)", "CI / test (1.26)": require those in
# main's branch rule. The lint job's image has no git: the checkout needs
# nothing in the image.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
lint:
image: alpine:3.20
steps:
- run: apk add --no-cache shellcheck
- run: shellcheck scripts/*.sh
test:
matrix:
go: ['1.25', '1.26']
image: golang:${{ matrix.go }}
steps:
- run: go vet ./...
- name: Test
run: go test -race -count=1 ./...
pull_request:with nothing under it runs for every pull request, on each new head. On branchd a pull request is always from a branch of the same repository, and its run uses that branch's pipeline files.push: branches: [main]also tests what lands onmain. Without it a push to a feature branch that has no pull request runs nothing.- No checkout step, no git in the image.
lintruns inalpine:3.20, which has no git. Every job starts in a checkout of the run's commit, with.git, fetched before the job's container starts.checkout: {depth: 0}fetches the whole history (50 commits by default),checkout: {tags: true}the tags,checkout: falsenothing. - Steps share one shell, bash when the image has it, else sh, with
set -e: the first command that fails fails the job. - The checks are
CI / lint,CI / test (1.25)andCI / test (1.26):<pipeline> / <job>, with a matrix cell's values in brackets.
Require the checks
In the branch rule for main, require CI / lint, CI / test (1.25) and
CI / test (1.26). A pull request then cannot merge until each has
succeeded on its head commit.
- Require only checks that run on every pull request to that branch. A
job with an
if:that can be false, or a pipeline filtered bypaths:, never reports on some pull requests, and they cannot merge. branchd names a required check that never reported as missing. - Renaming the pipeline (
name:) or a job renames its checks: change the rule in the same pull request.
A newer push cancels the older run
When you push again to a pull request's branch, the newer run supersedes the
older one: the older run is cancelled, its running jobs stopped, and its
checks say cancelled, "superseded by run #N". Only the head commit's
checks count for merging. concurrency: {cancel-in-progress: false} at the
top of the file keeps older runs going instead. See
Superseding.
Check it locally
branchd ci plan --event pull_request # this branch as a pull request into the default branch
branchd ci lint # every situation and every event