Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101#!/usr/bin/env bash# Every check the commit hooks make, plus the test suite, in one command.## A commit made with `--no-verify` is checked by nobody, and so is a branch# whose author never ran `prek install`. This script is what a person or a# runner invokes to check a branch anyway.## It does not restate the checks. .pre-commit-config.yaml is the list, and this# runs prek over it; a second list here would be a second source of truth and# would disagree with the hooks within a month. What this adds to the hooks is# the two things they cannot do:## 1. The commit-msg stage over a range. The hook sees one message as it is# written; here every commit on the branch is checked, including the ones# that went in with the hook turned off.# 2. The native test suite. The hooks check types and lint, because a full# `cargo test` on every commit is a wait nobody would accept. A change# that breaks a native test passes every hook.## There are two tiers. The default is the fast one, for every branch before# it merges: the hooks, the commit messages and the native tests in nextest's# `fast` profile, which keeps the first case of each long bot and floor sweep# and leaves the rest to the full run.## `--full` is the tier for batches: the nightly integration run# (tools/integration) and every release (scripts/release.sh). The Tangled# workflow runs it too, but no spindle is attached to the repository, so today# nothing runs that workflow. It runs every native test, the# doctests, and scripts/wasm-test.sh, which needs wasm-bindgen-test-runner; a# branch that touches the core or the frontend runs that script by hand too.# No test is in neither tier.## Usage: scripts/ci.sh [--full] [<base>]## --full Run the full tier instead of the fast one.# <base> The ref the branch is measured against for the commit-msg stage.# Defaults to $CI_BASE, then to origin/main.set -euo pipefail
cd "$(dirname "$0")/.."
full=0if [ "${1:-}" = --full ]; then full=1 shiftfibase="${1:-${CI_BASE:-origin/main}}"status=0
step() { printf '\n=== %s ===\n' "$1" >&2}
step "fonts: fetch the pinned faces"scripts/fetch-fonts.sh
step "prek: the pre-commit hooks, over every file"# --all-files rather than a diff: a runner has no staged set, and a hook whose# `files` pattern never matched the branch's diff is exactly the one that has# quietly stopped working.prek run --all-files || status=1
step "prek: the commit-msg hook, over $base..HEAD"# A spindle clones one commit deep, so it has neither the history nor the# base, and committed's prebuilt binary cannot load on its Nix image anyway.if [ "$(git rev-parse --is-shallow-repository)" = true ]; then echo "skipping the commit-msg stage: a shallow clone has no history to check" >&2elif ! git rev-parse --verify --quiet "$base" >/dev/null; then echo "skipping the commit-msg stage: $base does not resolve here" >&2else message="$(mktemp)" trap 'rm -f "$message"' EXIT commits="$(git rev-list "$base..HEAD")" if [ -z "$commits" ]; then echo "no commits on top of $base" >&2 fi for commit in $commits; do git log -1 --format=%B "$commit" >"$message" echo "--- $(git log -1 --format='%h %s' "$commit")" >&2 prek run --stage commit-msg --commit-msg-filename "$message" || status=1 donefi
if [ "$full" -eq 1 ]; then step "cargo test: the native crates, every test" python3 scripts/check-targets.py test || status=1
step "wasm tests: the goldens and the frontend in wasm32" scripts/wasm-test.sh || status=1else step "cargo test: the native crates, fast tier (--full runs the rest)" python3 scripts/check-targets.py test --fast || status=1fi
if [ "$status" -eq 0 ]; then printf '\nall checks passed\n' >&2else printf '\nsomething failed; see above\n' >&2fiexit "$status"