Rebuild web/dist on deploy when web/ changed
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run

The server serves the git-ignored web/dist, so a deploy that only pulled
and restarted kept the last hand-built bundle live; the kuhy credit footer
never reached :8770. deploy.sh now rebuilds it when the web/ tree differs
from the last built one (--web-only runs just that step).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-21 14:53:04 +01:00
parent 25a5f534f2
commit 71aca9740f
2 changed files with 138 additions and 2 deletions

View File

@ -0,0 +1,108 @@
"""scripts/deploy.sh --web-only: rebuild web/dist when web/ changed.
The web server serves the built bundle at web/dist, which git ignores. A
deploy that only pulled and restarted kept serving whatever bundle was last
built by hand, so a merged web change (the kuhy credit footer) never went
live. The build keys on the git tree of web/ recorded after the last good
build, like the phone step, so a PC-only change does not pay for a rebuild.
"""
from __future__ import annotations
import os
from pathlib import Path
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[2]
DEPLOY = ROOT / "scripts" / "deploy.sh"
# conftest replaces subprocess.run process-wide for every test; this module
# needs the real one, captured at import time before any fixture runs.
_real_run = subprocess.run
def _git(repo: Path, *args: str) -> str:
"""Run git in ``repo`` and return its stripped stdout."""
env = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull}
env.pop("GIT_DIR", None)
out = _real_run(
["git", "-C", str(repo), *args],
check=True,
capture_output=True,
text=True,
env=env,
)
return out.stdout.strip()
@pytest.fixture(name="live")
def _live_repo(tmp_path: Path) -> Path:
"""A throwaway 'live clone' with one committed web file."""
repo = tmp_path / "live"
(repo / "web").mkdir(parents=True)
(repo / "web" / "package.json").write_text("{}\n")
_git(repo, "init", "-q")
_git(repo, "-c", "user.email=t@t", "-c", "user.name=t", "add", ".")
_git(repo, "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-qm", "c")
return repo
def _fake_pnpm(tmp_path: Path, rc: int) -> tuple[Path, Path]:
"""A stand-in pnpm exiting ``rc``; returns (script, call log)."""
calls = tmp_path / "pnpm_calls"
script = tmp_path / "pnpm"
script.write_text(f'#!/bin/bash\necho "$@" >> "{calls}"\nexit {rc}\n')
script.chmod(0o755)
return script, calls
def _run(live: Path, pnpm: Path, marker: Path) -> subprocess.CompletedProcess[str]:
"""Run ``deploy.sh --web-only`` against ``live`` with a fake pnpm."""
env = {
**os.environ,
"SCREEN_LOCKER_LIVE": str(live),
"WEB_PNPM": str(pnpm),
"WEB_BUILD_MARKER": str(marker),
}
env.pop("GIT_DIR", None)
return _real_run(
["bash", str(DEPLOY), "--web-only"],
check=False,
capture_output=True,
text=True,
env=env,
)
def test_changed_web_is_built_and_recorded(live: Path, tmp_path: Path) -> None:
"""No record yet: install + build run and the web tree is recorded."""
pnpm, calls = _fake_pnpm(tmp_path, 0)
marker = tmp_path / "state" / "web_tree"
result = _run(live, pnpm, marker)
assert not result.returncode, result.stderr
lines = calls.read_text().splitlines()
assert lines[0].endswith("install --frozen-lockfile")
assert lines[1].endswith("run build")
assert marker.read_text().strip() == _git(live, "rev-parse", "HEAD:web")
def test_unchanged_web_skips_the_build(live: Path, tmp_path: Path) -> None:
"""Recorded tree == current tree: exit 0 without running pnpm."""
pnpm, calls = _fake_pnpm(tmp_path, 0)
marker = tmp_path / "web_tree"
marker.write_text(_git(live, "rev-parse", "HEAD:web") + "\n")
result = _run(live, pnpm, marker)
assert not result.returncode, result.stderr
assert "unchanged" in result.stdout
assert not calls.exists()
def test_failed_build_fails_and_records_nothing(live: Path, tmp_path: Path) -> None:
"""pnpm fails: the deploy fails loudly and the next one retries the build."""
pnpm, _ = _fake_pnpm(tmp_path, 1)
marker = tmp_path / "web_tree"
result = _run(live, pnpm, marker)
assert result.returncode == 1
assert "web" in result.stderr
assert not marker.exists()

