Trim comments to the non-obvious why
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s

Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 20:49:03 +00:00
co-authored by Claude Opus 5.5
parent effddd2794
commit 4530cb8dc4
222 changed files with 1173 additions and 5423 deletions
+17 -89
View File
@@ -1,47 +1,9 @@
# =============================================================================
# deploy.yaml — test every push; deploy pushes to main that pass.
#
# TWO JOBS
# test runs on every push, to any branch: `go vet` + `go test` for the
# backend and pytest for the Python service. These are the same
# checks as `make check-backend` and `make check-python`.
# deploy runs only for refs/heads/main, and only if `test` passed
# (`needs: test`). Before this gate existed every push to main went
# straight to the live site.
#
# WHERE THIS RUNS, AND WHAT THAT RULES OUT
# A self-hosted act_runner on the Pi itself, in HOST mode (see
# gitea-runner/run.sh): steps are shell commands on the Pi, not in a job
# container. So:
# - No host toolchains are assumed. The Pi is known to have git and docker
# and nothing else; Go and Python run inside `docker run` containers
# pinned to the same base images as backend/Dockerfile (golang:1.26) and
# python/Dockerfile (python:3.12-slim). Bump them together.
# - No `actions/checkout`. It is a JavaScript action and would need Node on
# the host. The source is fetched with plain git instead, over Gitea's SSH
# on its LXC (git.adam-french.co.uk:2222, pinned to the LAN IP in
# stpvm's /etc/hosts).
#
# THE LIVE DIRECTORY IS NOT TOUCHED UNTIL TESTS PASS
# The site runs out of /home/adamf/deploy/web_server. The test job never
# goes near it: it fetches into a separate bare cache repo and exports the
# pushed commit to a scratch directory. Only the deploy job, after `test`
# is green, does the `git reset --hard` there.
#
# NOT TESTED HERE: THE VUE BUILD
# Deliberately skipped. `docker compose up --build` in the deploy job
# already runs the full frontend build (npm ci + vite) while building the
# vue image, and a failed image build aborts `up` BEFORE any container is
# replaced, so the old site keeps serving. Building it a second time here
# would cost the Pi several minutes per push to learn nothing new. The same
# reasoning does not hold for Go and Python: their images build fine with
# failing tests, which is exactly why those are gated here.
#
# NO pull_request TRIGGER
# `push` with no branch filter already covers every branch, including the
# head branch of any PR in this repo, so adding pull_request would run the
# suite twice per push on a machine with little CPU to spare.
# =============================================================================
# `test` runs on every push; `deploy` runs for main only after it passes.
# The runner is in host mode with only git and docker on the host, so Go and
# Python run in containers pinned to the same images as their Dockerfiles
# (bump together), and checkout is plain git rather than actions/checkout.
# The Vue build isn't tested here: a failed image build in `up --build`
# aborts before any container is replaced.
name: Test and deploy
on:
@@ -51,19 +13,13 @@ jobs:
test:
runs-on: self-hosted
env:
# The commit and ref this push delivered. Passed through env rather
# than interpolated into the scripts so a branch name can never be
# parsed as shell.
# Via env so a branch name is never parsed as shell.
SHA: ${{ github.sha }}
REF: ${{ github.ref }}
REMOTE: ssh://[email protected]:2222/adamf/web_server.git
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
# Bare repo kept between runs so each fetch is incremental (the
# history is ~140MB; a fresh clone per push would be slow on the
# Pi's SD card). Lives outside the deploy directory on purpose.
# Kept between runs so fetches are incremental.
CACHE: /home/adamf/.cache/web_server-ci/repo.git
# This run's source tree, exported from the cache and removed in
# the last step. Keyed by commit so two runs cannot share a tree.
SRC: /home/adamf/.cache/web_server-ci/src-${{ github.sha }}
steps:
- name: Export the pushed commit to a scratch directory
@@ -72,33 +28,19 @@ jobs:
set -eu
mkdir -p "$(dirname "$CACHE")"
[ -d "$CACHE" ] || git init --quiet --bare "$CACHE"
# Fetch the pushed ref, then export the exact pushed commit.
# Using $SHA rather than FETCH_HEAD means that if the branch
# has moved on since this run was queued we still test the
# commit this run is about, not a newer one.
# $SHA, not FETCH_HEAD: test this run's commit even if the
# branch has moved on.
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF"
rm -rf "$SRC"
mkdir -p "$SRC"
# `git archive` gives a clean tree of tracked files only: no
# .git, and nothing left over from an earlier run.
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
# Do not rely on the shell having pipefail: if the archive
# half failed, make sure that is noticed here.
# In case the shell lacks pipefail.
test -f "$SRC/backend/go.mod"
test -f "$SRC/python/requirements-dev.txt"
echo "Exported $SHA ($REF) to $SRC"
# The whole repo is mounted read-only. Tests write only to
# t.TempDir(), and a read-only mount means the container (root)
# cannot leave root-owned files in $SRC that the clean-up step,
# running as the runner user, could not delete.
#
# The two named volumes are the Go module cache and build cache.
# Without them every run would re-download every dependency and
# recompile gorm, gin and gqlgen from scratch — minutes on a Pi.
# They survive `docker image prune` and the weekly maintenance
# job; `docker volume rm web_server_ci_gomod web_server_ci_gobuild`
# resets them if they ever go bad.
# Read-only so root in the container can't leave files the
# clean-up step can't delete. The named volumes are Go caches.
- name: Backend - go vet and go test
shell: bash
run: |
@@ -111,12 +53,7 @@ jobs:
golang:1.26 \
sh -c 'go vet ./... && go test ./...'
# requirements-dev.txt pulls in requirements.txt plus pytest. The
# install is repeated every run (the container is thrown away) but
# the pip cache volume means it is unpacking cached wheels, not
# downloading. Read-only source for the same reason as above, so
# bytecode and the pytest cache are switched off rather than left
# to fail noisily.
# Read-only source, so bytecode and the pytest cache are off.
- name: Python - pytest
shell: bash
run: |
@@ -129,16 +66,12 @@ jobs:
python:3.12-slim \
sh -c 'pip install --quiet --disable-pip-version-check --root-user-action=ignore -r requirements-dev.txt && python -m pytest tests -q -p no:cacheprovider'
# always(): a failed test must not leave a source tree behind per
# push. The cache repo is kept; only this run's export goes.
- name: Remove the scratch directory
if: always()
shell: bash
run: rm -rf "$SRC"
deploy:
# Both conditions matter: `needs` makes a red test job skip this one,
# and the `if` keeps pushes to other branches from deploying at all.
needs: test
if: github.ref == 'refs/heads/main'
runs-on: self-hosted
@@ -153,12 +86,8 @@ jobs:
set -eu
git config --global --add safe.directory /home/adamf/deploy/web_server
git fetch ssh://[email protected]:2222/adamf/web_server.git main
# Deploy only the commit the test job just passed. If main
# has moved on since this run started, FETCH_HEAD is a newer
# commit that THIS run never tested — stop, and let that
# commit's own run test and deploy it. Failing (rather than
# resetting to $SHA anyway) also means re-running an old run
# can never roll the site back to an old commit.
# Deploy only the tested commit; a newer main gets its own
# run. This also stops a re-run rolling the site back.
if [ "$(git rev-parse FETCH_HEAD)" != "$SHA" ]; then
echo "main is at $(git rev-parse FETCH_HEAD), but this run tested $SHA."
echo "Not deploying: the run for the newer commit will."
@@ -170,8 +99,7 @@ jobs:
working-directory: /home/adamf/deploy/web_server
env:
COMPOSE_BAKE: "false"
# The lock is shared with maintenance.yaml, so a deploy and the
# weekly rebuild cannot run compose at the same time.
# Shared with maintenance.yaml so the two never run compose at once.
run: flock .compose.lock docker compose up -d --build --remove-orphans
- name: Prune unused Docker resources
+3 -12
View File
@@ -2,9 +2,7 @@ name: Weekly Maintenance
on:
schedule:
# 05:00 UTC Sunday (06:00 in BST). The upgrade restarts dockerd and
# every container, so it runs when nobody is likely to be mid-edit;
# 01:00 kept catching late-night SilverBullet saves.
# Restarts dockerd, so it runs when nobody is likely mid-edit.
- cron: "0 5 * * 0"
workflow_dispatch:
@@ -24,15 +22,8 @@ jobs:
- name: Autoremove obsolete packages
run: sudo apt-get -y autoremove --purge
# Both compose steps below take .compose.lock, the same flock
# deploy.yaml holds while it runs compose. Without it this weekly
# job could recreate containers while a deploy is mid-build, and
# two `compose up`s racing over the same project can each recreate
# a container the other just started. flock blocks until the other
# holder finishes, so the job waits rather than fails. The lock is
# taken per step, not across both: nothing needs pull and up to be
# atomic, and holding it for less time keeps a deploy from waiting
# behind a long pull.
# .compose.lock is shared with deploy.yaml, so two compose runs
# never race. Taken per step to keep deploys from waiting long.
- name: Pull latest base images
working-directory: /home/adamf/deploy/web_server
run: flock .compose.lock docker compose pull
+6 -41
View File
@@ -1,48 +1,13 @@
# =============================================================================
# renovate.yaml — weekly dependency-update PRs, opened against this repo.
#
# Renovate stands in for Dependabot, which does not exist outside GitHub. What
# it updates is configured in /renovate.json5; this file is only how it runs.
#
# HOW IT RUNS
# The same host-mode act_runner as deploy.yaml, so (as there) nothing but
# git and docker is assumed on the host: Renovate runs from its own image.
# --network host gives the container the host's /etc/hosts, which pins
# git.adam-french.co.uk to the Gitea LXC's LAN IP, so it reaches Gitea on
# :3000, the port the runner itself registers against, and keeps working
# while the tunnel is down. RENOVATE_GIT_URL=endpoint matters for the same
# reason: without it Renovate clones from the URL Gitea advertises, which is
# ROOT_URL — the public https://git.adam-french.co.uk through Cloudflare.
#
# WHAT HAPPENS AFTER
# Each update is pushed as a renovate/* branch, which triggers deploy.yaml's
# `test` job like any other push (and never its `deploy` job, which is
# main-only). Nothing is merged automatically: merging is deploying.
# Renovate also keeps a "Dependency Dashboard" issue open listing everything
# pending; ticking a box there is picked up on the next run, so run this
# workflow by hand (workflow_dispatch) to act on it sooner.
#
# THE TOKEN
# RENOVATE_TOKEN is a repo Actions secret: a Gitea access token for the
# account the PRs come from (a dedicated `renovate` user with write access
# to this repo, ideally), scopes read:user, read:organization,
# write:repository, write:issue.
# RENOVATE_GITHUB_COM_TOKEN is optional: any github.com token with no
# scopes. Without it Renovate is rate-limited by GitHub and leaves release
# notes out of the PRs. (Gitea refuses secret names starting GITHUB_, hence
# the prefix.) Both reach the container as `-e NAME` with no value, so they
# are copied from this step's env and never appear in the process list.
#
# The renovate/renovate:44 tag floats within the major (--pull always picks
# up the newest 44.x each week); Renovate itself proposes the next major via
# the regex manager in renovate.json5.
# =============================================================================
# Weekly Renovate run (config in /renovate.json5). --network host uses the
# host's /etc/hosts pin to reach Gitea on the LAN, and RENOVATE_GIT_URL=endpoint
# stops it cloning via the public ROOT_URL. Secrets are passed as bare `-e NAME`
# so they never appear in the process list. Gitea refuses secret names starting
# GITHUB_, hence RENOVATE_GITHUB_COM_TOKEN.
name: Renovate
on:
schedule:
# 04:00 UTC Monday: clear of the Sunday 05:00 maintenance rebuild, and
# done before the working week so the PRs are waiting.
# Clear of the Sunday maintenance rebuild.
- cron: "0 4 * * 1"
workflow_dispatch: