mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:02:19 +01:00
Add scripts/deploy.sh and declare it in CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
16cb05f3a6
commit
6b67fcc4f1
@ -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`)
|
||||
|
||||
38
_installer_import/scripts/deploy.sh
Executable file
38
_installer_import/scripts/deploy.sh
Executable file
@ -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 "$@"
|
||||
94
_installer_import/tests/test_deploy.py
Normal file
94
_installer_import/tests/test_deploy.py
Normal file
@ -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()
|
||||
Loading…
Reference in New Issue
Block a user