mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-17 04:23:07 +00:00
356 lines
15 KiB
YAML
356 lines
15 KiB
YAML
# Post-merge verifier on `main`: always the FULL suite (no affected skips).
|
||
# When green, deploys production via `vercel deploy --prod` (Vercel Git builds
|
||
# are ignored — see scripts/vercel-ignore-build.sh). If HEAD moved while this
|
||
# run was in flight, `requeue` dispatches another run for the new tip.
|
||
#
|
||
# 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:
|
||
push:
|
||
branches: [main]
|
||
workflow_dispatch:
|
||
|
||
env:
|
||
PAYLOAD_SECRET: test-only-secret-not-used-in-production
|
||
NEXT_PUBLIC_SITE_URL: http://localhost:3000
|
||
|
||
jobs:
|
||
static:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 20
|
||
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
|
||
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
|
||
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
|
||
# 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:
|
||
runs-on: ubuntu-latest
|
||
needs: [checks]
|
||
if: needs.checks.result == 'success'
|
||
# pull → local `vercel build` (pnpm install + Next/Payload build against prod env) → upload.
|
||
timeout-minutes: 35
|
||
outputs:
|
||
stale: ${{ steps.tip.outputs.stale || 'false' }}
|
||
cooldown: ${{ steps.cooldown.outputs.active || 'false' }}
|
||
wait_seconds: ${{ steps.cooldown.outputs.wait_seconds || '0' }}
|
||
env:
|
||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
- name: Guard stale HEAD
|
||
id: tip
|
||
run: |
|
||
set -euo pipefail
|
||
git fetch origin main --quiet
|
||
tip=$(git rev-parse origin/main)
|
||
if [ "$tip" != "$GITHUB_SHA" ]; then
|
||
echo "Skip deploy: origin/main is $tip, this run verified $GITHUB_SHA"
|
||
echo "stale=true" >> "$GITHUB_OUTPUT"
|
||
exit 0
|
||
fi
|
||
echo "stale=false" >> "$GITHUB_OUTPUT"
|
||
# Cooldown script is plain Node — no pnpm. Disable package-manager-cache
|
||
# here: setup-node@v5 defaults to true and looks for pnpm before action-setup.
|
||
- uses: actions/setup-node@v5
|
||
if: steps.tip.outputs.stale != 'true'
|
||
with:
|
||
node-version: 24
|
||
package-manager-cache: false
|
||
- name: Require Vercel credentials
|
||
if: steps.tip.outputs.stale != 'true'
|
||
run: |
|
||
set -euo pipefail
|
||
missing=()
|
||
[ -z "${VERCEL_TOKEN:-}" ] && missing+=(VERCEL_TOKEN)
|
||
[ -z "${VERCEL_ORG_ID:-}" ] && missing+=(VERCEL_ORG_ID)
|
||
[ -z "${VERCEL_PROJECT_ID:-}" ] && missing+=(VERCEL_PROJECT_ID)
|
||
if [ "${#missing[@]}" -gt 0 ]; then
|
||
echo "::error::Missing repo secrets for gated deploy: ${missing[*]}. Add them under Settings → Secrets, then re-run this workflow."
|
||
exit 1
|
||
fi
|
||
# Fail closed on obvious paste mistakes (must be team_/prj_ from .vercel/project.json).
|
||
case "$VERCEL_ORG_ID" in team_*) ;; *)
|
||
echo "::error::VERCEL_ORG_ID must look like team_… (from .vercel/project.json after vercel link)."
|
||
exit 1
|
||
;;
|
||
esac
|
||
case "$VERCEL_PROJECT_ID" in prj_*) ;; *)
|
||
echo "::error::VERCEL_PROJECT_ID must look like prj_… (from .vercel/project.json after vercel link)."
|
||
exit 1
|
||
;;
|
||
esac
|
||
- name: Check deploy cooldown
|
||
id: cooldown
|
||
if: steps.tip.outputs.stale != 'true'
|
||
run: node scripts/vercel-deploy-cooldown.mjs
|
||
- name: Log deploy deferral
|
||
if: steps.tip.outputs.stale != 'true' && steps.cooldown.outputs.active == 'true'
|
||
run: |
|
||
echo "Deploy deferred: last production deploy is younger than 15 minutes."
|
||
echo "Requeue will retry in ${{ steps.cooldown.outputs.wait_seconds }}s."
|
||
# `vercel build` shells out to pnpm (packageManager in package.json); without
|
||
# these steps the runner only has npm → spawn pnpm ENOENT.
|
||
- uses: pnpm/action-setup@v6
|
||
if: steps.tip.outputs.stale != 'true' && steps.cooldown.outputs.active != 'true'
|
||
- uses: actions/setup-node@v5
|
||
if: steps.tip.outputs.stale != 'true' && steps.cooldown.outputs.active != 'true'
|
||
with:
|
||
node-version: 24
|
||
cache: pnpm
|
||
- name: Install Vercel CLI
|
||
if: steps.tip.outputs.stale != 'true' && steps.cooldown.outputs.active != 'true'
|
||
run: npm install --global vercel@55
|
||
- name: Deploy production
|
||
if: steps.tip.outputs.stale != 'true' && steps.cooldown.outputs.active != 'true'
|
||
run: |
|
||
set -euo pipefail
|
||
# Workflow-level env points at the CI teqo_test service. Drop it so
|
||
# `vercel build` uses `.vercel/.env.production.local` from `vercel pull`
|
||
# (otherwise Payload migrate hits 127.0.0.1:5432 → ECONNREFUSED).
|
||
unset DATABASE_URL PAYLOAD_SECRET NEXT_PUBLIC_SITE_URL
|
||
# Canonical CI link (Vercel KB): env VERCEL_*_ID + pull → build → deploy --prebuilt.
|
||
# "Could not retrieve Project Settings" usually means bad/expired token or wrong IDs (403).
|
||
vercel pull --yes --environment=production --token="$VERCEL_TOKEN"
|
||
vercel build --prod --token="$VERCEL_TOKEN"
|
||
# stdout is always the deployment URL (CLI contract). Capture it — do not
|
||
# pipe the whole CLI log or the exit code / URL get lost.
|
||
deploy_url=$(vercel deploy --prebuilt --prod --archive=tgz --token="$VERCEL_TOKEN")
|
||
echo "Deployed: $deploy_url"
|
||
# Git auto-deploy OFF is intentional. If "Auto-assign Custom Production
|
||
# Domains" is also OFF, --prod only stages *.vercel.app and leaves
|
||
# pt.jorgesolla.com.br on the previous Current — promote + verify here.
|
||
node scripts/vercel-ensure-production-alias.mjs "$deploy_url"
|
||
# Docs: promote staged production, then alias (Git Integration is OFF by design).
|
||
vercel promote "$deploy_url" --token="$VERCEL_TOKEN" --scope="$VERCEL_ORG_ID" || true
|
||
# `--yes` is only valid for `alias rm`, not `alias set` (CLI 55).
|
||
vercel alias set "$deploy_url" pt.jorgesolla.com.br --token="$VERCEL_TOKEN" --scope="$VERCEL_ORG_ID"
|
||
|
||
requeue:
|
||
runs-on: ubuntu-latest
|
||
needs: [checks, deploy]
|
||
if: always()
|
||
timeout-minutes: 40
|
||
steps:
|
||
- uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
- name: Re-dispatch if main advanced or deploy deferred
|
||
env:
|
||
DEPLOY_RESULT: ${{ needs.deploy.result }}
|
||
DEPLOY_COOLDOWN: ${{ needs.deploy.outputs.cooldown }}
|
||
DEPLOY_WAIT_SECONDS: ${{ needs.deploy.outputs.wait_seconds }}
|
||
run: |
|
||
set -euo pipefail
|
||
git fetch origin main --quiet
|
||
tip=$(git rev-parse origin/main)
|
||
if [ "$tip" != "$GITHUB_SHA" ]; then
|
||
echo "origin/main moved to $tip (verified $GITHUB_SHA) — requeue ci.yml"
|
||
node scripts/forgejo-dispatch.mjs ci.yml main
|
||
exit 0
|
||
fi
|
||
if [ "${DEPLOY_RESULT:-}" != "success" ]; then
|
||
echo "Deploy job did not succeed (${DEPLOY_RESULT:-skipped}) — idle"
|
||
exit 0
|
||
fi
|
||
if [ "${DEPLOY_COOLDOWN:-}" = "true" ]; then
|
||
wait="${DEPLOY_WAIT_SECONDS:-0}"
|
||
echo "Deploy deferred by cooldown — waiting ${wait}s then requeue ci.yml"
|
||
sleep "$wait"
|
||
git fetch origin main --quiet
|
||
tip=$(git rev-parse origin/main)
|
||
if [ "$tip" != "$GITHUB_SHA" ]; then
|
||
echo "main advanced during cooldown wait ($tip) — requeue for new tip"
|
||
else
|
||
echo "Cooldown elapsed for $GITHUB_SHA — requeue ci.yml"
|
||
fi
|
||
node scripts/forgejo-dispatch.mjs ci.yml main
|
||
exit 0
|
||
fi
|
||
echo "HEAD still $GITHUB_SHA — idle"
|