Lint trees in pre-commit and CI
Check every tree file on commit and in CI, with or without the CLI installed.
A broken tree is cheapest to fix before it is committed. Two pre-commit hooks check tree files on every commit, and one command checks them in CI.
Which files are trees
A file is a tree by its name alone: it ends in .beetree.yaml, .beetree.yml or .beetree.json. Every recipe on this page matches files with this pattern:
\.beetree\.(yaml|yml|json)$
Other YAML and JSON files in your repository are left alone.
What each check catches
| Check | Needs | Catches |
|---|---|---|
| Schema only | Nothing to install: pre-commit fetches the checker, the schema comes from beetreecraft.com | The shape of the file: required fields, the six node types, child counts, field types |
beetree validate | The beetree CLI on your PATH | Everything the schema catches, and what it cannot: unique node names, known decorators, blackboard defaults that fit their type, subtree references, custom node parameters, and misspelt fields named with the closest valid one |
Use the schema-only hook when not everyone on the team has the CLI, the full check when they do, or both. The tree format page explains the schema’s two addresses; these recipes pin the versioned one, so a release of beetreecraft.com never changes what your check accepts.
Schema only (nothing to install)
Add this to .pre-commit-config.yaml at the root of your repository:
repos:
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.4
hooks:
- id: check-jsonschema
name: beetree tree schema
files: '\.beetree\.(yaml|yml|json)$'
args: ['--schemafile', 'https://beetreecraft.com/schemas/v1/beetree.schema.json']
Full check (needs the CLI)
Install the CLI, then add this hook. pre-commit passes the changed tree files to beetree validate, several at a time:
repos:
- repo: local
hooks:
- id: beetree-validate
name: beetree validate
entry: beetree validate
language: system
files: '\.beetree\.(yaml|yml|json)$'
With both, list the two entries under one repos: key. Then install the hooks once, and check every tree already in the repository:
pre-commit install
pre-commit run --all-files
A tree that fails stops the commit, and the message names the file and the node:
beetree validate.........................................................Failed
- hook id: beetree-validate
- exit code: 1
Validation errors in trees/guard.beetree.yaml:
- tree.children[0]: unknown node type "sequnce" (did you mean "sequence"?)
Error: found 1 validation error(s)
In CI
Install the CLI with the install script, then validate every tree file the repository tracks. beetree validate exits non-zero when any file is invalid, which fails the job:
curl -fsSL https://beetreecraft.com/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
git ls-files -z '*.beetree.yaml' '*.beetree.yml' '*.beetree.json' | xargs -0 -r beetree validate
The install script checks the archive’s checksum before it installs anything; set BEETREE_INSTALL_DIR to put the binary elsewhere. When the repository already runs pre-commit in CI, pre-commit run --all-files runs both hooks there too.