- packages/db: schema on sqlite-core (timestamps as epoch ms → Date, JSON as text, booleans 0/1), one baseline migration; node:sqlite client under drizzle's better-sqlite3 session (busy_timeout first, WAL, BEGIN IMMEDIATE, retries on SQLITE_BUSY, lazy open, async transaction callbacks refused); PEPPA_DB (default ~/.peppa/peppa.db) - live updates: notify() pokes the bot over a unix socket; the bot also watches PRAGMA data_version every second (writes by other processes) - Postgres specifics ported: createTask transaction is synchronous, no `for update skip locked`, `count(*)`, json_extract instead of ->>, json_each instead of @> - `peppa db migrate` and `peppa db migrate-to-sqlite <file>` (read-only snapshot of Postgres, FK order from the schema, row count + foreign key checks, file appears only when they pass); old Postgres schema kept in packages/cli/legacy-pg-migrations for the migration and its test - daily VACUUM INTO backup from the watchdog (7 copies, admin alert on failure) - tests: a temp SQLite file per test file; storage.test.ts (20 processes, per-project numbering across processes, socket/data_version, migration from Postgres incl. a dangling foreign key, backups); two test races fixed - CI: no per-run Postgres database; PEPPA_TEST_PG only for the migration test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.0 KiB
Bash
Executable File
75 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# CI for Peppa itself (PEP-22): typecheck, web build, e2e on mocks.
|
|
#
|
|
# scripts/ci.sh checks of this checkout (also `pnpm run ci`)
|
|
# scripts/ci.sh --pr <N> checks of PR head N in peppa-bot/peppa in a temp worktree,
|
|
# with commit status `peppa/ci` in Gitea (pending → success/failure)
|
|
# scripts/ci.sh --repeat <N> run the e2e suite N times in a row (flake hunting)
|
|
# scripts/ci.sh --skip-build skip `next build`
|
|
#
|
|
# Every e2e test file uses its own SQLite file in a temp dir, so runs never share state; the
|
|
# Postgres → SQLite migration test makes (and drops) its own database on $PEPPA_TEST_PG.
|
|
# Logs of --pr runs: ~/.peppa/ci/<sha>.log.
|
|
set -uo pipefail
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
PR="" REPEAT=1 BUILD=1
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--pr) PR=$2; shift 2 ;;
|
|
--repeat) REPEAT=$2; shift 2 ;;
|
|
--skip-build) BUILD=0; shift ;;
|
|
*) echo "unknown argument: $1" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$PR" ]; then
|
|
. "$ROOT/scripts/lib/ci-env.sh"
|
|
. "$ROOT/scripts/gitea-lib.sh"
|
|
REPO="${PEPPA_CI_REPO:-peppa-bot/peppa}"
|
|
CONTEXT="peppa/ci"
|
|
SHA=$(gitea_api "$GITEA_URL/api/v1/repos/$REPO/pulls/$PR" 2>/dev/null | python3 -c 'import json,sys;print(json.load(sys.stdin)["head"]["sha"])' 2>/dev/null) \
|
|
|| { echo "PR $PR not found in $REPO" >&2; exit 2; }
|
|
status() { # <state> <description>
|
|
gitea_api -X POST "$GITEA_URL/api/v1/repos/$REPO/statuses/$SHA" \
|
|
-d "{\"state\":\"$1\",\"context\":\"$CONTEXT\",\"description\":\"$2\"}" >/dev/null \
|
|
|| echo "warning: could not set commit status" >&2
|
|
}
|
|
mkdir -p "$HOME/.peppa/ci"
|
|
LOG="$HOME/.peppa/ci/$SHA.log"
|
|
WT="$(mktemp -d)/peppa-ci"
|
|
git -C "$ROOT" fetch -q origin "refs/pull/$PR/head" || { echo "cannot fetch PR $PR" >&2; exit 2; }
|
|
git -C "$ROOT" worktree add -q --detach "$WT" "$SHA" || exit 2
|
|
trap 'git -C "$ROOT" worktree remove --force "$WT" >/dev/null 2>&1' EXIT
|
|
ln -s "$ENV_FILE" "$WT/.env" 2>/dev/null
|
|
status pending "running typecheck, build, e2e"
|
|
start=$(date +%s)
|
|
args=(--repeat "$REPEAT"); [ "$BUILD" = 0 ] && args+=(--skip-build)
|
|
(cd "$WT" && pnpm install --frozen-lockfile --prefer-offline >/dev/null && bash scripts/ci.sh "${args[@]}") >"$LOG" 2>&1
|
|
rc=$?
|
|
took=$(( ($(date +%s) - start) / 60 ))
|
|
if [ $rc = 0 ]; then
|
|
status success "passed in ${took} min"
|
|
else
|
|
status failure "$(grep -E '^ci: (FAIL|ok)' "$LOG" | tail -1 | cut -c5-) — log $LOG"
|
|
fi
|
|
tail -20 "$LOG"
|
|
echo "PR $PR @ ${SHA:0:8}: $([ $rc = 0 ] && echo success || echo failure), log $LOG"
|
|
exit $rc
|
|
fi
|
|
|
|
cd "$ROOT"
|
|
|
|
step() { # <name> <command...>
|
|
local name=$1; shift
|
|
echo "ci: ▶ $name"
|
|
local t=$(date +%s)
|
|
if "$@"; then echo "ci: ok $name ($(( $(date +%s) - t ))s)"; else echo "ci: FAIL $name"; exit 1; fi
|
|
}
|
|
|
|
step typecheck pnpm -r typecheck
|
|
[ "$BUILD" = 1 ] && step "web build" pnpm --filter @peppa/web build
|
|
for i in $(seq 1 "$REPEAT"); do
|
|
step "e2e $i/$REPEAT" pnpm --filter @peppa/testkit test
|
|
done
|
|
echo "ci: all green"
|