Files
CatoandClaude Opus 5.5 6a3be90d97 chore(ci): one check per change — remove the merge sweep, check on PRs only (#336)
Removes the fleet auto-merge sweep caller (and wake chain where present);
checks run on pull requests only, not again after merging; a deploy that
waited for CI on main now deploys on push. The forge merge check
(forge/verify) verifies each PR on its merge result and merges it.

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 05:13:43 +01:00

220 lines
9.8 KiB
YAML

name: CI
# WHY THIS FILE EXISTS, AND WHY IT IS NOT OPTIONAL
#
# loki's ci-gate.sh treats "CI green" and "no CI at all" identically —
# both exit 0 and let the deploy proceed. That is a sane default for a repo
# that has not set CI up yet, and it means a site WITHOUT this file deploys
# every push completely unverified while looking exactly like one that passed.
#
# Substrata shipped to production that way. So the scaffold emits this file with
# every new site: the gate has something real to wait for from the first commit.
#
# Runs the same bundle as `pnpm run verify` locally — one definition of verified.
on:
pull_request:
branches: [main]
workflow_dispatch: {}
# A newer push supersedes an older run. ci-gate.sh understands cancelled-and-
# superseded as a clean skip rather than a failure.
#
# THE GROUP IS PER COMMIT ON MAIN. Per branch, every main run queued behind the
# one before it: a ~10-minute run per merge, one at a time, and one run waited
# 31 minutes just to start (CI speed audit, 2026-10-27). Per commit, two merges
# run side by side, and a re-armed dispatch for the SAME commit still queues
# behind its push run instead of racing it. Cancelling stays off on main for the
# reason above.
concurrency:
group: ci-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || 'branch' }}
# Supersede freely on a branch nobody gates on — that is what the setting is
# for, and a PR pushed three times in a minute should not run CI three times.
#
# NEVER on main. Deploy waits for "CI green on this commit" and reads the
# LATEST CI run for the SHA. The auto-merge sweep re-arms ci.yml on a cadence,
# so a merge to main reliably produced a green run followed by a cancelled
# one, and the deploy then refused a commit whose CI had actually passed.
# That blocked two deploys before anyone read the run list closely enough to
# notice the green run sitting directly underneath the cancelled one.
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 15
# A real Postgres, because the store tests are about things only a database
# has an opinion about: an upsert that would violate a primary key, a
# cascade that has to actually cascade, jsonb that must come back an object
# rather than a string. Mocking it would assert that the mock agrees with
# itself. 17 matches the box.
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: heidi
POSTGRES_PASSWORD: heidi
POSTGRES_DB: heidi_test
ports:
- 5432:5432
# Without this the job races the container and the first query fails
# with ECONNREFUSED on a cold runner.
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgresql://heidi:heidi@localhost:5432/heidi_test
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: pnpm
# --frozen-lockfile: the lockfile is the contract, and a resolution that
# drifts from it is how a dependency silently changes.
- run: pnpm install --frozen-lockfile
# MERGE → LIVE: ONE FULL PROOF PER CHANGE, ON THE PULL REQUEST.
#
# A squash merge onto main has already passed everything below on its PR,
# so running it all again only doubles merge→live: 9.6 minutes median from
# merge to green main, of which about 7 repeated the PR (tests, layout and
# overlay audits). A main tip whose subject names a PR — squash merges end
# in `(#N)` — gets the fast gate: type-check, lint, file-input check.
# Pull requests and any main push WITHOUT `(#N)` (someone pushing straight
# to main) still get everything. Same rule as bitbaum/loki's ci.yml.
#
# Deploy builds the site on the box, so the build here is a PR-only proof.
- name: Choose the gate
id: gate
env:
EVENT: ${{ github.event_name }}
REF: ${{ github.ref }}
run: |
set -euo pipefail
subject=$(git log -1 --format=%s)
if [ "$EVENT" != "pull_request" ] && [ "$REF" = "refs/heads/main" ] && echo "$subject" | grep -Eq '\(#[0-9]+\)'; then
echo "main tip looks like a PR merge ($subject) — fast gate (verify:main)"
echo "fast=true" >> "$GITHUB_OUTPUT"
else
echo "full gate (event=$EVENT, subject: $subject)"
echo "fast=false" >> "$GITHUB_OUTPUT"
fi
# Next keeps its compiler output in .next/cache, and this job BUILDS. With
# nothing restoring it, every run of every scaffolded site recompiles from
# scratch — and the deploy then compiles a second time.
#
# This file is the third copy of the golden CI floor. The other two live in
# fleet/templates/ci/, and they gained this step on 2026-09-07 when a fleet
# sweep found 14 of 32 repos building cold. This one is the copy the
# scaffold ACTUALLY uses, so it was the one that mattered and the one that
# was missed — every site created between then and now started cold by
# construction. Held fleet-wide by fleet's cicd-hygiene-audit.sh, but that
# ratchet can only flag a repo after it exists; a template fixes it before.
#
# Keyed on the lockfile so a dependency change invalidates it. The bare
# restore-key is last on purpose: a stale cache still beats no cache, and
# Next validates its own entries rather than trusting them.
- name: Cache Next.js build
if: steps.gate.outputs.fast != 'true'
uses: actions/cache@v6
with:
path: .next/cache
key: nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
restore-keys: |
nextjs-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
nextjs-${{ runner.os }}-
# The same migrations the deploy applies, so the tests run against the
# schema that is about to ship rather than one written out by hand here.
- name: Apply migrations
if: steps.gate.outputs.fast != 'true'
run: |
for f in drizzle/[0-9]*.sql; do
echo "applying $f"
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -q -f "$f"
done
# `verify` verbatim — type-check, lint AND test. This job used to run the
# first two as separate steps and never ran the third, so the entire unit
# suite passed only on the machine of whoever remembered to run it. That
# is the one failure mode a CI floor exists to prevent, and it is exactly
# why the house rule is that CI calls the repo's own verify script rather
# than a hand-maintained copy of what it is thought to contain.
- name: Verify
run: |
if [ "${{ steps.gate.outputs.fast }}" = "true" ]; then
pnpm run verify:main
else
pnpm run verify
fi
# The build is the real test for a content site: a broken import or a bad
# config surfaces here and nowhere earlier.
- name: Build
if: steps.gate.outputs.fast != 'true'
run: pnpm run build
# THE LAYOUT CHECK RUNS HERE, and it has to be here rather than in
# `verify`, which deliberately needs neither a server nor a browser.
#
# It earns the two minutes. Horizontal overflow is a layout fact — real
# glyphs, real font, real viewport — so no amount of reading the source
# finds it, and this repository shipped it three separate times: the
# chat transcript, `/portal`, and the header the day an avatar was added
# to it. Each was reported from a phone, by a person, after it was live.
# An opt-in script nobody remembers to run would have caught none of
# them.
# Shared fleet step: --with-deps, falling back to the browser alone when
# apt cannot reach Ubuntu's archive (the 2026-11-11 outage).
- name: Install Chromium for the layout audit
if: steps.gate.outputs.fast != 'true'
uses: bitbaum/fleet/.github/actions/install-chromium@main
# With accounts ON, so the audits below measure the header production
# serves. Without a session secret the bar renders no sign-in control,
# and every layout audit here measured a header 100-odd pixels narrower
# than the real one — how a French header 10px too wide reached
# production (site-header.tsx). A throwaway secret per run: there are no
# real accounts in this database.
- name: Start the built site
if: steps.gate.outputs.fast != 'true'
run: |
BETTER_AUTH_SECRET="$(openssl rand -base64 48)" pnpm run start &
npx --yes wait-on -t 60000 http://127.0.0.1:3000/de
# Three languages rather than seven, and light only: the widths and the
# scripts are what find things (Russian is the longest, and 320px is
# where the header runs out), and the full matrix is a local command for
# when something here goes red.
- name: Layout audit
if: steps.gate.outputs.fast != 'true'
run: pnpm run audit:responsive
env:
BASE: http://127.0.0.1:3000
LOCALES: de,fr,ru
WIDTHS: 320,360,390
THEMES: light
# Every disclosure opened and checked for being on top. The header's
# menus were drawn under the chat's conversation list on desktop and no
# check noticed, because every other check looks at pages with
# everything shut. Dark as well as light: it was reported in dark.
- name: Overlay audit
if: steps.gate.outputs.fast != 'true'
run: pnpm run audit:overlays
env:
BASE: http://127.0.0.1:3000
WIDTHS: 1440,390
THEMES: light,dark