View File

@ -20,10 +20,16 @@
# written to PHONE_APP_MARKER after each install; no marker means the phone is
# required (fail closed). Any app change gives a new tree, so it is never skipped.
#
# Usage: bash scripts/deploy.sh [--health-only | --phone-only]
# Web: the server serves web/dist, which git ignores, so a pull alone left the
# last hand-built bundle live. The bundle is rebuilt (pnpm install + build,
# which stamps /version) whenever the git tree of web/ differs from the one in
# WEB_BUILD_MARKER, before the restart; a failed build fails the deploy.
#
# Usage: bash scripts/deploy.sh [--health-only | --phone-only | --web-only]
#
# Seams: SCREEN_LOCKER_LIVE (live clone), DEPLOY_WEB_PORT (health port),
# PHONE_DEPLOY (installer), PHONE_APP_MARKER (last installed app tree).
# PHONE_DEPLOY (installer), PHONE_APP_MARKER (last installed app tree),
# WEB_PNPM (pnpm binary), WEB_BUILD_MARKER (last built web tree).
# Exit: 0 healthy and installed everywhere | 1 any step or check failed.
set -euo pipefail
@ -33,6 +39,8 @@ readonly PY="/usr/bin/python3"
readonly APP_DIR="stronglift_replacement/workout_app"
readonly PHONE_DEPLOY="${PHONE_DEPLOY:-$HOME/.claude/scripts/phone_deploy.sh}"
readonly PHONE_APP_MARKER="${PHONE_APP_MARKER:-$HOME/.local/state/screen-locker/phone_app_tree}"
readonly WEB_PNPM="${WEB_PNPM:-pnpm}"
readonly WEB_BUILD_MARKER="${WEB_BUILD_MARKER:-$HOME/.local/state/screen-locker/web_tree}"
readonly UNITS=(screen-locker-web.service workout-poke.service runnerup-watch.service)
die() { echo "deploy: FAIL: $*" >&2; exit 1; }
@ -92,6 +100,7 @@ desktop() {
|| die "$LIVE HEAD is not its upstream after the pull"
ok "live clone at $(git -C "$LIVE" rev-parse --short HEAD)"
bash "$LIVE/install.sh" || die "install.sh failed"
web
for unit in "${UNITS[@]}"; do before[$unit]="$(main_pid "$unit")"; done
systemctl --user restart "${UNITS[@]}" || die "restart of ${UNITS[*]} failed"
for unit in "${UNITS[@]}"; do
@ -101,6 +110,21 @@ desktop() {
ok "restarted ${UNITS[*]}"
}
# Rebuild web/dist when web/ changed since the last good build (see header).
web() {
local tree
tree="$(git -C "$LIVE" rev-parse HEAD:web)" || die "no web tree at $LIVE HEAD"
if [[ "$(cat "$WEB_BUILD_MARKER" 2>/dev/null || true)" == "$tree" ]]; then
ok "web unchanged since the last build (tree ${tree:0:10}); build skipped"
return 0
fi
"$WEB_PNPM" -C "$LIVE/web" install --frozen-lockfile || die "web: pnpm install failed"
"$WEB_PNPM" -C "$LIVE/web" run build || die "web: pnpm run build failed"
mkdir -p "$(dirname "$WEB_BUILD_MARKER")"
printf '%s\n' "$tree" > "$WEB_BUILD_MARKER"
ok "web/dist rebuilt (tree ${tree:0:10})"
}
# The app's one-time gap deload backfill saves the pre-cut exercise_state on
# its first start after install; keep a PC copy so restore works without the
# phone's dir. The app needs a few seconds after launch, hence the retries;
@ -145,6 +169,10 @@ if [[ "${1:-}" == "--phone-only" ]]; then
phone
exit 0
fi
if [[ "${1:-}" == "--web-only" ]]; then
web
exit 0
fi
if [[ "${1:-}" == "--health-only" ]]; then
health
exit 0