Captain / Documentation / Part 8. Where Captain runs

Bosun: a project's tasks

Contents ↓

Bosun runs a project's chores: formatting, lints, tests, checks, releases. Its project file, bosun.capt at the project root, is a Captain module whose exported procedures are the project's tasks. The bosun command runs them on the developer's machine, prints one line per step, and keeps a report of every run.

Where a Makefile glues together scripts in many languages, bosun.capt does the same job in a checked program: each step's command is an argument vector, never a shell line, and each step's result is a typed value.

A project file

bosun.capt
module Hello::Bosun.

use Bosun::Tasks.

;; Formatting, lints and tests: what every commit must pass.
export check -> Text [
  fmt := run named: "fmt" program: "cargo" args: #( "fmt", "--all", "--", "--check" ).
  clippy := run named: "clippy" program: "cargo"
    args: #( "clippy", "--workspace", "--", "-D", "warnings" ).
  unit := cargoTest named: "unit tests" args: #( "--workspace" ) timeout: 20min.
  ret "checked".
].

;; Build once, then run the program's self-test against what was built.
export smoke profile: Text -> Text [
  built := run named: "build" program: "cargo" args: #( "build", "--release" ).
  tool := requireTool named: "jq".
  selfTest := run named: "self-test" program: "target/release/hello"
    args: #( "--self-test", profile )
    after: #( "build" ).
  ret "smoked".
].
Terminal
$ captain check bosun.capt
ok    bosun.capt (module Hello::Bosun, 2 declarations)
checked 1 file as 1 module, no errors
  • A task is an exported procedure returning a value; Bosun does not use the value, so ret "checked". is enough.
  • A task may take parameters. smoke profile: runs as bosun smoke profile=quick. A parameter may be text, i32, i64, bool, a symbol, a decimal, a duration or a size.
  • The comment above a task is its description, which bosun list --json reports.
  • Options are trailing keywords. timeout: and after: above are optional keywords of the built-in tasks. A procedure written in Captain source cannot declare optional keywords; the built-in module can.

bosun list compiles the file and lists the tasks:

Terminal
$ bosun list
  check
  smoke profile=<Text>

The tasks

Bosun::Tasks declares these effects, each of which is one step:

Task Does Returns
run named:program:args: runs a program directly, never through a shell; options in:, env:, timeout:, expectExit:, after:, report:, checks: BosunStep
cargoTest named:args: runs cargo test and reads which tests passed, failed and were ignored; a run that tested nothing fails BosunTests
requireTool named: passes if the program is on PATH; if not, the step cannot be judged, which is never a pass BosunStep
checkArtifact named:path: records a file's SHA-256, or confirms it against one BosunArtifact
inspectCrate named:path: reads a packaged Rust crate and checks its layout, pins and licence BosunCrate
publishCrate named:path:sha256:registry: publishes a crate whose digest was checked, and confirms the registry serves those bytes BosunPublication
projectPath of: the absolute path of a path inside the project; not a step Text

The result records are opaque: a program reads their fields, such as (unit passed), (unit failures) or (fmt state), but cannot make one. The only record a project file builds is BosunJsonCheck, which describes a check on a step's JSON report.

How a run behaves

  • Every step runs. A failing step does not stop the task; the run's verdict is the worst step's. The exit code is 0 if every step passed, 1 if one failed, and 2 if one could not be judged.
  • Dependencies are declared, not branched on. after: #( "build" ) makes the self-test depend on the step named build. If the build fails, the self-test is recorded as not run, with the reason, and nothing is invented for it. Writing the dependent step unconditionally, rather than inside an ifTrue:, keeps it in the report either way.
  • A step runs once per run. Two tasks run together, bosun check smoke, share any step with the same name, program, arguments, directory, environment and options: it runs once.
  • A task cannot call another task. Captain has no calls without arguments, so checked := check. does not parse. Shared steps go in a helper procedure that takes an argument, called from each task.

Each run keeps .bosun/runs/<id>/: a JSON report (bosun.run/1), a log per step, and Captain's own run log.

What Bosun checks

Like Forge, Bosun reads the compiled file's manifest and refuses a file in which any task can reach an effect that is not one of its tasks. A project file that runs a shell through the built-in exec effect passes captain check, and Bosun refuses it before anything runs:

Terminal
$ bosun list
bosun: `check` can reach `exec program:args:`, which is not a Bosun task; bosun.capt may use Bosun's tasks only

So bosun.capt cannot read files, open connections or start services itself. Anything else is done by a program a run step starts, and that program, its arguments and its outcome are in the report.