Files
ccp/.gitea/workflows/ci.yaml
T
adamfandClaude Opus 5.5 4a07f54884
Test and publish / test (push) Successful in 1m11s
Test and publish / publish (push) Successful in 3m41s
Drop -race from CI: the Pi's kernel can't run it
The runner's arm64 kernel has a 39-bit virtual address space, and the
race detector (ThreadSanitizer) needs 48 bits there, so every test
binary aborted. `make check` still runs -race locally.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 23:12:42 +01:00

158 lines
7.1 KiB
YAML

# =============================================================================
# ci.yaml — test every push; publish an image for pushes to main that pass.
#
# Modelled on job-tracker's ci.yaml and run by the same runner: a self-hosted
# act_runner on the Pi (stppi) in HOST mode, with git and docker and no other
# toolchain. So Go runs in a `docker run` container, and the source is
# fetched with plain git rather than actions/checkout (which needs Node on
# the host).
#
# TWO JOBS
# test gofmt, go vet, staticcheck and go test (with the database
# tests against a throwaway Postgres container), as `make check`
# minus -race, which the Pi can't run. Then the Vue app's
# typecheck and build, in a node container.
# publish main only, after test: builds deploy/Dockerfile, pushes it to
# this Gitea's container registry as :<sha> and :latest, then
# pulls it into the web_server stack (its `activity-tracker`
# service) and waits for it to be healthy.
#
# SECRETS (repo settings -> Actions -> Secrets)
# REGISTRY_USER a Gitea user that can write packages for adamf
# REGISTRY_TOKEN that user's access token with the write:package scope
# =============================================================================
name: Test and publish
on:
push:
env:
IMAGE: adam-french.co.uk/adamf/activity-tracker
jobs:
test:
runs-on: self-hosted
env:
SHA: ${{ github.sha }}
REF: ${{ github.ref }}
REMOTE: ssh://git@localhost:2222/adamf/ccp.git
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/src-${{ github.sha }}
steps:
- name: Export the pushed commit to a scratch directory
shell: bash
run: |
set -eu
mkdir -p "$(dirname "$CACHE")"
[ -d "$CACHE" ] || git init --quiet --bare "$CACHE"
git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF"
rm -rf "$SRC"
mkdir -p "$SRC"
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
test -f "$SRC/go.mod"
# A throwaway Postgres on its own network, for the database tests
# (internal/testdb gives each test its own database on it).
- name: Start Postgres
shell: bash
run: |
set -eu
docker network create "ci-$SHA"
docker run -d --name "ci-pg-$SHA" --network "ci-$SHA" --network-alias pg \
-e POSTGRES_PASSWORD=ci postgres:17
for i in $(seq 1 30); do
docker exec "ci-pg-$SHA" pg_isready -U postgres -h localhost && exit 0
sleep 1
done
docker logs "ci-pg-$SHA"
exit 1
# Read-only source, and named volumes for the module and build
# caches so repeat runs don't download everything again. No -race:
# the Pi's kernel has a 39-bit address space, which the race
# detector doesn't support on arm64. `make check` runs it locally.
- name: Go - lint and test
shell: bash
run: |
set -eu
docker run --rm \
-v "$SRC":/src:ro -w /src \
-v activity_tracker_ci_gomod:/go/pkg/mod \
-v activity_tracker_ci_gobuild:/root/.cache/go-build \
--network "ci-$SHA" \
-e TEST_DATABASE_URL='postgres://postgres:ci@pg:5432/postgres?sslmode=disable' \
golang:1.27 \
sh -c 'test -z "$(gofmt -l .)" && go vet ./... && go tool staticcheck ./... && go test -count=1 ./...'
# Copies web/ out of the read-only source so node_modules and the
# build output stay in the container.
- name: Web - typecheck and build
shell: bash
run: |
set -eu
docker run --rm \
-v "$SRC":/src:ro \
-v activity_tracker_ci_npm:/root/.npm \
node:24-alpine \
sh -c 'cp -r /src/web /web && cd /web && npm ci && npm run typecheck && npx vite build --outDir /tmp/dist'
- name: Remove the scratch directory and Postgres
if: always()
shell: bash
run: |
rm -rf "$SRC"
docker rm -f "ci-pg-$SHA" || true
docker network rm "ci-$SHA" || true
publish:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: self-hosted
env:
SHA: ${{ github.sha }}
CACHE: /home/adamf/.cache/activity-tracker-ci/repo.git
SRC: /home/adamf/.cache/activity-tracker-ci/publish-${{ github.sha }}
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
steps:
- name: Build and push the image
shell: bash
run: |
set -eu
rm -rf "$SRC" && mkdir -p "$SRC"
git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC"
printf '%s' "$REGISTRY_TOKEN" | docker login adam-french.co.uk -u "$REGISTRY_USER" --password-stdin
# Built natively on the Pi, so the image is arm64 — the only
# platform it runs on.
docker build -f "$SRC/deploy/Dockerfile" -t "$IMAGE:$SHA" -t "$IMAGE:latest" "$SRC"
docker push "$IMAGE:$SHA"
docker push "$IMAGE:latest"
- name: Remove the scratch directory
if: always()
shell: bash
run: rm -rf "$SRC"
# Put the new image live, exactly as job-tracker does: pull and
# recreate only this service, under the lock web_server's deploy
# and env-apply hold while they run compose. A pinned
# ACTIVITY_TRACKER_IMAGE_TAG in the site's .env makes this a no-op.
- name: Roll the site onto the new image
working-directory: /home/adamf/deploy/web_server
env:
DOCKER_API_VERSION: "1.41"
shell: bash
run: |
set -eu
flock env-apply/run/lock sh -c 'docker compose pull activity-tracker && docker compose up -d --no-deps activity-tracker'
for i in $(seq 1 30); do
status=$(docker inspect -f '{{.State.Health.Status}}' activity-tracker)
echo "activity-tracker: $status"
[ "$status" = healthy ] && exit 0
[ "$status" = unhealthy ] && break
sleep 5
done
docker logs --tail 50 activity-tracker
exit 1