#!/bin/bash # Fast-forward this clone to its upstream (Gitea) and restart the web server # when the code changed. Run every few minutes by receipt-update.timer on the # machine the service runs on. # # The tests gate the restart: if they fail on the new commit, the clone goes # back to the old one, the service keeps running the old code, and that # commit is skipped until a newer one lands. set -euo pipefail cd "$(dirname "$0")/.." git fetch --quiet old=$(git rev-parse HEAD) new=$(git rev-parse '@{upstream}') [ "$old" = "$new" ] && exit 0 failed_marker="$(git rev-parse --git-dir)/receipt-update-failed" if [ "$(cat "$failed_marker" 2>/dev/null)" = "$new" ]; then exit 0 fi git merge --ff-only --quiet "$new" if ! git diff --quiet "$old" "$new" -- pyproject.toml; then .venv/bin/pip install --quiet '.[web,dev]' fi if ! output=$(.venv/bin/python -m pytest -q -p no:cacheprovider 2>&1); then echo "$output" | tail -n 20 echo "Tests failed on $(git rev-parse --short "$new"); staying on $(git rev-parse --short "$old")." >&2 git reset --quiet --hard "$old" echo "$new" >"$failed_marker" exit 1 fi systemctl --user restart receipt-web echo "Updated $(git rev-parse --short "$old") -> $(git rev-parse --short "$new")."