90bfcaa388
Every commit on dev that's part of an open PR fires each workflow TWICE: once for the push event and once for the pull_request event (observable in run #43 + #44 for the same SHA in android.yml, same shape across test-web.yml and test-go.yml). The two runs check the exact same SHA — pure waste. Drop the pull_request trigger from test-web.yml, test-go.yml, and android.yml. The dev push already exercises every check that a PR would re-run. This repo has no fork PRs to cover, which is the only case pull_request would catch that push doesn't. Add a concurrency group keyed on workflow + ref with cancel-in-progress: true to every workflow including release.yml. Rapid re-pushes (or force-moving the per-day tag) now cancel the older in-flight run instead of stacking.
126 lines
5.1 KiB
YAML
126 lines
5.1 KiB
YAML
name: test-go
|
|
|
|
# Go server: vet + golangci-lint + short race tests. Runs on push to
|
|
# dev/main and PRs to main, scoped to Go-side files only — web-only or
|
|
# Flutter-only diffs don't trigger this workflow.
|
|
#
|
|
# Two jobs: `test` (fast — vet + lint + `go test -short -race`, no DB) and
|
|
# `integration` (full `go test -race` against an ephemeral Postgres).
|
|
#
|
|
# Integration-job DB wiring follows the act_runner shared-daemon pattern:
|
|
# the runner's Docker daemon also runs the operator's dev compose stack,
|
|
# so service containers get NO published ports (collision) and no
|
|
# service-name DNS. We discover the service container by the job-scoped
|
|
# name filter via the mounted docker socket and reach it by bridge IP.
|
|
# The exactly-one assertion is a hard guard — pointing tests at the dev
|
|
# Postgres would truncate it (the disaster Fable #339 exists to prevent).
|
|
#
|
|
# `web/build/` has a committed placeholder index.html so go:embed succeeds
|
|
# without needing the SPA to be freshly built. Real builds happen in
|
|
# release.yml (container) and locally during dev.
|
|
|
|
on:
|
|
push:
|
|
branches: [dev, main]
|
|
paths:
|
|
- '**/*.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
- 'sqlc.yaml'
|
|
- 'internal/**'
|
|
- 'cmd/**'
|
|
- '.golangci.yml'
|
|
- '.gitea/workflows/test-go.yml'
|
|
|
|
# pull_request trigger intentionally omitted — see test-web.yml for
|
|
# the rationale (single-author repo, push covers PR-merge equivalent).
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: go-ci
|
|
container:
|
|
image: git.fabledsword.com/bvandeusen/ci-go:1.26
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Toolchain versions
|
|
run: |
|
|
go version
|
|
golangci-lint --version
|
|
|
|
- name: go vet
|
|
run: go vet ./...
|
|
|
|
- name: golangci-lint
|
|
run: golangci-lint run ./...
|
|
|
|
- name: go test (short, race)
|
|
run: go test -short -race ./...
|
|
|
|
integration:
|
|
runs-on: go-ci
|
|
container:
|
|
image: git.fabledsword.com/bvandeusen/ci-go:1.26
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: minstrel
|
|
POSTGRES_PASSWORD: minstrel
|
|
POSTGRES_DB: minstrel_test
|
|
# No `ports:` — the runner shares the operator's dev compose
|
|
# Docker daemon; publishing a fixed host port collides.
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Integration suite (discover service by bridge IP, migrate, test)
|
|
run: |
|
|
set -eux
|
|
# Discover THIS job's Postgres service container via the
|
|
# mounted docker socket. act_runner attaches the job
|
|
# container and its service container(s) to a shared per-job
|
|
# network, so scope discovery to a postgres that sits on a
|
|
# network THIS job container is also on. The old
|
|
# `--filter name=integration` matched EVERY concurrent
|
|
# integration run's postgres (a dev push + the main-merge run
|
|
# overlap → 2 candidates → false "expected exactly 1" abort).
|
|
# The operator's dev compose `minstrel-postgres-*` is never on
|
|
# this job's network; skip it explicitly as belt-and-suspenders
|
|
# (a wrong target would truncate real data).
|
|
SELF=$(cat /etc/hostname)
|
|
SELF_NETS=$(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$SELF")
|
|
test -n "$SELF_NETS"
|
|
echo "self ($SELF) networks: $SELF_NETS"
|
|
PG_ID=""
|
|
PG_NAME=""
|
|
for cid in $(docker ps --filter "ancestor=postgres:16-alpine" -q); do
|
|
nm=$(docker inspect -f '{{.Name}}' "$cid" | sed 's#^/##')
|
|
case "$nm" in *minstrel-postgres*|*_postgres_*) continue ;; esac
|
|
for net in $(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}' "$cid"); do
|
|
case " $SELF_NETS " in *" $net "*) PG_ID="$cid"; PG_NAME="$nm"; break 2 ;; esac
|
|
done
|
|
done
|
|
test -n "$PG_ID" || { echo "FATAL: no postgres service container on this job's network (self nets: $SELF_NETS)"; exit 1; }
|
|
echo "selected postgres: $PG_ID $PG_NAME"
|
|
PG_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$PG_ID")
|
|
test -n "$PG_IP"
|
|
export MINSTREL_TEST_DATABASE_URL="postgres://minstrel:minstrel@${PG_IP}:5432/minstrel_test?sslmode=disable"
|
|
|
|
# Wait for Postgres to accept TCP (no health-check dependency).
|
|
for i in $(seq 1 60); do (echo > "/dev/tcp/${PG_IP}/5432") 2>/dev/null && break; sleep 2; done
|
|
|
|
# Apply embedded migrations to the fresh test DB, then run the
|
|
# full suite (no -short → integration tests execute). -p 1:
|
|
# every integration package TRUNCATEs the one shared test DB;
|
|
# concurrent package binaries → TRUNCATE deadlocks. Serialize
|
|
# package execution (the documented local invocation too).
|
|
MINSTREL_DATABASE_URL="$MINSTREL_TEST_DATABASE_URL" go run ./cmd/minstrel migrate
|
|
go test -p 1 -race ./...
|