PEP-22: Gitea Actions workflow for Peppa on the PEP-57 runner; testkit creates its DB over SQL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
93f38bbcba
commit
8fee68f8eb
35
.gitea/workflows/ci.yml
Normal file
35
.gitea/workflows/ci.yml
Normal file
@ -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
|
||||||
@ -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
|
|
||||||
@ -16,6 +16,7 @@
|
|||||||
"@peppa/shared": "workspace:*",
|
"@peppa/shared": "workspace:*",
|
||||||
"drizzle-orm": "0.45.4",
|
"drizzle-orm": "0.45.4",
|
||||||
"@peppa/bot": "workspace:*",
|
"@peppa/bot": "workspace:*",
|
||||||
"@peppa/mcp": "workspace:*"
|
"@peppa/mcp": "workspace:*",
|
||||||
|
"postgres": "4.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,15 +7,19 @@ import { mkdirSync, mkdtempSync, readFileSync, existsSync, writeFileSync } from
|
|||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join, resolve } from "node:path";
|
import { join, resolve } from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
import postgres from "postgres";
|
||||||
import type { Scenario, MockLogEntry } from "../src/scenario.ts";
|
import type { Scenario, MockLogEntry } from "../src/scenario.ts";
|
||||||
|
|
||||||
const ROOT = resolve(fileURLToPath(import.meta.url), "../../../..");
|
const ROOT = resolve(fileURLToPath(import.meta.url), "../../../..");
|
||||||
const TMP = mkdtempSync(join(tmpdir(), "peppa-cjm-"));
|
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_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, {
|
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_HOME: join(TMP, "home"),
|
||||||
PEPPA_TMUX_SOCKET: `peppa-test-${process.pid}`,
|
PEPPA_TMUX_SOCKET: `peppa-test-${process.pid}`,
|
||||||
PEPPA_CLAUDE_BIN: join(ROOT, "packages/testkit/bin/mock-claude"),
|
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 });
|
mkdirSync(process.env.PEPPA_HOME!, { recursive: true });
|
||||||
|
|
||||||
execFileSync("bash", [
|
{
|
||||||
"-c",
|
const admin = postgres(`${TEST_PG}/postgres`, { max: 1, onnotice: () => {} });
|
||||||
`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 [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.
|
// Import after the env is set: these modules read it at load time.
|
||||||
export const core = await import("@peppa/core");
|
export const core = await import("@peppa/core");
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -362,6 +362,9 @@ importers:
|
|||||||
drizzle-orm:
|
drizzle-orm:
|
||||||
specifier: 0.45.4
|
specifier: 0.45.4
|
||||||
version: 0.45.4(postgres@4.1.1)
|
version: 0.45.4(postgres@4.1.1)
|
||||||
|
postgres:
|
||||||
|
specifier: 4.1.1
|
||||||
|
version: 4.1.1
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,8 @@ fi
|
|||||||
|
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
DB="peppa_test_ci_$$"
|
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
|
trap cleanup EXIT
|
||||||
|
|
||||||
step() { # <name> <command...>
|
step() { # <name> <command...>
|
||||||
|
|||||||
@ -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 "<number> <sha>" 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" </dev/null
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
pass
|
|
||||||
while [ -n "$LOOP" ]; do sleep "$LOOP"; pass; done
|
|
||||||
Loading…
Reference in New Issue
Block a user