Some checks failed
PR Ready + auto-merge / ready-automerge (pull_request) Failing after 1s
CI (PR) / scope (pull_request) Failing after 1s
CI (PR) / lint (pull_request) Failing after 1s
CI (PR) / format (pull_request) Failing after 1s
CI (PR) / docs-guards (pull_request) Failing after 1s
CI (PR) / plans-only-closes (pull_request) Failing after 1s
CI (PR) / typecheck (pull_request) Has been skipped
CI (PR) / build (pull_request) Has been skipped
CI (PR) / e2e (1) (pull_request) Has been skipped
CI (PR) / knip (pull_request) Has been skipped
CI (PR) / cycles (pull_request) Has been skipped
CI (PR) / unit (pull_request) Has been skipped
CI (PR) / int (pull_request) Has been skipped
CI (PR) / e2e (2) (pull_request) Has been skipped
CI (PR) / checks (pull_request) Failing after 2s
- gate lê label org.opencontainers.image.revision do container rodando (compose pode mentir após rollback falho); desconhecido → fail-open verde; incapaz de classificar → exit 1 (run vermelho, nunca blackout silencioso) - gate main-only (github.ref) + setup-node explícito; deploy guard usa a mesma revision (idempotência à prova de rollback-falho) - docs: runbook (verificação ao vivo, falhas novas), AGENT-OPS (pool dormente), skills engineering-audit/model-selection, changelog; impl plan atualizado
300 lines
12 KiB
YAML
300 lines
12 KiB
YAML
# Post-merge verifier on `main`, in a fixed 30-minute window (OPS65): the
|
||
# workflow no longer fires on every push. The `schedule` trigger polls every
|
||
# 30 min and a cheap gate (`gate`, runs-on host, no pnpm) classifies whether
|
||
# anything that would enter the docker build context changed since the
|
||
# revision running on the homeserver (the `org.opencontainers.image.revision`
|
||
# label of the running container, read over ssh).
|
||
# - Deployed == HEAD → suite + deploy skip; the run stays green
|
||
# (the `checks` rollup already accepts skipped jobs).
|
||
# - Anything else (production change, unknown deployed state, dispatch) →
|
||
# full suite; deploy in the same window.
|
||
# - `workflow_dispatch` always runs the full pipeline (explicit operator
|
||
# intent); the deploy is idempotent via the "already deployed" guard in
|
||
# scripts/deploy-homeserver.sh.
|
||
#
|
||
# Fail-open: an unreadable/unknown deployed revision makes the gate report
|
||
# production=true, so the suite ALWAYS verifies main and a quiet day only
|
||
# skips when we KNOW deployed == HEAD. A gate that cannot classify at all
|
||
# (git/.dockerignore error) exits non-zero and turns the run RED — never a
|
||
# silent green blackout. The deploy job only runs when the gate succeeded
|
||
# AND production changed AND checks are green — never deploy blind.
|
||
#
|
||
# When the suite is green, the `deploy` job publishes teqo-1313 on the
|
||
# homeserver (OPS53): it streams scripts/deploy-homeserver.sh to the homeserver
|
||
# over SSH; the remote script builds the standalone image at the pushed SHA,
|
||
# pushes it to the local registry (localhost:5000), applies pending migrations
|
||
# through the compose maintenance service and rolls the container out.
|
||
#
|
||
# Forgejo port (OPS50): Postgres services publish to per-job HOST ports on the
|
||
# runner machine (act/forgejo runner semantics — the canonical 5432 is the
|
||
# workstation's own dev database), and jobs reach them through the bridge
|
||
# gateway: DB_HOST = gateway IP from /proc/net/route. No `permissions:`
|
||
# (Forgejo issues one native GITHUB_TOKEN) and no `concurrency:` (unsupported).
|
||
# `gh workflow run` requeues became `node scripts/forgejo-dispatch.mjs`.
|
||
# The GitHub fail-fast action was dropped (Forgejo has no cancel-run plumbing);
|
||
# job timeouts cover that role.
|
||
|
||
name: CI
|
||
|
||
on:
|
||
schedule:
|
||
- cron: '*/30 * * * *'
|
||
workflow_dispatch:
|
||
|
||
env:
|
||
PAYLOAD_SECRET: test-only-secret-not-used-in-production
|
||
NEXT_PUBLIC_SITE_URL: http://localhost:3000
|
||
|
||
jobs:
|
||
gate:
|
||
name: gate production change
|
||
# Host runner: needs `ssh homeserver` (same environment as the deploy
|
||
# job — the key lives on the workstation host) and a full clone to diff
|
||
# <deployed-rev>..HEAD. Main + dispatch only: a branch dispatch must not
|
||
# run that branch's code on the host — the skipped gate makes the suite
|
||
# run fail-open on ubuntu containers instead (test-only secrets).
|
||
if: github.ref == 'refs/heads/main'
|
||
runs-on: host
|
||
timeout-minutes: 10
|
||
outputs:
|
||
production: ${{ steps.classify.outputs.production }}
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
- uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
package-manager-cache: false
|
||
- name: Read deployed revision and classify production change
|
||
id: classify
|
||
run: |
|
||
set -euo pipefail
|
||
# Truth = the RUNNING container's revision label (the compose file
|
||
# can lie after a failed rollback — it is swapped before the
|
||
# rollout). Empty/malformed = unknown deployed state → the
|
||
# classifier reports production=true (full run, green).
|
||
deployed_sha="$(ssh homeserver "docker inspect -f '{{index .Config.Labels \"org.opencontainers.image.revision\"}}' teqo-1313 2>/dev/null" || true)"
|
||
if ! printf '%s' "$deployed_sha" | grep -Eq '^[0-9a-f]{40}$'; then
|
||
deployed_sha=""
|
||
fi
|
||
echo "deployed_sha: ${deployed_sha:-<none>}"
|
||
out="$(node scripts/ci-classify-production.mjs --deployed "$deployed_sha")"
|
||
printf '%s\n' "$out"
|
||
echo "production=$(printf '%s' "$out" | node -pe 'JSON.parse(require("fs").readFileSync(0,"utf8")).production')" >> "$GITHUB_OUTPUT"
|
||
|
||
static:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 20
|
||
needs: [gate]
|
||
# Fail-open: an errored gate never skips the verifier; only a gate that
|
||
# succeeded AND found no production change skips the suite.
|
||
if: needs.gate.result != 'success' || needs.gate.outputs.production == 'true'
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
- uses: pnpm/action-setup@v6
|
||
- uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: pnpm
|
||
- run: pnpm install --frozen-lockfile
|
||
- run: node scripts/check-test-locations.mjs
|
||
- run: pnpm lint
|
||
- run: pnpm format:check
|
||
- run: pnpm typecheck
|
||
- run: pnpm knip
|
||
- run: pnpm check:cycles
|
||
- run: pnpm test:unit
|
||
|
||
int:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 25
|
||
needs: [gate]
|
||
if: needs.gate.result != 'success' || needs.gate.outputs.production == 'true'
|
||
env:
|
||
# Self-hosted runner has 8 CPUs; vitest forks ≈ CPUs and each fork holds
|
||
# a Payload pool (max 10) → overflows the service Postgres' 100 clients
|
||
# ("too many clients already"). 4 forks stay well under. GitHub's 2–4
|
||
# vCPU runners keep the CPU-relative default (no env).
|
||
VITEST_MAX_WORKERS: 4
|
||
services:
|
||
postgres:
|
||
image: postgres:17-alpine
|
||
env:
|
||
POSTGRES_USER: teqo
|
||
POSTGRES_PASSWORD: teqo
|
||
POSTGRES_DB: teqo_test
|
||
ports:
|
||
- 5433:5432
|
||
options: >-
|
||
--health-cmd "pg_isready -U teqo"
|
||
--health-interval 5s
|
||
--health-timeout 5s
|
||
--health-retries 12
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
- uses: pnpm/action-setup@v6
|
||
- uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: pnpm
|
||
- run: pnpm install --frozen-lockfile
|
||
- name: Prepare database URL (service via bridge gateway)
|
||
run: |
|
||
set -euo pipefail
|
||
DB_HOST=$(awk '$2 == "00000000" {a=$3; print strtonum("0x" substr(a,7,2)) "." strtonum("0x" substr(a,5,2)) "." strtonum("0x" substr(a,3,2)) "." strtonum("0x" substr(a,1,2)); exit}' /proc/net/route)
|
||
echo "DATABASE_URL=postgresql://teqo:teqo@${DB_HOST}:5433/teqo_test" >> "$GITHUB_ENV"
|
||
# vitest re-loads .env.test over the process env, so the service URL
|
||
# must win through the .env.test.local layer (same mechanism
|
||
# `pnpm worktree next` uses). OPS50.
|
||
echo "DATABASE_URL=postgresql://teqo:teqo@${DB_HOST}:5433/teqo_test" > .env.test.local
|
||
- run: pnpm migrate
|
||
- run: pnpm db:seed:minimal
|
||
- run: pnpm test:int
|
||
|
||
build:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 25
|
||
needs: [gate]
|
||
if: needs.gate.result != 'success' || needs.gate.outputs.production == 'true'
|
||
services:
|
||
postgres:
|
||
image: postgres:17-alpine
|
||
env:
|
||
POSTGRES_USER: teqo
|
||
POSTGRES_PASSWORD: teqo
|
||
POSTGRES_DB: teqo_test
|
||
ports:
|
||
- 5434:5432
|
||
options: >-
|
||
--health-cmd "pg_isready -U teqo"
|
||
--health-interval 5s
|
||
--health-timeout 5s
|
||
--health-retries 12
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
- uses: pnpm/action-setup@v6
|
||
- uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: pnpm
|
||
- run: pnpm install --frozen-lockfile
|
||
- name: Prepare database URL (service via bridge gateway)
|
||
run: |
|
||
set -euo pipefail
|
||
DB_HOST=$(awk '$2 == "00000000" {a=$3; print strtonum("0x" substr(a,7,2)) "." strtonum("0x" substr(a,5,2)) "." strtonum("0x" substr(a,3,2)) "." strtonum("0x" substr(a,1,2)); exit}' /proc/net/route)
|
||
echo "DATABASE_URL=postgresql://teqo:teqo@${DB_HOST}:5434/teqo_test" >> "$GITHUB_ENV"
|
||
- name: Build (against the service database)
|
||
run: pnpm build
|
||
|
||
e2e:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 40
|
||
needs: [gate]
|
||
if: needs.gate.result != 'success' || needs.gate.outputs.production == 'true'
|
||
# Main always runs the full suite: split it across 2 jobs (OPS34), each
|
||
# building its own `.next-e2e` (measured 2026-08-10: build 172s + tests
|
||
# 196s + ~54s fixed → ≈ 5.5 min per shard vs 435s serial). `fail-fast:
|
||
# false` so one shard's failure keeps the other's diagnostics. Keep the
|
||
# [1, 2] / 2 literal in sync with `e2eShardConfig` in
|
||
# scripts/lib/test-affected-core.mjs (ci-pr pins the same literal).
|
||
strategy:
|
||
fail-fast: false
|
||
matrix:
|
||
shard: [1, 2]
|
||
env:
|
||
# Explicit CI workers; the local default stays 2 (playwright.config.ts).
|
||
PLAYWRIGHT_WORKERS: 2
|
||
services:
|
||
postgres:
|
||
image: postgres:17-alpine
|
||
env:
|
||
POSTGRES_USER: teqo
|
||
POSTGRES_PASSWORD: teqo
|
||
POSTGRES_DB: teqo_test
|
||
ports:
|
||
- ${{ matrix.shard == 1 && '5435' || '5436' }}:5432
|
||
options: >-
|
||
--health-cmd "pg_isready -U teqo"
|
||
--health-interval 5s
|
||
--health-timeout 5s
|
||
--health-retries 12
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
- uses: pnpm/action-setup@v6
|
||
- uses: actions/setup-node@v5
|
||
with:
|
||
node-version: 24
|
||
cache: pnpm
|
||
- run: pnpm install --frozen-lockfile
|
||
- name: Cache Playwright browsers
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: ~/.cache/ms-playwright
|
||
key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
|
||
restore-keys: |
|
||
playwright-${{ runner.os }}-
|
||
- name: Install Playwright chromium
|
||
run: pnpm exec playwright install --with-deps chromium
|
||
- name: Prepare database URL (service via bridge gateway)
|
||
run: |
|
||
set -euo pipefail
|
||
DB_HOST=$(awk '$2 == "00000000" {a=$3; print strtonum("0x" substr(a,7,2)) "." strtonum("0x" substr(a,5,2)) "." strtonum("0x" substr(a,3,2)) "." strtonum("0x" substr(a,1,2)); exit}' /proc/net/route)
|
||
DB_PORT=${{ matrix.shard == 1 && '5435' || '5436' }}
|
||
echo "DATABASE_URL=postgresql://teqo:teqo@${DB_HOST}:${DB_PORT}/teqo_test" >> "$GITHUB_ENV"
|
||
# playwright re-loads .env.test over the process env, so the service
|
||
# URL must win through the .env.test.local layer (same mechanism
|
||
# `pnpm worktree next` uses). OPS50.
|
||
echo "DATABASE_URL=postgresql://teqo:teqo@${DB_HOST}:${DB_PORT}/teqo_test" > .env.test.local
|
||
- run: pnpm migrate
|
||
- run: pnpm db:seed:minimal
|
||
- name: Build for e2e
|
||
run: pnpm build
|
||
env:
|
||
# Same dir the Playwright webServer serves (playwright.config.ts
|
||
# falls back to '.next-e2e'; gate-ci.mjs builds there too).
|
||
NEXT_DIST_DIR: .next-e2e
|
||
- name: E2E tests (full suite, shard ${{ matrix.shard }})
|
||
# No `--` separator: pnpm would forward it verbatim to playwright and
|
||
# the flag would be parsed as a file pattern ("No tests found").
|
||
run: pnpm test:e2e --shard=${{ matrix.shard }}/2
|
||
|
||
checks:
|
||
name: checks
|
||
runs-on: ubuntu-latest
|
||
needs: [static, int, build, e2e]
|
||
if: always()
|
||
steps:
|
||
- name: All main verifier checks green
|
||
env:
|
||
NEEDS: ${{ toJSON(needs) }}
|
||
run: |
|
||
set -euo pipefail
|
||
echo "$NEEDS" | jq -e '
|
||
to_entries
|
||
| all(.value.result == "success" or .value.result == "skipped")
|
||
'
|
||
|
||
deploy:
|
||
name: deploy homeserver (teqo-1313)
|
||
# OPS53. Runs directly on the runner HOST (not a job container): the
|
||
# deploy needs the workstation's SSH key to reach the homeserver
|
||
# (`ssh homeserver`) and streams the whole remote build/migrate/rollout
|
||
# to this job's logs. Deliberately wired ONLY here — main window +
|
||
# workflow_dispatch — never in ci-pr.yml: a host job is code execution as
|
||
# `fsolla` on the workstation, and main only ever moves through a merged
|
||
# PR whose full suite was already green.
|
||
# OPS65: double-gated — the verifier rollup must be green AND the gate
|
||
# must have found a production change. The explicit `if` prevents both
|
||
# "deploy blind on a failed gate" and "deploy with a red suite" (a bare
|
||
# output condition would run despite failed needs).
|
||
needs: [checks, gate]
|
||
if: needs.checks.result == 'success' && needs.gate.outputs.production == 'true'
|
||
runs-on: host
|
||
timeout-minutes: 60
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
- name: Deploy teqo-1313 on the homeserver
|
||
run: |
|
||
set -euo pipefail
|
||
ssh homeserver "bash -s -- $GITHUB_SHA" < scripts/deploy-homeserver.sh
|