okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petrun treefmt in test.sh and the commit hook, as CI doesf51ff27

main
2.4 KiB72 linesraw
1#!/usr/bin/env bash
2# Every check that must pass before a commit.
3#
4# The quick checks run first, in order. Then the daemon is compiled once and
5# every suite runs at the same time, each into its own log, which is printed
6# only if that suite fails. The e2e suites boot their daemons from that one
7# snapshot (ALBEDO_TEST_DAEMON) instead of through gleam, so none of them waits
8# on the build lock `gleam test` holds for its whole run. test/manual is opt-in
9# and not run here; those harnesses need a provider, a PTY, or artifacts from
10# an earlier benchmark run.
11set -euo pipefail
12cd "$(dirname "$0")"
13export ALBEDO_NO_BROWSER=1
14# a detached kernel a suite left behind ends soon after, not in an hour
15export ALBEDO_KERNEL_GRACE_SECONDS=20
16
17# treefmt (Go, Nix and the other formatters CI runs); it rewrites what it fixes
18# and fails when it had to, so commit the result
19nix fmt -- --fail-on-change --no-cache
20ruff check
21ruff format --check priv/python test
22ty check
23gleam format --check src test
24test/gleam-lint.sh
25cargo test --quiet --release --locked --manifest-path native/render/Cargo.toml
26native/render/install.sh
27go -C cli/tools/apigen run . -check
28go -C cli vet ./...
29# the Python e2e suite drives the CLI through this binary
30go -C cli build -o bin/albedo ./cmd/albedo
31
32scratch="${ALBEDO_TEST_TMP:-/tmp/albedo-tests}/gate-$$"
33mkdir -p "$scratch"
34trap 'rm -rf "$scratch"' EXIT
35ALBEDO_TEST_DAEMON="$(test/snapshot-daemon.sh "$scratch/daemon")"
36export ALBEDO_TEST_DAEMON
37
38names=()
39pids=()
40log() {
41  echo "$scratch/${1//[\/ ]/-}.log"
42}
43suite() {
44  local name="$1"
45  shift
46  "$@" >"$(log "$name")" 2>&1 &
47  names+=("$name")
48  pids+=("$!")
49}
50
51suite "gleam test" gleam test
52for test in test/harness/*_test.py; do
53  suite "$test" python3 test/python_test_runner.py "$test"
54done
55suite "go test" go -C cli test ./internal/... ./cmd/...
56# the Go e2e suite builds its own CLI and boots a hermetic daemon, so it must
57# never reuse a cached run. Bound parallel scenarios while the other suites run.
58go_parallel="$(python3 -c 'import os; print(max(1, min(4, (os.cpu_count() or 1) // 4)))')"
59suite "go e2e" go -C cli test -count=1 -parallel="$go_parallel" ./test/e2e
60suite "python e2e" python3 test/e2e/run.py
61
62failed=0
63for i in "${!pids[@]}"; do
64  if wait "${pids[$i]}"; then
65    echo "ok      ${names[$i]}"
66  else
67    failed=1
68    echo "FAILED  ${names[$i]}"
69    cat "$(log "${names[$i]}")"
70  fi
71done
72exit "$failed"