diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ca90c0b..48824065 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,9 +39,10 @@ jobs: # Every step below runs a justfile recipe, named after it. Reproduce any # failure locally with the command in the step name — nothing about the gate - # lives only in this file. - gate: - name: Gate + # lives only in this file. `just check` is check-static plus the Go and UI + # unit suites; CI runs those three in parallel and adds the race suite. + static: + name: Static checks runs-on: ubuntu-24.04 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -72,8 +73,8 @@ jobs: cache: npm cache-dependency-path: site/package-lock.json - # `--help` installs the pinned binary without linting; `just check` runs - # the real thing, so local and CI share one invocation. + # `--help` installs the pinned binary without linting; `just check-static` + # runs the real thing, so local and CI share one invocation. - uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: version: v2.14.0 @@ -82,22 +83,93 @@ jobs: - name: just ui-deps run: just ui-deps - # `just check` ends with site-build, which cannot run without these. - # Without it the gate fails as exit 127 — `astro: not found` — which reads + # check-static ends with site-build, which cannot run without these. + # Without it the job fails as exit 127 — `astro: not found` — which reads # like a broken runner rather than a missing install. - name: just site-deps run: just site-deps - # fmt-check, lint, dependency audit, UI asset freshness, and - # backend/frontend tests. - # lefthook runs on push. - - name: just check - run: just check + # fmt-check, lint, dependency audit, UI asset freshness, docs and site. + - name: just check-static + run: just check-static + + - name: just ui-test + run: just ui-test + + # The plain suite keeps the allocation and memory ceilings that only build + # without the race detector (`//go:build !race`). + go-test: + name: Go tests + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum + - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4 + - name: just test + run: just test + + race-shards: + name: Race shards + runs-on: ubuntu-24.04 + outputs: + shards: ${{ steps.shards.outputs.shards }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - id: shards + run: echo "shards=$(bash scripts/go-race-shards.sh json)" >> "$GITHUB_OUTPUT" + + # The slowest packages each get a runner; scripts/go-race-shards.sh owns the + # split, and its "rest" shard takes every other package. + go-race: + name: Go race (${{ matrix.shard }}) + needs: race-shards + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + shard: ${{ fromJSON(needs.race-shards.outputs.shards) }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum + - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4 + - name: just test-race $(scripts/go-race-shards.sh ${{ matrix.shard }}) + env: + SHARD: ${{ matrix.shard }} + run: | + set -euo pipefail + packages=$(bash scripts/go-race-shards.sh "$SHARD") + # shellcheck disable=SC2086 # one argument per package + just test-race $packages - # Re-runs the suite under the race detector. Kept out of `check` so the - # local pre-push hook stays fast. - - name: just test-race - run: just test-race + # The required check. A required job that is skipped counts as passed, so + # this one always runs and fails unless every part succeeded. + gate: + name: Gate + needs: [static, go-test, race-shards, go-race] + if: always() + runs-on: ubuntu-24.04 + steps: + - env: + RESULTS: ${{ join(needs.*.result, ' ') }} + run: | + echo "results: ${RESULTS}" + for result in ${RESULTS}; do + [ "${result}" = success ] || exit 1 + done # The performance spec runs in its own job so neither group nears Playwright's # 12-minute global timeout; one worker keeps its timings uncontended. @@ -109,10 +181,21 @@ jobs: fail-fast: false matrix: include: - - group: smoke and accessibility - slug: smoke + # The suite runs on one worker, and most of its time is the 1100 + # viewport's accessibility and smoke specs, so each 1100 scheme gets a + # runner and the 1440 viewport shares one with the short MCP specs. + - group: smoke and accessibility (1100 light) + slug: smoke-1100-light + skip_performance: "1" + args: --project=app-1100-light + - group: smoke and accessibility (1100 dark) + slug: smoke-1100-dark skip_performance: "1" - args: --project=app-1100-light --project=app-1100-dark --project=app-1440-light --project=app-1440-dark --project=mcp + args: --project=app-1100-dark + - group: smoke and accessibility (1440, MCP) + slug: smoke-1440-mcp + skip_performance: "1" + args: --project=app-1440-light --project=app-1440-dark --project=mcp - group: performance slug: performance skip_performance: "" @@ -140,7 +223,7 @@ jobs: - name: just ui-deps run: just ui-deps - name: just e2e-browsers - if: matrix.slug == 'smoke' || matrix.slug == 'catalog' + if: startsWith(matrix.slug, 'smoke') || matrix.slug == 'catalog' run: just e2e-browsers - name: just design-check if: matrix.slug == 'catalog' @@ -192,11 +275,11 @@ jobs: retention-days: 7 # Build the exact runtime image on pull requests and reject high/critical OS, - # Go-binary, or embedded-secret findings before merge. + # Go-binary, or embedded-secret findings before merge. It runs beside Gate + # rather than after it; both are required. container-scan: name: Container scan if: github.event_name == 'pull_request' - needs: gate runs-on: ubuntu-24.04 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e689b2e0..12d5538a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,10 @@ jobs: verify: name: verify release source runs-on: ubuntu-24.04 + permissions: + contents: read + # Reads the CI run for the tagged commit. + actions: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -79,6 +83,20 @@ jobs: name: upgrade-notes path: ${{ runner.temp }}/upgrade-notes.md if-no-files-found: error + # The tag is on main (checked above), and CI's push run on main already + # ran every check and the race suite on this exact commit. Reuse that + # result; run the suites here only when no such run passed, for example + # when a newer push cancelled it. + - name: Find CI's result for this commit + id: ci + env: + GH_TOKEN: ${{ github.token }} + run: | + if bash scripts/ci-passed.sh "${GITHUB_SHA}"; then + echo "passed=true" >> "${GITHUB_OUTPUT}" + else + echo "passed=false" >> "${GITHUB_OUTPUT}" + fi - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version-file: go.mod @@ -89,12 +107,18 @@ jobs: with: bun-version: 1.4.2 - uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 + if: steps.ci.outputs.passed != 'true' with: version: v2.14.0 args: --help - run: just ui-deps - - run: just check - - run: just test-race + # The advisory database changes over time, so the audit runs at release + # even when CI's result is reused. + - run: just ui-audit + - if: steps.ci.outputs.passed != 'true' + run: just check + - if: steps.ci.outputs.passed != 'true' + run: just test-race # DuckDB needs CGO and this repository carries no cross toolchain, so every # binary is built on a runner of its own architecture. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 37bd3579..96fab4e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,8 @@ suite. See [browser smoke testing](docs/testing.md) for coverage and failure art `just install` also installs [Lefthook](https://lefthook.dev)'s Git hooks, which run formatting and linting on commit and the full gate on push. The pre-push hook may be skipped when Lefthook detects no changed files; -CI runs the same `just check` unconditionally and enforces the gate. +CI runs the same checks unconditionally, split into parallel jobs plus the race +suite, and enforces the gate. The browser workspace uses `package.json` overrides for transitive security fixes that their direct dependencies have not locked yet. Keep those overrides diff --git a/docs/release.md b/docs/release.md index 44aaecc3..f786464b 100644 --- a/docs/release.md +++ b/docs/release.md @@ -64,11 +64,14 @@ steps in its description, so they can be copied into the notes. Run `just release` from a clean, current `main`. The script: 1. verifies that no other release is running; -2. runs `just check` and the race-enabled Go suite; -3. confirms that neither local `HEAD` nor `origin/main` moved during testing; +2. waits for CI's push run on `main` for that commit, which runs every check and + the race-enabled Go suite, and stops unless it passed; +3. confirms that neither local `HEAD` nor `origin/main` moved meanwhile; 4. calculates and pushes the next CalVer tag. -The tag workflow then independently validates tag syntax, ancestry, and ordering; +The tag workflow then independently validates tag syntax, ancestry, and ordering. +It reuses that CI result for the tagged commit, re-running only the dependency +audit, and runs the full suites itself when no successful run exists. It then builds every target on its native runner; publishes the multi-architecture image; copies that accepted manifest to Docker Hub; requires the registry digests to match; and creates the GitHub release only after anonymous pulls from both GHCR diff --git a/justfile b/justfile index 6e10573e..91094593 100644 --- a/justfile +++ b/justfile @@ -191,8 +191,8 @@ test *ARGS='./...': # that alignment check — the -race data-race detector stays on. # Run the Go tests under the race detector. -test-race: - bash scripts/with-duckdb.sh go test -race -gcflags=all=-d=checkptr=0 ./... +test-race *ARGS='./...': + bash scripts/with-duckdb.sh go test -race -gcflags=all=-d=checkptr=0 {{ARGS}} # Opt-in wall-clock acceptance; deterministic work bounds remain in test. fanql-perf: @@ -359,14 +359,18 @@ social-card: # ── Gate ───────────────────────────────────────────────────────────────────── -# lefthook's pre-push hook and CI both run this. +# lefthook's pre-push hook runs this; CI runs the same three parts in parallel +# jobs and adds the race suite. +check: check-static test ui-test + @echo "All checks passed" + +# Everything in `check` except the Go and UI unit suites. # # docs-generate-check comes before the site build for the same reason it exists: # a settings page that no longer matches the type the loader binds is a # documented setting the binary would reject, and it should fail here rather # than be published. -check: script-tests dashboard-eval-generate-check test-names-check go-deadcode ui-deadcode fmt-check ui-boundaries-check lint release-test duckdb-wrapper-test ui-audit ui-check notices-check test ui-test docs-generate-check site-build - @echo "All checks passed" +check-static: script-tests dashboard-eval-generate-check test-names-check go-deadcode ui-deadcode fmt-check ui-boundaries-check lint release-test duckdb-wrapper-test ui-audit ui-check notices-check docs-generate-check site-build clean: rm -rf bin diff --git a/lefthook.yml b/lefthook.yml index c4ca6fc7..d9f98ee0 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -55,6 +55,6 @@ pre-push: # filters pre-push jobs by its own changed-file detection and skips when # that set is empty, which is deliberate (`lefthook run --force` overrides # it). Treat this hook as a fast local convenience, not a guarantee — CI - # runs the same `just check` unconditionally, and that is the gate that - # actually enforces it. + # runs the same checks unconditionally in parallel jobs, and that is the + # gate that actually enforces it. run: just check diff --git a/scripts/ci-passed.sh b/scripts/ci-passed.sh new file mode 100755 index 00000000..6d82f25a --- /dev/null +++ b/scripts/ci-passed.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# Exits 0 when CI's push run on main for exactly this commit succeeded, +# including its Gate job; exits 1 otherwise. +# +# A release tag can only point at a main commit, and main only advances +# through pull requests whose Gate passed, so a successful push run on the +# same commit verified the same tree the release builds. The release reuses +# that result instead of running the suites again. +# +# ci-passed.sh [--wait] +# +# --wait follows a run that is still in progress instead of failing. +set -euo pipefail + +wait=0 +if [ "${1:-}" = --wait ]; then + wait=1 + shift +fi +sha=${1:?usage: ci-passed.sh [--wait] } +[[ "$sha" =~ ^[0-9a-f]{40}$ ]] || { + echo "ci-passed: ${sha} is not a full commit SHA" >&2 + exit 1 +} +repo=${GITHUB_REPOSITORY:-$(gh repo view --json nameWithOwner --jq .nameWithOwner)} + +# Seconds to wait for CI to register the push run before giving up. +registration=300 + +while :; do + runs=$(gh api "repos/${repo}/actions/workflows/ci.yml/runs?head_sha=${sha}&event=push&branch=main&per_page=20" \ + --jq ".workflow_runs[] | select(.head_sha == \"${sha}\" and .head_branch == \"main\" and .event == \"push\") | \"\(.id) \(.status) \(.conclusion)\"") + + passed=$(awk '$2 == "completed" && $3 == "success" { print $1; exit }' <<<"$runs") + if [ -n "$passed" ]; then + gate=$(gh api "repos/${repo}/actions/runs/${passed}/jobs?per_page=100" \ + --jq '[.jobs[] | select(.name == "Gate") | .conclusion] | join(" ")') + if [ "$gate" = success ]; then + echo "ci-passed: CI run ${passed} passed for ${sha}" >&2 + exit 0 + fi + echo "ci-passed: CI run ${passed} succeeded but its Gate reads '${gate}'" >&2 + exit 1 + fi + + pending=$(awk '$2 != "completed" { print $1; exit }' <<<"$runs") + if [ "$wait" = 1 ] && [ -n "$pending" ]; then + echo "ci-passed: waiting for CI run ${pending} on ${sha}" >&2 + # A watch that fails at once (an API error) must not turn into a busy loop. + gh run watch "$pending" --repo "$repo" --interval 30 >/dev/null || sleep 30 + continue + fi + # Just after a push, CI may not have registered the run yet. + if [ "$wait" = 1 ] && [ -z "$runs" ] && ((registration > 0)); then + echo "ci-passed: waiting for CI to start on ${sha}" >&2 + sleep 15 + registration=$((registration - 15)) + continue + fi + + echo "ci-passed: no successful CI push run on main for ${sha}" >&2 + exit 1 +done diff --git a/scripts/go-race-shards.sh b/scripts/go-race-shards.sh new file mode 100755 index 00000000..a0e6ad6c --- /dev/null +++ b/scripts/go-race-shards.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Splits the Go packages into shards for CI's race suite. +# +# The slowest packages each run alone; "rest" holds every other package, so +# the shards cover `go list ./...` exactly by construction. A new package lands +# in "rest" without any change here. +# +# go-race-shards.sh json shard names as a JSON array, for a CI matrix +# go-race-shards.sh that shard's import paths, one per line +set -euo pipefail + +# Measured on CI's 4-vCPU runner; each takes 5 to 7 minutes under -race. +readonly isolated=(fanql query telemetry engine mcp api) + +cd "$(dirname "$0")/.." + +shard=${1:?usage: go-race-shards.sh json | } + +if [ "$shard" = json ]; then + printf '[' + for name in "${isolated[@]}"; do printf '"%s",' "$name"; done + printf '"rest"]\n' + exit 0 +fi + +module=$(go list -m) +# Through the wrapper, so the listing uses the same build tags as the tests +# and never fetches the dynamic library modules they do not use. +packages=$(bash scripts/with-duckdb.sh go list ./...) + +if [ "$shard" = rest ]; then + exclude=$(printf "${module}/internal/%s\n" "${isolated[@]}") + grep -vxF -f <(printf '%s\n' "$exclude") <<<"$packages" + exit 0 +fi + +for name in "${isolated[@]}"; do + [ "$name" = "$shard" ] || continue + path="${module}/internal/${name}" + grep -qxF "$path" <<<"$packages" || { + echo "go-race-shards: ${path} is not a package; update the isolated list" >&2 + exit 1 + } + printf '%s\n' "$path" + exit 0 +done + +echo "go-race-shards: unknown shard ${shard}" >&2 +exit 1 diff --git a/scripts/go-race-shards.test.ts b/scripts/go-race-shards.test.ts new file mode 100644 index 00000000..f02a8c4e --- /dev/null +++ b/scripts/go-race-shards.test.ts @@ -0,0 +1,24 @@ +import { expect, test } from "bun:test"; + +const root = new URL("..", import.meta.url).pathname; +const run = (...args: string[]) => Bun.spawnSync(["bash", "scripts/go-race-shards.sh", ...args], { cwd: root }); +const lines = (out: ReturnType) => out.stdout.toString().split("\n").filter(Boolean); + +test("the race shards cover every Go package exactly once", () => { + const names: string[] = JSON.parse(run("json").stdout.toString()); + expect(names.at(-1)).toBe("rest"); + const sharded = names.flatMap(name => { + const out = run(name); + expect(out.exitCode).toBe(0); + return lines(out); + }); + const all = Bun.spawnSync(["go", "list", "./..."], { cwd: root }).stdout.toString().split("\n").filter(Boolean); + expect(new Set(sharded).size).toBe(sharded.length); + expect([...sharded].sort()).toEqual([...all].sort()); +}, 60_000); // Seven `go list` runs. + +test("an unknown race shard fails instead of testing nothing", () => { + const out = run("missing"); + expect(out.exitCode).toBe(1); + expect(out.stderr.toString()).toContain("unknown shard missing"); +}); diff --git a/scripts/release.sh b/scripts/release.sh index 229a3425..157f8838 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -81,8 +81,10 @@ main() { --json status --jq '[.[] | select(.status != "completed")] | length') [ "$active" = "0" ] || die "another release workflow is still active" - just check - just test-race + # CI's push run on main already ran every check and the race suite on this + # exact commit; wait for it rather than repeating them here. + bash "$(dirname "$0")/ci-passed.sh" --wait "$head_before" || + die "CI has not passed on ${head_before}; rerun it or release a newer main" [ -z "$(git status --porcelain)" ] || die "verification changed the worktree" [ "$(git rev-parse HEAD)" = "$head_before" ] || die "HEAD changed during verification"