diff --git a/_installer_import/CLAUDE.md b/_installer_import/CLAUDE.md index c81e24c..6949597 100644 --- a/_installer_import/CLAUDE.md +++ b/_installer_import/CLAUDE.md @@ -6,3 +6,4 @@ - lint: `pre-commit run --all-files` - coverage: `python3 -m pytest -q --cov --cov-branch --cov-report=xml` - coverage-gaps: `coverage-gaps coverage.xml` +- deploy: `scripts/deploy.sh` (fast-forwards kuhy's checkout `~/src/steam-game-installer` to origin/main, refusing a dirty tree, reruns `./run.sh --deps-only`, then checks the CLI starts; idempotent, non-zero unless at origin/main and healthy; test: `tests/test_deploy.py`) diff --git a/_installer_import/scripts/deploy.sh b/_installer_import/scripts/deploy.sh new file mode 100755 index 0000000..a5a19a1 --- /dev/null +++ b/_installer_import/scripts/deploy.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# ============================================================================ +# Deploy origin/main to where this tool runs: kuhy's checkout +# (~/src/steam-game-installer, used through ./run.sh). Refuses a dirty tree, +# fast-forwards it, reruns ./run.sh --deps-only (steamcmd, depotdownloader, +# editable .venv), then starts the CLI as the health check. Nothing is +# published elsewhere: no package, no service, no release. +# Idempotent; non-zero unless the checkout is at origin/main and the CLI starts. +# scripts/deploy.sh +# SGI_DEPLOY_DIR=/path another checkout (the test uses a fixture) +# ============================================================================ + +set -euo pipefail + +readonly DIR="${SGI_DEPLOY_DIR:-$HOME/src/steam-game-installer}" + +die() { + echo "deploy: FAILED ($1)" >&2 + exit 1 +} + +main() { + [[ -d "$DIR/.git" ]] || die "no checkout at $DIR" + [[ -z "$(git -C "$DIR" status --porcelain)" ]] || die "$DIR has local changes" + git -C "$DIR" checkout -q main || die "cannot switch $DIR to main" + git -C "$DIR" pull -q --ff-only origin main || die "cannot fast-forward $DIR" + local head want + head="$(git -C "$DIR" rev-parse HEAD)" + want="$(git -C "$DIR" rev-parse origin/main)" + [[ "$head" == "$want" ]] || die "$DIR is at ${head:0:7}, origin/main is ${want:0:7}" + (cd "$DIR" && ./run.sh --deps-only) || die "dependency install failed" + "$DIR/.venv/bin/python" -m steam_installer.cli --help >/dev/null || + die "health check: the CLI does not start" + echo "deploy: $DIR at ${head:0:7}, deps ok, CLI starts" +} + +main "$@" diff --git a/_installer_import/tests/test_deploy.py b/_installer_import/tests/test_deploy.py new file mode 100644 index 0000000..003210e --- /dev/null +++ b/_installer_import/tests/test_deploy.py @@ -0,0 +1,94 @@ +"""scripts/deploy.sh against a fixture checkout instead of kuhy's real one.""" + +from __future__ import annotations + +import os +from pathlib import Path +import subprocess + +import pytest + +DEPLOY = Path(__file__).resolve().parent.parent / "scripts" / "deploy.sh" + +# Stubs stand in for the real run.sh / venv so the test installs nothing. +RUN_SH = '#!/bin/bash\n[[ "$1" == --deps-only ]] && touch .deps-ran\n' +VENV_PY = '#!/bin/bash\n[[ -f "$(dirname "$0")/healthy" ]]\n' + + +def _git(cwd: Path, *args: str) -> str: + """Run git quietly in cwd and return stdout.""" + return subprocess.run( + ["git", "-C", str(cwd), *args], check=True, capture_output=True, text=True + ).stdout.strip() + + +def _commit(repo: Path, name: str, body: str, mode: int = 0o644) -> None: + """Write one file into repo and commit it.""" + path = repo / name + path.write_text(body) + path.chmod(mode) + _git(repo, "add", name) + _git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", name) + + +@pytest.fixture +def checkout(tmp_path: Path) -> tuple[Path, Path]: + """An origin with run.sh and a clone of it that is one commit behind.""" + origin = tmp_path / "origin" + origin.mkdir() + _git(origin, "init", "-q", "-b", "main") + _commit(origin, ".gitignore", ".venv/\n.deps-ran\n") + _commit(origin, "run.sh", RUN_SH, 0o755) + clone = tmp_path / "clone" + subprocess.run(["git", "clone", "-q", str(origin), str(clone)], check=True) + _commit(origin, "new.txt", "new\n") + venv_bin = clone / ".venv" / "bin" + venv_bin.mkdir(parents=True) + (venv_bin / "python").write_text(VENV_PY) + (venv_bin / "python").chmod(0o755) + (venv_bin / "healthy").touch() + return origin, clone + + +def _deploy(clone: Path) -> subprocess.CompletedProcess[str]: + """Run deploy.sh pointed at the fixture clone.""" + env = {**os.environ, "SGI_DEPLOY_DIR": str(clone)} + return subprocess.run( + ["bash", str(DEPLOY)], env=env, capture_output=True, text=True, check=False + ) + + +def test_deploy_fast_forwards_installs_and_checks( + checkout: tuple[Path, Path], +) -> None: + """A clean checkout ends at origin/main with deps run and exit 0.""" + origin, clone = checkout + result = _deploy(clone) + assert result.returncode == 0, result.stderr + assert _git(clone, "rev-parse", "HEAD") == _git(origin, "rev-parse", "HEAD") + assert (clone / ".deps-ran").exists() + assert _deploy(clone).returncode == 0 # idempotent + + +def test_deploy_refuses_dirty_checkout(checkout: tuple[Path, Path]) -> None: + """Local edits in kuhy's checkout are never overwritten.""" + _, clone = checkout + (clone / "run.sh").write_text(RUN_SH + "# local edit\n") + result = _deploy(clone) + assert result.returncode != 0 + assert "local changes" in result.stderr + + +def test_deploy_fails_when_health_check_fails(checkout: tuple[Path, Path]) -> None: + """A CLI that cannot start makes deploy exit non-zero.""" + _, clone = checkout + (clone / ".venv" / "bin" / "healthy").unlink() + result = _deploy(clone) + assert result.returncode != 0 + assert "health" in result.stderr + + +def test_claude_md_declares_deploy() -> None: + """CLAUDE.md names scripts/deploy.sh as the deploy command.""" + claude = DEPLOY.parent.parent / "CLAUDE.md" + assert "- deploy: `scripts/deploy.sh`" in claude.read_text()