# 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 (`check`, runs-on host, no pnpm) classifies whether # anything that would enter the docker build context changed since the SHA # running on the homeserver (read from `~/stack/docker-compose.yml` over ssh). # - No production change → suite + deploy skip; the run stays green # (the `checks` rollup already accepts skipped jobs). # - Production change → 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. # # Gate fail-open: an unreadable deployed SHA or an ssh failure makes `check` # report production=true, so the suite ALWAYS verifies main. The deploy job # only runs when the gate succeeded AND production changed AND checks are # green — never deploy blind. A gate failure self-heals on the next window # (the diff is re-evaluated against the same deployed SHA). # # 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: check: name: check 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 # ..HEAD. Runs every window; the suite jobs below consume # its `production` output. Deliberately wired ONLY here — main + dispatch # — never in ci-pr.yml (host job = code execution as `fsolla`). runs-on: host timeout-minutes: 10 outputs: production: ${{ steps.classify.outputs.production }} steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - name: Read deployed SHA and classify production change id: classify run: | set -euo pipefail deployed_sha="$(ssh homeserver "grep -oE 'image: teqo-1313:[0-9a-f]+' ~/stack/docker-compose.yml | sed -E 's/.*://' | head -1" 2>/dev/null || true)" echo "deployed_sha: ${deployed_sha:-}" node scripts/ci-classify-production.mjs --deployed "$deployed_sha" echo "production=$(node scripts/ci-classify-production.mjs --deployed "$deployed_sha" --value)" >> "$GITHUB_OUTPUT" static: runs-on: ubuntu-latest timeout-minutes: 20 needs: [check] # Fail-open: an errored gate never skips the verifier; only a gate that # succeeded AND found no production change skips the suite. if: needs.check.result != 'success' || needs.check.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: [check] if: needs.check.result != 'success' || needs.check.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: [check] if: needs.check.result != 'success' || needs.check.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: [check] if: needs.check.result != 'success' || needs.check.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, check] if: needs.checks.result == 'success' && needs.check.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