Files
ccp/.gitea/workflows/ci.yaml
T
adamfandClaude Opus 5.5 0be97384fa
Test and publish / test (push) Successful in 1m28s
Test and publish / publish (push) Successful in 3m30s
Move the dashboard and setup pages to a Vue SPA
The pages are now a Vue 3 + Vite + TypeScript app in web/, built into
internal/web/dist/app and embedded in the binary. Go still serves
index.html for / and /setup behind the admin gate, plus the hashed
/assets/* (public, cached forever). The router takes its base from the
current URL, so it works under nginx's /tracker/ prefix unchanged.

Only dist/.gitkeep is committed, so go build and go test need no Node;
an unbuilt binary shows a "run make web" page at /. The Dockerfile gains
a Node stage, CI typechecks and builds the app, and make build/run build
it first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 22:06:41 +01:00

134 lines
5.8 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 go vet + go test, as `make test`. The API tests skip themselves
# here: they need TEST_DATABASE_URL, and CI has no Postgres. 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"
# Read-only source, and named volumes for the module and build
# caches so repeat runs don't download everything again.
- name: Go - vet 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 \
golang:1.27 \
sh -c 'go vet ./... && go test ./...'
# 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
if: always()
shell: bash
run: rm -rf "$SRC"
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