Files
ccp/.gitea/workflows/ci.yaml
T
adamfandClaude Opus 5.5 f4ce04875c
Test and publish / test (push) Successful in 2m38s
Test and publish / publish (push) Failing after 2m30s
Add activity tracker server, Hyprland agent and Gitea image publishing
The Go API on PostgreSQL ingests desktop, browser, presence, manual and
Health Auto Export events and serves activities and daily goal summaries.
The Hyprland agent records window focus, idle and lock intervals.

The CI workflow publishes adam-french.co.uk/adamf/activity-tracker to the
Gitea registry and rolls the web_server stack onto it. The image probes
itself through a new `tracker healthcheck` command, because distroless
has no wget.

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

121 lines
5.2 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.
# 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 ./...'
- 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