Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .agents/skills/github-prs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The rules on what may merge are in `AGENTS.md` ("Verifying", "Pull requests", "E
## 1. Before every commit

- **Never skip the hooks.** `make hooks` installs the pre-push hook (`make check-fast`); never push with `--no-verify` except in an emergency, and say so.
- Run what your change needs (the table is `docs/CI.md`, "What to run"): `make lint LINT_DIRS=<dirs>` and `make test TEST_PKGS=<pkgs>` for the Go packages it can affect (`scripts/affected.sh` prints them; `make check-fast` is the seconds-long pass), `make check-generated` for sqlc, templ or mock inputs, `make check-migrations` for a migration, `make deploy-check` for `deploy/`, `make actionlint` for workflows, `make release-smoke` for a Dockerfile or what it builds, `make ci` for a change to the tooling. Tests only at the test boundaries (`AGENTS.md`, "Test boundaries"); never a test in `deploy/` or the UI.
- **Default: `make check-pr`.** It runs what the branch's changes need (the table is `docs/CI.md`, "What to run"), fails when the affected-package selection does not match the diff, and prints the `make ci-local RAN="…"` line to attest with. By hand: `make lint LINT_DIRS=<dirs>` and `make test TEST_PKGS=<pkgs>` for the Go packages it can affect (`scripts/affected.sh` prints them; `make check-fast` is the seconds-long pass), `make check-generated` for sqlc, templ or mock inputs, `make check-migrations` for a migration, `make deploy-check` for `deploy/`, `make actionlint` for workflows, `make release-smoke` for a Dockerfile or what it builds, `make ci` for a change to the tooling. Tests only at the test boundaries (`AGENTS.md`, "Test boundaries"); never a test in `deploy/` or the UI.
- A change adds no lint or format findings, warnings included.
- Add the paths you changed; never `git add -A` in an old worktree.

Expand All @@ -22,7 +22,8 @@ After **every** push or rebase, once you have run what the change needs:

```bash
git push # pushed head, clean worktree
make ci-local RAN="make lint LINT_DIRS=./apps/web/... ; make test TEST_PKGS=./apps/web/internal/services"
make check-pr # runs what the change needs, prints the RAN line
make ci-local RAN="make lint LINT_DIRS='./apps/web/internal/services ...'; make test TEST_PKGS='...'; make secret-scan"
```

- It runs nothing and takes seconds. It refuses a dirty worktree, a detached HEAD (except `COMMIT=<sha>` of a `main` commit), a head that is not the pushed branch head, or a head that already has a failed `local-ci`.
Expand Down
5 changes: 3 additions & 2 deletions .claude/skills/github-prs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The rules on what may merge are in `AGENTS.md` ("Verifying", "Pull requests", "E
## 1. Before every commit

- **Never skip the hooks.** `make hooks` installs the pre-push hook (`make check-fast`); never push with `--no-verify` except in an emergency, and say so.
- Run what your change needs (the table is `docs/CI.md`, "What to run"): `make lint LINT_DIRS=<dirs>` and `make test TEST_PKGS=<pkgs>` for the Go packages it can affect (`scripts/affected.sh` prints them; `make check-fast` is the seconds-long pass), `make check-generated` for sqlc, templ or mock inputs, `make check-migrations` for a migration, `make deploy-check` for `deploy/`, `make actionlint` for workflows, `make release-smoke` for a Dockerfile or what it builds, `make ci` for a change to the tooling. Tests only at the test boundaries (`AGENTS.md`, "Test boundaries"); never a test in `deploy/` or the UI.
- **Default: `make check-pr`.** It runs what the branch's changes need (the table is `docs/CI.md`, "What to run"), fails when the affected-package selection does not match the diff, and prints the `make ci-local RAN="…"` line to attest with. By hand: `make lint LINT_DIRS=<dirs>` and `make test TEST_PKGS=<pkgs>` for the Go packages it can affect (`scripts/affected.sh` prints them; `make check-fast` is the seconds-long pass), `make check-generated` for sqlc, templ or mock inputs, `make check-migrations` for a migration, `make deploy-check` for `deploy/`, `make actionlint` for workflows, `make release-smoke` for a Dockerfile or what it builds, `make ci` for a change to the tooling. Tests only at the test boundaries (`AGENTS.md`, "Test boundaries"); never a test in `deploy/` or the UI.
- A change adds no lint or format findings, warnings included.
- Add the paths you changed; never `git add -A` in an old worktree.

Expand All @@ -22,7 +22,8 @@ After **every** push or rebase, once you have run what the change needs:

```bash
git push # pushed head, clean worktree
make ci-local RAN="make lint LINT_DIRS=./apps/web/... ; make test TEST_PKGS=./apps/web/internal/services"
make check-pr # runs what the change needs, prints the RAN line
make ci-local RAN="make lint LINT_DIRS='./apps/web/internal/services ...'; make test TEST_PKGS='...'; make secret-scan"
```

- It runs nothing and takes seconds. It refuses a dirty worktree, a detached HEAD (except `COMMIT=<sha>` of a `main` commit), a head that is not the pushed branch head, or a head that already has a failed `local-ci`.
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The most common defect is a change that works on the path you tested and is miss
- **`make check-fast` before every push (mandatory).** It runs gofmt, golangci-lint (whose `govet` runs `go vet`'s analyzers), the test-location check and plain `go test` (no `-race`) on only the packages your changes can affect, plus the generators whose inputs changed, the `deploy/` module (lint, names and `make deploy-vars`) when it, `.env.example` or the Makefile changed, the migration order when a migration changed (see "Migrations"), and `make vulncheck` when a `go.mod`, `go.sum`, `package.json` or `pnpm-lock.yaml` changed. Changes mean everything that differs from the merge base with origin/main: commits, staged, unstaged and untracked files, mapped to packages by `scripts/affected.sh` (`make affected` prints them), so a shared input (go.mod, tooling, lint config, migrations) checks everything. It takes seconds (a docs-only change: under a second; a full run: under 10 s warm), so it fits machines where a full `make ci` is not allowed. Database tests skip unless `TEST_DATABASE_URL` is set; `make test` runs them with `-race` against Postgres. `make hooks` installs a pre-push hook that runs it from every worktree of the clone (`make hooks-remove` undoes it; `git push --no-verify` skips it once, for emergencies only). Anything that runs git or go from a hook drops git's repository env first (`git rev-parse --local-env-vars`), as the hook and `scripts/check-fast.sh` do.
- **Release smoke** (`make release-smoke`; run it whenever a build input changes: a Dockerfile, or code a Dockerfile's binary is built from): builds every binary that has a Dockerfile with that Dockerfile's own build-stage `ENV` and `RUN` line (`scripts/dockerfile-builds.sh` reads them, so never copy build flags elsewhere) and fails on a dynamically linked one, runs `server migrate` and `admin migrate` on fresh databases, and boots web and admin with `APP_ENV=production` and only the config production requires until `/healthz` answers 200. It catches what tests cannot: an image that will not start on distroless (a dependency that links dynamically even with `CGO_ENABLED=0`), and a production config that refuses to boot without an optional integration. A new required production setting goes in its env list.
- `make lint test` before every commit when you can run the full suite. `make ci` runs every check on the checkout as it is: build, generated-code diff (sqlc, mocks, templ), gofmt + golangci-lint, the test-location check, `go test -race` against a throwaway Postgres with per-boundary coverage floors, and the probes that prove the layering and test rules still bite (`make lint-layering lint-tests`). `make vulncheck` (also in `make ci`) fails on any known vulnerability in a dependency of any Go module or the mobile lockfile ([docs/CI.md](docs/CI.md#known-vulnerabilities)).
- **A pull request is verified locally, on its exact head, then attested (mandatory; [docs/CI.md](docs/CI.md)).** Run what the change needs ("What to run" there): for Go, `make lint test` scoped with `LINT_DIRS`/`TEST_PKGS` from `scripts/affected.sh`, plus `make check-generated`, `make check-migrations`, `make deploy-check`, `make actionlint` or `make release-smoke` for what you touched, `make ci` for a change to the tooling. Commit, push, then `make ci-local RAN="<what you ran>"` in the clean worktree. It runs nothing and takes seconds: it refuses a dirty, unpushed or already-failed head, posts the `local-ci` commit status and fills the PR body's "Local verification" section with your statement, which is never edited by hand. Every push or rebase needs a new attestation. Stack PRs and merge right away.
- **A pull request is verified locally, on its exact head, then attested (mandatory; [docs/CI.md](docs/CI.md)).** Run what the change needs ("What to run" there): `make check-pr` runs it and prints the statement to attest with; by hand, for Go, `make lint test` scoped with `LINT_DIRS`/`TEST_PKGS` from `scripts/affected.sh`, plus `make check-generated`, `make check-migrations`, `make deploy-check`, `make actionlint` or `make release-smoke` for what you touched, `make ci` for a change to the tooling. Commit, push, then `make ci-local RAN="<what you ran>"` in the clean worktree. It runs nothing and takes seconds: it refuses a dirty, unpushed or already-failed head, posts the `local-ci` commit status and fills the PR body's "Local verification" section with your statement, which is never edited by hand. Every push or rebase needs a new attestation. Stack PRs and merge right away.
- **A failed head is final.** A failure is fixed forward with a new commit, never attested until green: a head attested as failed (`make ci-local FAILED="<what>"`) is refused for good by `make ci-local`, the `Local verification` check and `make pr-merge`. A failure in what the branch changed is fixed in the PR; any other is fixed forward at once in its own PR off `main` with a regression test that fails before the fix, and the branch rebases on it.
- GitHub runs no verification: on a PR only `Secret scan` and `Local verification` (which shows "Expected" until `make ci-local` claims the head), started by `make ci-local`'s body edit, and on `main` only `Deploy staging`, which ships a commit only when `make ci-local` attested it. Avoid adding workflow jobs: a new check is a make target the agent runs, listed in docs/CI.md "What to run". The PR jobs run only `main`'s code (`pull_request_target`) and read the head as data; never check out or run the head there ([docs/CI.md](docs/CI.md#trusted-code-only)).
- Run the narrowest thing first: `go test ./apps/web/internal/services/...`.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ secret-scan: ## gitleaks (pinned) on the files changed since the merge base, or
vulncheck: ## Known vulnerabilities: govulncheck (pinned) on every Go module + pnpm audit on the mobile lockfile; exceptions in scripts/vulncheck/allowlist.txt (ARGS=-go-only)
$(GO) run ./scripts/vulncheck $(ARGS)

.PHONY: check-pr
check-pr: ## Before make ci-local: run what this branch's changes need (docs/CI.md "What to run"), then print the RAN line (ARGS=--dry-run: only say what)
./scripts/check-pr.sh $(ARGS)

.PHONY: check-fast
check-fast: ## Before every push: gofmt, golangci-lint (incl. govet), plain tests for only what your changes vs origin/main affect (seconds)
./scripts/check-fast.sh
Expand Down
2 changes: 1 addition & 1 deletion docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ A push to `main` runs only `Deploy staging` (`deploy-staging.yml`), which deploy

### What to run

Run what your change needs on the head you attest, and nothing more. `scripts/affected.sh` (`make affected`) prints the Go dirs and packages a change can affect; `make check-fast` is the seconds-long pass over them.
Run what your change needs on the head you attest, and nothing more. **`make check-pr` is the default:** it runs the rows below that match the branch's changes (lint and `-race` tests on the affected packages, or `make ci` when a shared input changed), stops at the first failure, and prints the `make ci-local RAN="…"` line naming exactly what ran (`ARGS=--dry-run` only lists it). `scripts/affected.sh` (`make affected`) picks the Go dirs and packages: the changed packages and everything that imports them, or everything when go.mod, tooling, lint config, a migration or sqlc's config, queries or generated code changed. It fails, and so does everything built on it, when its selection does not match the diff: a changed Go file outside `deploy/` in no package, a changed package not selected, or Go changes and nothing selected. `make check-fast` is the seconds-long pre-push pass over the same packages.

| Changed | Run |
|---|---|
Expand Down
64 changes: 51 additions & 13 deletions scripts/affected.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
# and the LINT_DIRS/TEST_PKGS to run before make ci-local): the Go packages whose own files changed plus every
# package whose code or tests import them, transitively (Go's package graph
# via `go list -test -deps`). Changes to shared inputs (go.mod/go.sum,
# tooling, scripts, lint config, migrations, generator config) mean a full run.
# tooling, scripts, lint config, migrations, sqlc's config, queries and
# generated code) mean a full run: sqlc changes reach the database tests
# through the schema, not only through imports.
#
# A guard fails (exit 3) when the selection does not match the diff: a
# changed Go file outside deploy/ (its own module) that maps to no package, a
# changed package missing from the selection, or Go changes and nothing
# selected. A wrong selection would let make check-fast and make check-pr
# pass on code they never checked.
#
# Usage: scripts/affected.sh [<base>] (default: merge-base with origin/main,
# scripts/branches.sh)
Expand Down Expand Up @@ -38,19 +46,30 @@ out() {
if [ -n "${GITHUB_OUTPUT:-}" ]; then printf '%s=%s\n' "$1" "$2" >>"$GITHUB_OUTPUT"; fi
}

# sqlc inputs and outputs: every queries:/out: path in sqlc.yaml (schemas are
# migrations).
sqlcdir=packages/database
mapfile -t sqlcpaths < <(sed -nE 's/^[[:space:]]*(queries|out):[[:space:]]*([^[:space:]#]+).*/\2/p' "$sqlcdir/sqlc.yaml" |
while read -r p; do echo "$sqlcdir/${p%/}/"; done)

# Shared inputs: anything here can change every package's result.
# AFFECTED_FULL=1 forces a full run.
full=false
[ -n "${AFFECTED_FULL:-}" ] && full=true && echo "full run: AFFECTED_FULL" >&2
[ "$full" = true ] || for f in "${changed[@]}"; do
case $f in
go.mod | go.sum | mise.toml | Makefile | .golangci.yml | tools/* | scripts/* | \
*/migrations/* | packages/database/sqlc.yaml)
*/migrations/* | "$sqlcdir/sqlc.yaml")
full=true
echo "full run: $f" >&2
break
;;
esac
for p in "${sqlcpaths[@]}"; do
if [[ $f == "$p"* ]]; then full=true; fi
done
if [ "$full" = true ]; then
echo "full run: $f" >&2
break
fi
done

if [ "$full" = true ]; then
Expand All @@ -64,16 +83,9 @@ if [ "$full" = true ]; then
exit 0
fi

# sqlc inputs and outputs: every queries:/out: path in sqlc.yaml (schemas are
# migrations, which force a full run above).
sqlcdir=packages/database
mapfile -t sqlcpaths < <(sed -nE 's/^[[:space:]]*(queries|out):[[:space:]]*([^[:space:]#]+).*/\2/p' "$sqlcdir/sqlc.yaml" |
while read -r p; do echo "$sqlcdir/${p%/}/"; done)
# sqlc changes ran everything above; templ inputs and outputs.
sqlc=false templ=false
for f in "${changed[@]}"; do
for p in "${sqlcpaths[@]}"; do
if [[ $f == "$p"* ]]; then sqlc=true; fi
done
case $f in
*.templ | *_templ.go) templ=true ;;
esac
Expand All @@ -95,6 +107,7 @@ filemap=$(go list -e -f '{{$d := .Dir}}{{$p := .ImportPath}}{{range .GoFiles}}{{
dirmap=$(go list -e -f '{{.Dir}} {{.ImportPath}}' ./... | sed "s|^$PWD/||")

declare -A seeds=()
unmapped=()
for f in "${changed[@]}"; do
p=$(awk -v f="$f" '$1 == f { print $2; exit }' <<<"$filemap")
if [ -z "$p" ]; then
Expand All @@ -105,7 +118,13 @@ for f in "${changed[@]}"; do
d=$(dirname "$d")
done
fi
if [ -n "$p" ]; then seeds[$p]=1; fi
if [ -n "$p" ]; then
seeds[$p]=1
elif [[ $f == *.go && $f != deploy/* && -e $f ]]; then
# A deleted file of a deleted package maps to nothing, and needs nothing:
# its importers changed too, or they no longer build.
unmapped+=("$f")
fi
done

declare -A affected=()
Expand All @@ -124,6 +143,25 @@ if [ "${#seeds[@]}" -gt 0 ]; then
fi

pkgs=$(printf '%s\n' "${!affected[@]}" | sed '/^$/d' | sort)

# Guard: the selection must cover the diff.
problems=()
for f in "${unmapped[@]}"; do problems+=("$f is a changed Go file in no package of $mod"); done
for p in "${!seeds[@]}"; do
[ -n "${affected[$p]:-}" ] || problems+=("$p changed but is not selected")
done
gochanged=false
for f in "${changed[@]}"; do
# Existing files: a deleted one in a live package maps to it above, and a
# deleted package with no importers left needs nothing checked.
if [[ $f == *.go && $f != deploy/* && -e $f ]]; then gochanged=true; fi
done
if [ "$gochanged" = true ] && [ -z "$pkgs" ]; then problems+=("Go files changed but no package is selected"); fi
if [ "${#problems[@]}" -gt 0 ]; then
echo "affected: the selection does not match the diff (run everything: AFFECTED_FULL=1, or make ci):" >&2
printf ' %s\n' "${problems[@]}" >&2
exit 3
fi
dirs=$(sed "s|^$mod|.|" <<<"$pkgs")

# go:generate: packages whose directive source or -destination output changed.
Expand Down
Loading
Loading