diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 00000000..ba165286 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,35 @@ +# CI for Peppa itself (PEP-22): typecheck, web build and the e2e suite on mocks — the same +# scripts/ci.sh that runs locally. Runs on Peppa's act_runner (`peppa-trusted`, registered for +# peppa-bot's repos, PEP-57); Postgres is a throwaway service container, tmux is installed in the job. +name: peppa-ci +on: + pull_request: + push: + branches: [main] +jobs: + ci: + # The runner has the host's docker.sock: only branches of this repository, never forks. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + runs-on: peppa-trusted + timeout-minutes: 30 + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_USER: peppa + POSTGRES_PASSWORD: peppa + env: + PEPPA_TEST_PG: postgres://peppa:peppa@postgres:5432 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "26" + - name: tools + run: | + apt-get update -qq && apt-get install -y -qq tmux >/dev/null + npm install -g pnpm@12.18.0 >/dev/null + - name: install + run: pnpm install --frozen-lockfile + - name: ci + run: bash scripts/ci.sh diff --git a/infra/ci/peppa-ci.yml b/infra/ci/peppa-ci.yml deleted file mode 100644 index a8fd843f..00000000 --- a/infra/ci/peppa-ci.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Gitea Actions workflow for Peppa itself (PEP-22). Not active yet: there is no act_runner for -# peppa-bot/peppa. To enable, register a runner with label `peppa-host` (host mode: e2e needs -# tmux, docker exec into peppa-postgres and Postgres on 127.0.0.1:5433) and copy this file to -# .gitea/workflows/ci.yml. Until then scripts/mock-act-runner.sh sets the same `peppa/ci` status. -name: peppa/ci -on: - pull_request: - push: - branches: [main] -jobs: - ci: - runs-on: peppa-host - steps: - - uses: actions/checkout@v4 - - run: pnpm install --frozen-lockfile --prefer-offline - - run: bash scripts/ci.sh diff --git a/packages/testkit/package.json b/packages/testkit/package.json index da3b5555..cc45f2b5 100644 --- a/packages/testkit/package.json +++ b/packages/testkit/package.json @@ -16,6 +16,7 @@ "@peppa/shared": "workspace:*", "drizzle-orm": "0.45.4", "@peppa/bot": "workspace:*", - "@peppa/mcp": "workspace:*" + "@peppa/mcp": "workspace:*", + "postgres": "4.1.1" } } diff --git a/packages/testkit/test/helpers.ts b/packages/testkit/test/helpers.ts index 87ff6cd4..7e101a40 100644 --- a/packages/testkit/test/helpers.ts +++ b/packages/testkit/test/helpers.ts @@ -7,15 +7,19 @@ import { mkdirSync, mkdtempSync, readFileSync, existsSync, writeFileSync } from import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import postgres from "postgres"; import type { Scenario, MockLogEntry } from "../src/scenario.ts"; const ROOT = resolve(fileURLToPath(import.meta.url), "../../../.."); const TMP = mkdtempSync(join(tmpdir(), "peppa-cjm-")); -// PEPPA_TEST_DB lets parallel sessions (one per worktree) run the suite without sharing a database. +// PEPPA_TEST_DB lets parallel sessions (one per worktree) run the suite without sharing a database; +// PEPPA_TEST_PG points at another Postgres server (CI job: a service container). const TEST_DB = process.env.PEPPA_TEST_DB ?? "peppa_test"; +const TEST_PG = process.env.PEPPA_TEST_PG ?? "postgres://peppa:peppa@127.0.0.1:5433"; +if (!/^[a-z0-9_]+$/.test(TEST_DB)) throw new Error(`bad PEPPA_TEST_DB: ${TEST_DB}`); Object.assign(process.env, { - DATABASE_URL: `postgres://peppa:peppa@127.0.0.1:5433/${TEST_DB}`, + DATABASE_URL: `${TEST_PG}/${TEST_DB}`, PEPPA_HOME: join(TMP, "home"), PEPPA_TMUX_SOCKET: `peppa-test-${process.pid}`, PEPPA_CLAUDE_BIN: join(ROOT, "packages/testkit/bin/mock-claude"), @@ -30,10 +34,12 @@ Object.assign(process.env, { }); mkdirSync(process.env.PEPPA_HOME!, { recursive: true }); -execFileSync("bash", [ - "-c", - `docker exec peppa-postgres psql -U peppa -tAc "select 1 from pg_database where datname='${TEST_DB}'" | grep -q 1 || docker exec peppa-postgres createdb -U peppa ${TEST_DB}`, -]); +{ + const admin = postgres(`${TEST_PG}/postgres`, { max: 1, onnotice: () => {} }); + const [exists] = await admin`select 1 from pg_database where datname = ${TEST_DB}`; + if (!exists) await admin.unsafe(`create database ${TEST_DB}`); + await admin.end(); +} // Import after the env is set: these modules read it at load time. export const core = await import("@peppa/core"); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 58164673..43b95916 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -362,6 +362,9 @@ importers: drizzle-orm: specifier: 0.45.4 version: 0.45.4(postgres@4.1.1) + postgres: + specifier: 4.1.1 + version: 4.1.1 packages: diff --git a/scripts/ci.sh b/scripts/ci.sh index a31c73f0..fdfc1100 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -58,7 +58,8 @@ fi cd "$ROOT" DB="peppa_test_ci_$$" -cleanup() { docker exec peppa-postgres dropdb -U peppa --if-exists "$DB" >/dev/null 2>&1; } +# A CI job's Postgres (PEPPA_TEST_PG) is a throwaway service container: nothing to drop there. +cleanup() { [ -n "${PEPPA_TEST_PG:-}" ] || docker exec peppa-postgres dropdb -U peppa --if-exists "$DB" >/dev/null 2>&1; } trap cleanup EXIT step() { # diff --git a/scripts/mock-act-runner.sh b/scripts/mock-act-runner.sh deleted file mode 100755 index b8545a43..00000000 --- a/scripts/mock-act-runner.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Stand-in for Gitea Actions' act_runner until one is registered for peppa-bot/peppa (PEP-22): -# picks up open PRs whose head commit has no `peppa/ci` status yet and runs scripts/ci.sh --pr -# for each, which reports the status back like a workflow job would. -# -# scripts/mock-act-runner.sh one pass over open PRs -# scripts/mock-act-runner.sh --loop 120 keep polling every 120 s (foreground; not a service) -# scripts/mock-act-runner.sh --dry-run only list PRs that would be checked -set -uo pipefail -ROOT="$(cd "$(dirname "$0")/.." && pwd)" -. "$ROOT/scripts/lib/ci-env.sh" -. "$ROOT/scripts/gitea-lib.sh" -REPO="${PEPPA_CI_REPO:-peppa-bot/peppa}" -LOOP="" DRY=0 -while [ $# -gt 0 ]; do - case "$1" in - --loop) LOOP=$2; shift 2 ;; - --dry-run) DRY=1; shift ;; - *) echo "unknown argument: $1" >&2; exit 2 ;; - esac -done - -# Prints " " for open PRs without a peppa/ci status on their head. -pending_prs() { - gitea_api "$GITEA_URL/api/v1/repos/$REPO/pulls?state=open&limit=50" | - python3 -c 'import json,sys -for p in json.load(sys.stdin): print(p["number"], p["head"]["sha"])' | - while read -r n sha; do - gitea_api "$GITEA_URL/api/v1/repos/$REPO/commits/$sha/statuses" | - python3 -c 'import json,sys; sys.exit(0 if any(s["context"]=="peppa/ci" for s in json.load(sys.stdin)) else 1)' || - echo "$n $sha" - done -} - -pass() { - pending_prs | while read -r n sha; do - echo "mock-act-runner: PR $n @ ${sha:0:8}" - [ "$DRY" = 1 ] || bash "$ROOT/scripts/ci.sh" --pr "$n"